public ActionResult AddUserToRole(int userId, int roleId) { var profile = this.membershipService.GetProfile(new GetProfileRequest { IdentityToken = this.FormsAuthentication.GetAuthenticationToken() }); if (profile.Id.Equals(userId)) { return this.GetWarningJsonFromResources("CantModifyOwnRole"); } if (roleId.Equals(2)) { return this.GetWarningJsonFromResources("ShopperRoleCannotBeAssigned"); } var req = new AddUserToRoleRequest { RoleId = roleId, UserId = userId }; var response = this.membershipService.AddUserToRole(req); var jsonNetResult = new JsonNetResult { Formatting = (Formatting)Newtonsoft.Json.Formatting.Indented, Data = new { response.Message, MessageType = response.MessageType.ToString() } }; return jsonNetResult; }
/// <summary> /// The add user to role. /// </summary> /// <param name="request"> /// The request. /// </param> /// <returns> /// The <see cref="AddUserToRoleResponse"/>. /// </returns> public AddUserToRoleResponse AddUserToRole(AddUserToRoleRequest request) { this.roleRepository.AddUserToRole(request.UserId, request.RoleId); this.roleRepository.SaveChanges(); return new AddUserToRoleResponse { Message = CommonResources.ResourceManager.GetString("UserAddedToRole"), MessageType = MessageType.Success }; }