public ActionResult EditRoles(int clientId) { var roles = this.userService.GetRoles().ToList(); var client = this.clientsService.GetClient(clientId); var model = new UpdateRolesModel { ClientId = client.Id, Roles = client.Roles.Select(x => (Role)Enum.Parse(typeof(Role), roles.First(r => r.Id == x.RoleId).Name, true)) }; return this.View(model); }
public ActionResult EditRoles(UpdateRolesModel model) { var roles = this.userService.GetRoles(); var client = this.clientsService.GetClient(model.ClientId); client.Roles.Clear(); model.Roles.ForEach( r => { var roleId = roles.First(x => x.Name == Enum.GetName(typeof(Role), r)).Id; client.Roles.Add(new IdentityUserRoleEntity { RoleId = roleId, UserId = client.Id }); }); this.clientsService.CreateOrUpdate(client); return this.Json(true, JsonRequestBehavior.AllowGet); }