public virtual JsonResult AddUserInRole(AddUserInRoleModel model) { if (model.IsNull() || !ModelState.IsValid) { return(Json(new ActionResponse <int> { Message = LocalMessage.InvalidFormData }, JsonRequestBehavior.AllowGet)); } var user = _lazyUserBusiness.Value.Find(model.SearchMobileNumber); if (user.IsNull()) { return(Json(new ActionResponse <int> { Message = LocalMessage.UserNotFound }, JsonRequestBehavior.AllowGet)); } return(Json(_userInRoleBusiness.Insert(new UserInRole { ExpireDateSh = model.ExpireDateSh, IsActive = model.IsActive, RoleId = model.RoleId, UserId = user.UserId }), JsonRequestBehavior.AllowGet)); }
public ActionResult AddUserInRole(AddUserInRoleModel model) { try { if (ModelState.IsValid) { var user = UserManager.FindByEmail(model.Email); if (user != null) { IdentityResult result = UserManager.AddToRole(user.Id, model.Role); if (result.Succeeded) { return(RedirectToAction("Index")); } else { ModelState.AddModelError("", "Что-то пошло не так"); } } else { ModelState.AddModelError("", "Такого пользователя не существует"); } } return(View(model)); } catch (Exception e) { return(RedirectToAction("Index", "Error", new { error = e.Message })); } }