I want to make it possible for user to change his profile details(except UserId,Username and password(password changed in another view))
so in my method when I make it like that
public void SaveUser(UserProfile user)
{
context.Entry(user).State = System.Data.EntityState.Modified;
context.SaveChanges();
}
I get an error Store update, insert, or delete statement affected an unexpected number of rows (0). After that I have surfed the stackoverflow, where someone suggested to make it another way, so i edited my SaveUser method
public void SaveUser(UserProfile user)
{
var objectContext = ((System.Data.Entity.Infrastructure.IObjectContextAdapter
)context).ObjectContext;
try
{
objectContext.SaveChanges();
}
catch (OptimisticConcurrencyException)
{
objectContext.Refresh(RefreshMode.ClientWins, context.UserProfiles);
objectContext.SaveChanges();
}
}
after these changes I don't get this error anymore, however my profile details are not changed.
My HttpPost Edit method(HttpGet retrieves correct information)
[HttpPost]
public ActionResult Edit(UserProfile user)
{
if (ModelState.IsValid)
{
repository.SaveUser(user);
return View(user);
}
return View();
}
In my Edit view I have only LabelFor's and EditorFor's for everything(except Id,Username and Password) and Submit button.
Trying to solve that all day long and have not succeeded yet.