i have the following EdiePOST action method:-
[HttpPost]
public ActionResult Edit([Bind(Include = "Note,DoctorID,VisitID,StatusID,timestamp")] Visit visit) //[Bind(Include="Note,DoctorID,VisitID,StatusID")]
{
if ((visit.EditableByAssingedDoctor(User.Identity.Name)) || (visit.EditableByCreatedBy(User.Identity.Name)))
{
try
{
if (ModelState.IsValid)
{
int id = visit.VisitID;
var v = repository.GetVisit(id);
visit.CreatedBy = v.CreatedBy;
visit.Date = v.Date;
visit.PatientID = v.PatientID;
visit.VisitTypeID = v.VisitTypeID;
repository.UpdateVisit(visit);
repository.Save();
return RedirectToAction("Index");
}
}
catch (DbUpdateConcurrencyException ex)
{
//code goes here
where the repository.UpdateVisit(visit);
is :-
public void UpdateVisit(Visit v)
{
entities.Entry(v).State = EntityState.Modified;
}
But when i run my application and i try to edit the visit object i got the following error :-
An object with the same key already exists in the ObjectStateManager. The ObjectStateManager cannot track multiple objects with the same key.
on the repository.UpdateVisit(visit);
method,, so what are going wrong?
BR