Example #1
0
        public SaveExecutiveEmployeePersonCommandAggregate(DataAccess.RepositoryContext context,
                                                           string firstName, decimal salary, decimal bonus) : base(context)
        {
            Person = new PersonEntity
            {
                FirstName = firstName
            };

            var savePerson = new SaveEntityCommandOperation <PersonEntity>(Person);

            Enqueue(savePerson);

            Employee = new EmployeeEntity
            {
                Salary = salary
            };

            var saveEmployee = new SaveEntityCommandOperation <EmployeeEntity>(Employee,
                                                                               new EntityDependency[]
            {
                new EntityDependency
                {
                    Entity = Person
                }
            });

            Enqueue(saveEmployee);

            RootEntity = new ExecutiveEntity
            {
                Bonus = bonus
            };

            var saveExecutive = new SaveEntityCommandOperation <ExecutiveEntity>(RootEntity,
                                                                                 new EntityDependency[]
            {
                new EntityDependency
                {
                    Entity = Employee
                }
            });

            Enqueue(saveExecutive);
        }
Example #2
0
        public DepartmentCommandAggregate(DataAccess.RepositoryContext context, DepartmentDto department) : base(context)
        {
            RootEntity = new DepartmentEntity
            {
                Name = department.Name
            };

            Enqueue(new SaveEntityCommandOperation <DepartmentEntity>(RootEntity));

            foreach (var employee in department.Employees)
            {
                // Create the employee
                var personEntity = new PersonEntity
                {
                    FirstName = employee.FirstName
                };

                Enqueue(
                    new SaveEntityCommandOperation <PersonEntity>(personEntity)
                    );

                // Set the salary and department id
                var employeeRoleEntity = new EmployeeRoleEntity
                {
                    Salary = employee.Salary
                };

                Enqueue(
                    new SaveEntityCommandOperation <EmployeeRoleEntity>(
                        employeeRoleEntity,
                        new EntityDependency[]
                {
                    new EntityDependency
                    {
                        Entity = RootEntity
                    },
                    new EntityDependency
                    {
                        Entity = personEntity
                    }
                })
                    );

                if (employee.IsManager)
                {
                    var departmentManagerRoleEntity = new DepartmentManagerRoleEntity();

                    Enqueue(
                        new SaveEntityCommandOperation <DepartmentManagerRoleEntity>(
                            departmentManagerRoleEntity,
                            new EntityDependency[]
                    {
                        new EntityDependency
                        {
                            Entity = employeeRoleEntity
                        },
                        new EntityDependency
                        {
                            Entity = RootEntity
                        }
                    })
                        );
                }
            }
        }