public async Task Create(RoleCreateDto input) { if (await _repository.FirstOrDefaultAsync(x => x.RoleCode == input.RoleCode) != null) { throw new UserFriendlyException(string.Format(L("DuplicateRoleCode"), input.RoleCode)); } var role = input.MapTo <RoleEntity>(); role.Id = Guid.NewGuid(); await _repository.InsertAsync(role); }
public async Task Create(ActionCreateDto input) { if (await _repository.FirstOrDefaultAsync(x => x.ActionCode == input.ActionCode) != null) { throw new UserFriendlyException(string.Format(L("Identity.DuplicateActionCode"), input.ActionCode)); } var action = input.MapTo <ActionEntity>(); action.Id = Guid.NewGuid(); await _repository.InsertAsync(action); }
public async Task Create(ModuleCreateDto input) { var module = await _repository.FirstOrDefaultAsync(x => x.ModuleCode == input.ModuleCode); if (module != null) { throw new UserFriendlyException(string.Format(L("DuplicateModuleCode"), input.ModuleCode)); } var mapped = input.MapTo <ModuleEntity>(); mapped.Id = Guid.NewGuid(); await _repository.InsertAsync(mapped); }
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 CreateTenant(CreateTenantDto input) { var tenant = new TenantEntity(input.TenancyName, input.DisplayName) { IsActive = input.IsActive }; if (await _repository.FirstOrDefaultAsync(x => x.TenancyName == tenant.TenancyName) != null) { throw new UserFriendlyException(string.Format(L("TenancyNameIsAlreadyTaken"), tenant.TenancyName)); } await _repository.InsertAsync(tenant); await CurrentUnitOfWork.SaveChangesAsync(); //To get new tenant's id. //We are working entities of new tenant, so changing tenant filter CurrentUnitOfWork.SetFilterParameter(AbpDataFilters.MayHaveTenant, AbpDataFilters.Parameters.TenantId, tenant.Id); }
public async Task <Guid> CreateUser(CreateUserDto input) { var user = input.MapTo <UserEntity>(); var userId = Guid.NewGuid(); user.Id = Guid.NewGuid(); if (!input.Password.IsNullOrEmpty()) { var rs = await new PasswordValidator().ValidateAsync(input.Password); rs.CheckErrors(); } else { input.Password = UserEntity.CreateRandomPassword(); } user.Password = new PasswordHasher().HashPassword(input.Password); if (await _repository.FirstOrDefaultAsync(x => x.UserName == user.UserName) != null) { throw new UserFriendlyException(string.Format(L("Identity.DuplicateName"), user.UserName)); } if (await _repository.FirstOrDefaultAsync(x => x.Email == user.Email) != null) { throw new UserFriendlyException(string.Format(L("Identity.DuplicateEmail"), user.Email)); } if (AbpSession.TenantId.HasValue && AbpSession.TenantId != default(Guid)) { user.TenantId = AbpSession.TenantId.Value; } await _repository.InsertAsync(user); return(user.Id); }
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); } } }