public async Task <IdentityResult> CreateRoleAsync(RoleDto role) { var roleEntity = role.ToEntity(); var identityResult = await _identityRepository.CreateRoleAsync(roleEntity); return(HandleIdentityError(identityResult, _identityServiceResources.RoleCreateFailed().Description, _identityServiceResources.IdentityErrorKey().Description, role)); }
public async Task <IdentityResult> UpdateRoleAsync(RoleDto role) { var canInsert = await CanInsertRoleAsync(role); var roleIdentityEntity = role.ToEntity(); return(await _identityRepository.UpdateRoleAsync(roleIdentityEntity)); }
public async Task DeleteRole(RoleDto role) { var result = await RoleManager.DeleteAsync(role.ToEntity()); if (!result.Succeeded) { Logger.LogWarning(result.Errors.ToString()); } }
public virtual async Task <RoleSelectDto> Create(RoleDto dto, CancellationToken cancellationToken) { var model = dto.ToEntity(_mapper); await _repository.Entities.AddAsync(model, cancellationToken); var role = await _repository.TableNoTracking.ProjectTo <RoleSelectDto>(_mapper.ConfigurationProvider) .SingleOrDefaultAsync(roleSelectDto => roleSelectDto.Id == model.Id, cancellationToken); return(role); }
public virtual async Task <RoleSelectDto> Update(int id, RoleDto dto, CancellationToken cancellationToken) { var model = await _repository.GetByIdAsync(cancellationToken, id); model = dto.ToEntity(_mapper, model); await _repository.UpdateAsync(model, cancellationToken); var role = await _repository.TableNoTracking.ProjectTo <RoleSelectDto>(_mapper.ConfigurationProvider) .SingleOrDefaultAsync(roleSelectDto => roleSelectDto.Id == model.Id, cancellationToken); return(role); }
public async Task <RoleDto> GetRoleAsync(RoleDto role) { var roleEntity = role.ToEntity(); var userIdentityRole = await _identityRepository.GetRoleAsync(roleEntity); if (userIdentityRole == null) { throw new UserFriendlyErrorPageException(string.Format(_identityServiceResources.RoleDoesNotExist().Description, role.Id), _identityServiceResources.RoleDoesNotExist().Description); } var roleDto = userIdentityRole.ToModel(); return(roleDto); }
/// <summary> /// 添加角色 /// </summary> /// <param name="dto">传入角色信息</param> public void AddRole(RoleDto dto) { #region 业务验证 Role role = _roleRepository.Get(t => t.Name == dto.Name); if (role != null) { throw new LsException(string.Format("角色[{0}]已经存在,请确认!", dto.Name)); } #endregion Role entity = dto.ToEntity <Role>(); _roleRepository.Add(entity); }
public async Task <Guid?> CreateRoleAsync(RoleDto role) { var canInsert = await CanInsertRoleAsync(role); if (!canInsert) { return(null); } var roleIdentity = role.ToEntity(); var result = await _identityRepository.CreateRoleAsync(roleIdentity); return(result.roleId); }
public string Update(RoleDto dto) { string message = ""; try { int result = _roleRepository.Update(dto.ToEntity()); message = _messageClass.ShowSuccessMessage(result); } catch (SqlException ex) { message = _messageClass.ShowErrorMessage(string.Format("{0} ~ {1}", ex.Number.ToString(), ex.Message)); } return(message); }
public async Task <RoleDto> AddRoleAsync(RoleDto model) { try { var dbEntity = model.ToEntity <Role>(_mapper); await _roleRepository.InsertAsync(dbEntity); int result = await _unitOfWork.SaveChangesAsync(); model.RoleId = dbEntity.RoleId; } catch (Exception ex) { _logger.LogError(ex, ex.Message); throw ex; } return(model); }
public async Task <bool> CanInsertRoleAsync(RoleDto role) { var roleIdentityEntity = role.ToEntity(); return(await _identityRepository.CanInsertRoleAsync(roleIdentityEntity)); }