public static CompanyEnrollment ToCompanyEnrollment(this CreateCompanyEnrollmentCommand command) { if (command == null) { return(null); } return(new CompanyEnrollment() { CompanyId = command.CompanyId, UserId = command.UserId, IsCompanyCreator = command.IsCompanyCreator }); }
void ICompanyService.CreateCompany(CreateCompanyCommand command) { try { Company companyToCreate = command.ToCompany(); companyRepository.CreateCompany(companyToCreate); companyRepository.Save(); CreateCompanyEnrollmentCommand enrollmentCommand = new CreateCompanyEnrollmentCommand() { CompanyId = companyToCreate.Id, IsCompanyCreator = true, UserId = command.UserId }; companyEnrollmentRepository.CreateCompanyEnrollment(enrollmentCommand.ToCompanyEnrollment()); companyEnrollmentRepository.Save(); } catch (DbUpdateException ex) { throw new DbUpdateException("Service failed.\n" + ex.Message, ex.InnerException); } }