public ActionResult Edit(UserViewModel user, int[] selectedRoles) { var allRoles = roleService.GetAll().Select(item => item.ToMvcRoleModel()); var roles = new List<RoleViewModel>(); if (selectedRoles != null) { user.RoleNames = new List<string>(); foreach (var r in allRoles.Where(role => selectedRoles.Contains(role.Id))) { user.RoleNames.Add(r.Name); roles.Add(r); } } try { userService.Update(user.ToBllUser(roles)); } catch (ArgumentNullException e) { return RedirectToAction("Index", "Error", new { id = "Параметр " + e.Message + " NULL" }); } catch (ArgumentException e) { return RedirectToAction("Index", "Error", new { id = e.Message }); } catch { return RedirectToAction("Index", "Error", new { id = "Ошибка при сохранении файла в БД" }); } return RedirectToAction("Index"); }
public ActionResult Edit(UserViewModel user, string[] selectedRoles) { UpdateUserRoles(user, selectedRoles); _userService.UpdateUser(user.ToBllUser()); if (!((ClaimsIdentity)User.Identity).Claims .Any(x => x.Type == ClaimTypes.Role && x.Value == "Admin")) { _signService.IdentitySignout(); _signService.IdentitySignin(user.ToBllUser()); } return RedirectToAction("Index", "Home",null); }