C#C
C#12mo ago
7 replies
its0mar

Optimistic concurrency failure, object has been modified

public async Task<IActionResult> UpdateInfo(UpdateInfoDTO dto)
{
    if (!ModelState.IsValid)
    {
        ViewBag.Errors = ModelState.Values.SelectMany(e => e.Errors).Select(e => e.ErrorMessage).ToList();
        return View(dto);
    }

    ApplicationUser user = new ApplicationUser { UserName = dto.UserName, PersonName = dto.PersonName, Email = dto.Email, PhoneNumber = dto.Phone, ProfilePicPath = dto.ProfilePicture };
    user.SecurityStamp = Guid.NewGuid().ToString();
    var result = await _userManager.UpdateAsync(user);

    if (result.Succeeded)
    {
        return RedirectToAction(nameof(HomeController.Index), "Home");
    }
    else
    {
        foreach (IdentityError error in result.Errors)
        {
            ModelState.AddModelError("UpdateInfo", error.Description);
        }
        return View(dto);
    }

}

hello, when I try to update a user I get Optimistic concurrency failure, object has been modified , how I can fix it and what is the reason of it
Was this page helpful?