public async Task UpdateTenant(TenantEditDto input) { if (await _repository.FirstOrDefaultAsync(t => t.TenancyName == input.TenancyName && t.Id != input.Id) != null) { throw new UserFriendlyException(string.Format(L("TenancyNameIsAlreadyTaken"), input.TenancyName)); } var tenant = await _repository.FirstOrDefaultAsync(input.Id); if (tenant == null) { throw new AbpException("There is no tenant with id: " + input.Id); } input.MapTo(tenant); await _repository.UpdateAsync(tenant); }
public async Task UpdateUser(UserEditDto input) { var user = await _repository.FirstOrDefaultAsync(x => x.Id == input.Id); if (user == null) { throw new AbpException("There is no user with id: " + input.Id); } input.MapTo(user); if (!input.Password.IsNullOrEmpty()) { var rs = await new PasswordValidator().ValidateAsync(input.Password); rs.CheckErrors(); user.Password = new PasswordHasher().HashPassword(input.Password); } var usr = await _repository.FirstOrDefaultAsync(x => x.UserName == user.UserName); if (usr != null && usr.Id != input.Id) { throw new UserFriendlyException(string.Format(L("Identity.DuplicateName"), user.UserName)); } usr = await _repository.FirstOrDefaultAsync(x => x.Email == user.Email); if (usr != null && usr.Id != input.Id) { throw new UserFriendlyException(string.Format(L("Identity.DuplicateEmail"), user.Email)); } var oldUserName = user.UserName; if (oldUserName == "admin" && input.UserName != "admin") { throw new UserFriendlyException(string.Format(L("CanNotRenameAdminUser"), "admin")); } await _repository.UpdateAsync(user); }
public async Task CreateOrUpdate(IEnumerable <RoleRightDto> inputs) { foreach (var item in inputs) { var rs = item.MapTo <RoleRightEntity>(); if (!item.Id.HasValue) { if (await _roleRightRepository.FirstOrDefaultAsync( x => x.ActionModuleId == item.ActionModuleId && x.RoleId == item.RoleId) == null) { rs.Id = Guid.NewGuid(); await _roleRightRepository.InsertAsync(rs); } } else { await _roleRightRepository.UpdateAsync(rs); } } }
public async Task Update(RoleEditDto input) { var rs = await _repository.FirstOrDefaultAsync(x => x.Id == input.Id); if (rs == null) { throw new UserFriendlyException(string.Format("There is no role with id : {0}", input.Id)); } input.MapTo(rs); var result = await _repository.FirstOrDefaultAsync(x => x.RoleCode == input.RoleCode); if (result != null && result.Id != input.Id) { throw new UserFriendlyException(string.Format(L("DuplicateRoleCode"), input.RoleCode)); } await _repository.UpdateAsync(rs); }
public async Task CreateOrUpdate(IEnumerable <ActionModuleDto> inputs) { foreach (var item in inputs) { var mapped = item.MapTo <ActionModuleEntity>(); if (!item.Id.HasValue) { if ( await _actionModuleRepository.FirstOrDefaultAsync( x => x.ActionId == item.ActionId && x.ModuleId == item.ModuleId) == null) { mapped.Id = Guid.NewGuid(); await _actionModuleRepository.InsertAsync(mapped); } } else { await _actionModuleRepository.UpdateAsync(mapped); } } }