public static async Task Execute(DeleteEmployeeInfo model, IEmployeeAggregateRepository repo, IUnitOfWork unitOfWork) { var employee = await repo.GetByIdAsync(model.Id) ?? throw new InvalidOperationException($"An employee with id '{model.Id}' could not be found!"); if (employee.Addresses().Count > 0) { foreach (Address address in employee.Addresses()) { employee.DeleteAddress(address.Id); } } if (employee.ContactPersons().Count > 0) { foreach (ContactPerson contact in employee.ContactPersons()) { employee.DeleteContactPerson(contact.Id); } } repo.Delete(employee); await unitOfWork.Commit(); }
public static Task Execute(IWriteModel model, IEmployeeAggregateRepository repo, IUnitOfWork unitOfWork) => model switch {
public EmployeeAggregateCommandHandler(IEmployeeAggregateRepository repo, IUnitOfWork unitOfWork) { _employeeRepo = repo; _unitOfWork = unitOfWork; }
public EmployeeAggregateRepoTests() { TestDataInitialization.InitializeData(_dbContext); _unitOfWork = new AppUnitOfWork(_dbContext); _employeeRepo = new EmployeeAggregateRepository(_dbContext); }
public static async Task Execute(EditEmployeeInfo model, IEmployeeAggregateRepository repo, IUnitOfWork unitOfWork) { var employee = await repo.GetByIdAsync(model.Id) ?? throw new InvalidOperationException($"An employee with id '{model.Id}' could not be found!"); if (model.Status == RecordStatus.Modified) { employee.UpdateSupervisorId(SupervisorId.Create(model.SupervisorId)); employee.UpdateEmployeeName(PersonName.Create(model.FirstName, model.LastName, model.MiddleInitial)); employee.UpdateSSN(SSN.Create(model.SSN)); employee.UpdateTelephone(PhoneNumber.Create(model.Telephone)); employee.UpdateMaritalStatus(MaritalStatus.Create(model.MaritalStatus)); employee.UpdateTaxExemptions(TaxExemption.Create(model.Exemptions)); employee.UpdatePayRate(PayRate.Create(model.PayRate)); employee.UpdateLastModifiedDate(); if (model.IsActive) { employee.Activate(); } else if (!model.IsActive) { employee.Deactivate(); } } if (model.Addresses != null && model.Addresses.Count > 0) { foreach (var address in model.Addresses) { if (address.Status == RecordStatus.New) { employee.AddAddress(0, AddressVO.Create(address.AddressLine1, address.AddressLine2, address.City, address.StateCode, address.Zipcode)); } else if (address.Status == RecordStatus.Modified) { employee.UpdateAddress(address.AddressId, AddressVO.Create(address.AddressLine1, address.AddressLine2, address.City, address.StateCode, address.Zipcode)); } else if (address.Status == RecordStatus.Deleted) { employee.DeleteAddress(address.AddressId); } } } if (model.Contacts != null && model.Contacts.Count > 0) { foreach (var contact in model.Contacts) { if (contact.Status == RecordStatus.New) { employee.AddContactPerson(0, PersonName.Create(contact.FirstName, contact.LastName, contact.MiddleInitial), PhoneNumber.Create(contact.Telephone), contact.Notes); } else if (contact.Status == RecordStatus.Modified) { employee.UpdateContactPerson(contact.PersonId, PersonName.Create(contact.FirstName, contact.LastName, contact.MiddleInitial), PhoneNumber.Create(contact.Telephone), contact.Notes); } if (contact.Status == RecordStatus.Deleted) { employee.DeleteContactPerson(contact.PersonId); } } } await unitOfWork.Commit(); }
public EmployeePatchActionAttribute(IEmployeeAggregateRepository repo, ILoggerManager logger) { _employeeRepo = repo; _logger = logger; }
public static async Task Execute(CreateEmployeeInfo model, IEmployeeAggregateRepository repo, IUnitOfWork unitOfWork) { if (await repo.Exists(model.Id)) { throw new InvalidOperationException($"This employee ({model.FirstName} {model.MiddleInitial ?? ""} {model.LastName}) already exists!"); } ExternalAgent agent = new(model.Id, AgentType.Employee); Employee employee = new Employee ( agent, SupervisorId.Create(model.SupervisorId), PersonName.Create(model.FirstName, model.LastName, model.MiddleInitial), SSN.Create(model.SSN), PhoneNumber.Create(model.Telephone), MaritalStatus.Create(model.MaritalStatus), TaxExemption.Create(model.Exemptions), PayRate.Create(model.PayRate), StartDate.Create(model.StartDate), IsActive.Create(model.IsActive) ); if (model.Addresses != null && model.Addresses.Count > 0) { foreach (var address in model.Addresses) { employee.AddAddress( 0, AddressVO.Create ( address.AddressLine1, address.AddressLine2, address.City, address.StateCode, address.Zipcode ) ); } } if (model.Contacts != null && model.Contacts.Count > 0) { foreach (var contact in model.Contacts) { employee.AddContactPerson ( 0, PersonName.Create(contact.FirstName, contact.LastName, contact.MiddleInitial), PhoneNumber.Create(contact.Telephone), contact.Notes ); } } await repo.AddAsync(employee); await unitOfWork.Commit(); model.Id = employee.Id; }