public ActionResponseDto Edit(TenantInputDto dto) { var tenant = _tenantManager.Get(dto.Id) ?? new Tenant(); Mapper.Map(dto, tenant); bool isNewTenant = tenant.Id == Guid.Empty; // 保存租户 _tenantManager.Save(ref tenant); // 保存超级管理员 using (UnitOfWork.DisableFilter(typeof(OwnerTenantFilter))) { var superAdmin = _userManager.Get(u => u.Username == dto.SuperAdminName && u.OwnerTenantId == tenant.Id) ?? new User(); superAdmin.Type = SuperAdminUserType.ConstType; superAdmin.Username = dto.SuperAdminName; superAdmin.OwnerTenant = tenant; if (dto.SuperAdminPassword != dto.SuperAdminConfirmPassword) { throw new BadRequestException("Confirm password not matched with password"); } else if (!string.IsNullOrEmpty(dto.SuperAdminPassword)) { superAdmin.SetPassword(dto.SuperAdminPassword); } else if (superAdmin.Id == Guid.Empty) { throw new BadRequestException("Please provider a password for new user"); } _userManager.Save(ref superAdmin); } return(ActionResponseDto.CreateSuccess("Saved Successfully")); }
private void AddDataAlreadyExistsProblem(TenantInputDto tenant) { _problemCollector.AddProblem(new CodedProblemDetails ( ProblemType.ERROR_DATA_ALREADY_EXISTS, $"{nameof(Tenant)}.{nameof(tenant.TenantName)}", tenant.TenantName )); }
public async Task <ActionResult> CreateAsync([FromBody] TenantInputDto tenantInput) { var tenant = Mapper.Map <Tenant>(tenantInput); await CustomerLogic.CreateTenantAsync(tenant); var errorResult = CheckProblems(); if (errorResult != null) { return(errorResult); } await PublishEndpoint.Publish <ITenantCreatedEvent>(new { Tenant = tenant }); return(CreatedAtAction( Url.Action(nameof(GetAsync)), new { id = tenant.Id }, tenant)); }