I want to save the ID of the user who logged in DB in the "CreatedBy" column in the DB All identities created by the user must have the ID of the user who created them, but when clicking on the "Create" button, I receive a < strong> System.NotImplementedException , I have no idea why.
Use Identity framework with ASP.net MVC 5 and EF.
Model IdentityModel.cs , method where the error is found:
public static implicit operator string(ApplicationUser v)
{
throw new NotImplementedException(); // aqui se encuentra la excepcion
}
}
Create () control FitnessGoalController created from the FitnessGoals Model, this is where it's about saving the ID of the user logged in the DB:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "ID,Name,Goal,StartDate,FinishDate,Weight")] FitnessGoals fitnessGoals)
{
var user = UserManager.FindById(User.Identity.GetUserId());
if (ModelState.IsValid)
{
fitnessGoals.CreatedBy = user;
db.FitnessGoals.Add(fitnessGoals);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(fitnessGoals);
}