its0mar
its0mar
CC#
Created by its0mar on 2/5/2025 in #help
relationship navigations entity framework
post class and ApplicationUser class both have a collection of Reaction but when i try to get the reaction count its always zero line : https://github.com/Its0mar/ZeroWebRepo/blob/88f8b0f9f7792a0146325d6054fc60a6097f4ee8/Services/PostService.cs#L52
19 replies
CC#
Created by its0mar on 1/29/2025 in #help
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);
}

}
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
8 replies