public ActionResult Save(UserFormViewModel user) { if (!ModelState.IsValid) { return(RedirectToAction("New", "User")); } _userAppService.DeleteUserApps(user.BlazerId); _userRoleService.DeleteUserRole(user.BlazerId); var roleIds = user.AppRoles.Select(x => x.Id).ToList(); var appIds = user.Apps.Select(x => x.Id).ToList(); _userAppService.AddUserApps(user.BlazerId, appIds, roleIds); _userRoleService.AddUserRole(user.BlazerId, user.RoleId); return(RedirectToAction("Index", "User")); }
public IHttpActionResult AddUserRole(UserRole userrole) { try { if (userrole != null) { if (ModelState.IsValid) { string accessToken = Request.Headers.Authorization == null ? null : Request.Headers.Authorization.Parameter; bool isUserRoleSaved = _service.AddUserRole(userrole, accessToken); if (isUserRoleSaved) { return(Content(HttpStatusCode.OK, "UserRole has been created successfully.")); } else { return(Content(HttpStatusCode.OK, "UserRole is already exist.")); } } else { string modelError = null; for (int i = 0; i < ModelState.Keys.Count; i++) { modelError = string.Join(",", ModelState.Values.Where(E => E.Errors.Count > 0).SelectMany(E => E.Errors).Select(E => E.ErrorMessage).ToArray()); } return(Content(HttpStatusCode.BadRequest, modelError)); } } else { throw new Exception("Please provide the user role details."); } } catch (Exception ex) { Logger.WriteException("AddUserRole : ", ex); return(Content(HttpStatusCode.BadRequest, ex.GetBaseException().Message)); } }
public static UserRole AddUserRole(UserRole userRole) { return(UserRoleService.AddUserRole(userRole)); }