private Employee GetEmployeeWithAddresses()
        {
            var employeeAgent = new ExternalAgent(Guid.NewGuid(), AgentType.Employee);
            var employee      = new Employee
                                (
                employeeAgent,
                SupervisorId.Create(Guid.NewGuid()),
                PersonName.Create("George", "Orwell", "Z"),
                SSN.Create("123789999"),
                PhoneNumber.Create("817-987-1234"),
                MaritalStatus.Create("M"),
                TaxExemption.Create(5),
                PayRate.Create(40.00M),
                StartDate.Create(new DateTime(1998, 12, 2)),
                IsActive.Create(true)
                                );

            employee.AddAddress(1, AddressVO.Create("123 Main Terrace", "#4", "Somewhere", "TX", "78885"));
            employee.AddAddress(2, AddressVO.Create("123 Main Plaza", "Apt 13", "nowhere", "TX", "78981"));

            return(employee);
        }
Exemplo n.º 2
0
        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;
        }