public async Task UpdateCompanyRegistrationAsync(Guid id, RegistrationCompanyDTO registration) { RegistrationDataFilter companyFilter = CreateRegistrationCompanyFilter(registration); using (IUnitOfWork uow = this.unitOfWorkFactory.CreateUnitOfWork()) { //Update registration var repo = uow.GetRepository <IRegistrationRepository>(); var existingRegistration = await this.GetRegistrationById(repo, id); this.mapper.Map(registration, existingRegistration); existingRegistration.DateUpdated = DateTime.UtcNow; //Update company data var companyRepo = uow.GetRepository <IRegistrationCompanyRepository>(); var company = await companyRepo.FindRegistrationCompany(companyFilter); if (company == null) { company = new RegistrationCompany(); companyRepo.Add(company); } existingRegistration.CompanyData = company; this.mapper.Map(registration, company); await uow.SaveChangesAsync(); } }
public async Task <IActionResult> Update(Guid id, [FromBody] RegistrationCompanyDTO registration) { // TODO ask what properties can be edited await this.registrationService.UpdateCompanyRegistrationAsync(id, registration); return(NoContent()); }
private static RegistrationDataFilter CreateRegistrationCompanyFilter(RegistrationCompanyDTO registration) { return(new RegistrationDataFilter { Email = registration.Email, Phone = registration.Phone, RegistrationId = registration.RegistrationName }); }
public async Task <IActionResult> CreateCompany([FromBody] RegistrationCompanyDTO createRegistration) { if (createRegistration == null) { return(BadRequest(new { Message = "Invalid input data." })); } var result = await this.registrationService.CreateRegistrationCompanyAsync(createRegistration); IdDTO idDTO = new IdDTO { Id = result.ToString() }; return(CreatedAtRoute("GetRegistration", new { id = result.ToString() }, idDTO)); }
public async Task <Guid> CreateRegistrationCompanyAsync(RegistrationCompanyDTO createRegistration) { var registration = this.mapper.Map <Registration>(createRegistration); registration.DateCreated = TimeProvider.Current.UtcNow; RegistrationDataFilter companyFilter = CreateRegistrationCompanyFilter(createRegistration); using (IUnitOfWork uow = this.unitOfWorkFactory.CreateUnitOfWork()) { var repo = uow.GetRepository <IRegistrationRepository>(); var registrationCompanyRepo = uow.GetRepository <IRegistrationCompanyRepository>(); registration.CompanyData = await registrationCompanyRepo.FindRegistrationCompany(companyFilter) ?? this.mapper.Map <RegistrationCompany>(createRegistration); repo.Add(registration); await uow.SaveChangesAsync(); return(registration.Id); } }
private void SetupFindRegistrationCompanyBy(RegistrationCompanyDTO filter, RegistrationCompany dummyRegistrationCompany) { this.registrationCompanyRepositoryFake .Setup(x => x.FindRegistrationCompany(It.Is <RegistrationDataFilter>(y => y.Email == filter.Email && y.Phone == filter.Phone && y.RegistrationId == filter.RegistrationName))) .ReturnsAsync(dummyRegistrationCompany); }