public async Task <IActionResult> UserRolesDelete(TUserDtoKey id, TRoleDtoKey roleId) { await _identityService.ExistsUserAsync(id.ToString()); await _identityService.ExistsRoleAsync(roleId.ToString()); var userDto = await _identityService.GetUserAsync(id.ToString()); var roles = await _identityService.GetRolesAsync(); var rolesDto = new UserRolesDto <TRoleDto, TUserDtoKey, TRoleDtoKey> { UserId = id, RolesList = roles.Select(x => new SelectItemDto(x.Id.ToString(), x.Name)).ToList(), RoleId = roleId, UserName = userDto.UserName }; return(View(rolesDto)); }
public ActionResult UserRolesGridViewPartialUpdate(UserRolesDto item) { var model = db.UserRoles; if (ModelState.IsValid) { try { var userRole = db.UserRoles.Where(c => c.ObjId == item.ObjId).SingleOrDefault(); if (userRole != null) { this.UpdateModel(userRole); db.SaveChanges(); } else { userRole.RoleId = item.RoleId; model.Attach(userRole); db.SaveChanges(); ; } } catch (Exception e) { ViewData["EditError"] = e.Message; } } else { ViewData["EditError"] = "Please, correct all errors."; } var modelReturn = GetUserRolesDto(item.UserId.ToString()); return(PartialView("_UserRoles", modelReturn)); }
public async Task <IdentityResult> DeleteUserRoleAsync(UserRolesDto role) { var identityResult = await _identityRepository.DeleteUserRoleAsync(role.UserId, role.RoleId); return(HandleIdentityError(identityResult, _identityServiceResources.UserRoleDeleteFailed().Description, _identityServiceResources.IdentityErrorKey().Description, role)); }
public async Task <BaseApiResponse> GetUserRoles(string userId) { try { if (userId == null) { return(BaseApiResponseHelper.GenerateApiResponse(true, "get roles for user", null, new List <string> { $"User ID is null." })); } var user = await _userManager.FindByIdAsync(userId); if (user == null) { return(BaseApiResponseHelper.GenerateApiResponse(true, "get roles for user", null, new List <string> { $"User ID {userId} did not match any users." })); } var listUserRolesDto = new List <UserRolesDto>(); foreach (var role in await _roleManager.Roles.ToListAsync()) { var userRolesDto = new UserRolesDto { RoleName = role.Name }; if (await _userManager.IsInRoleAsync(user, role.Name)) { userRolesDto.Selected = true; } else { userRolesDto.Selected = false; } listUserRolesDto.Add(userRolesDto); } var data = new UserRolesForEditDto { UserId = user.Id, Username = user.UserName, Email = user.Email, UserRoles = listUserRolesDto }; return(BaseApiResponseHelper.GenerateApiResponse(true, "Get roles for user", new List <UserRolesForEditDto> { data }, null)); } catch (Exception ex) { return(BaseApiResponseHelper.GenerateApiResponse(false, "get roles for user", null, new List <string> { $"{ex.Message}." })); } }
public static UserRole FromDto(UserRolesDto dto) => dto.To <UserRole>();
public async Task <int> AssignRoleToUser(UserRolesDto dto) { var userRole = _mapper.Map <UserRolesDto, UserRoles>(dto); return(await _userRepository.AssignRoleToUser(userRole)); }
public UserRolesDto Update(UserRolesDto entity) { var model = Mapper.Map <UserRoles>(entity); return(Mapper.Map <UserRolesDto>(_userRolesDal.Update(model))); }
public UserRolesDto Add(UserRolesDto entity) { var model = Mapper.Map <UserRoles>(entity); return(Mapper.Map <UserRolesDto>(_userRolesDal.Add(model))); }
public void Delete(UserRolesDto entity) { _userRolesDal.Delete(Mapper.Map <UserRoles>(entity)); }
public UserRolesDto UpdateUserRoleList(UserRolesDto roles) { throw new NotImplementedException(); }