public SaveEmployeePersonCommandAggregate(DataAccess.RepositoryContext context, string firstName, int salary) : base(context)
        {
            Person = new PersonEntity
            {
                FirstName = firstName
            };

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

            Enqueue(savePerson);

            RootEntity = new EmployeeEntity
            {
                Salary = salary
            };

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

            Enqueue(saveEmployee);
        }
Exemplo n.º 2
0
        public DeleteExecutiveEmployeePersonCommandAggregate(DataAccess.RepositoryContext context, int?executiveId) : base(context)
        {
            RootEntity = new ExecutiveEntity
            {
                Id = executiveId
            };

            Enqueue(
                new DeleteEntityCommandOperation <ExecutiveEntity>(RootEntity)
                );
        }
        public PersonSpouseQueryAggregate(DataAccess.RepositoryContext context) : base(context, null)
        {
            GetSpouseLoadOperation = new GetSingleLinkedEntityQueryOperation <PersonEntity2>
            {
                GetLinkedEntity = (repository, entity, user) =>
                                  ((PersonQueryRepository2)repository).GetForPerson(RootEntity.Id),

                GetLinkedEntityAsync = async(repository, entity, user) =>
                                       await((PersonQueryRepository2)repository).GetForPersonAsync(RootEntity.Id)
            };

            QueryOperations.Enqueue(
                GetSpouseLoadOperation
                );
        }
Exemplo n.º 4
0
        public ManagerEmployeesQueryAggregate(DataAccess.RepositoryContext context) : base(context, null)
        {
            GetEmployeesLoadOperation = new GetCollectionLinkedEntityQueryOperation <PersonEntity3>
            {
                //GetLinkedEntities = (repository, entity, user) =>
                //    ((PersonQueryRepository4)repository).GetForManager(RootEntity.Id, user).ToList(),

                GetLinkedEntitiesAsync = async(repository, entity, user) =>
                {
                    var entities = await((PersonQueryRepository4)repository).GetForManagerAsync(RootEntity.Id);

                    return(entities.ToList());
                }
            };

            QueryOperations.Enqueue(
                GetEmployeesLoadOperation
                );
        }
        public PersonSpouseCommandAggregate(DataAccess.RepositoryContext context, PersonSpouseDto personSpouse) : base(context)
        {
            // Save the spouse first so we can link to it
            Spouse = new PersonEntity2
            {
                FirstName = personSpouse.SpouseName
            };

            Enqueue(
                new SaveEntityCommandOperation <PersonEntity2>(Spouse)
                );

            // Save the root entity
            RootEntity = new PersonEntity2
            {
                FirstName = personSpouse.FirstName
            };

            Enqueue(
                new SaveEntityCommandOperation <PersonEntity2>(
                    RootEntity,
                    new EntityDependency[]
            {
                new EntityDependency
                {
                    Entity = Spouse
                }
            })
                );

            // Update the spouse to link to tue root entity
            Enqueue(
                new UpdateEntityCommandOperation <PersonEntity2>(
                    Spouse,
                    new EntityDependency[]
            {
                new EntityDependency
                {
                    Entity = RootEntity
                }
            })
                );
        }
        public CountryCapitalCityQueryAggregate() : base(null, null)
        {
            RepositoryContext = new DataAccess.RepositoryContext("SqlServerTest.DomainFrameworkOneToOneTest.ConnectionString");

            RepositoryContext.RegisterQueryRepository <CountryEntity>(new CountryQueryRepository());

            RepositoryContext.RegisterQueryRepository <CapitalCityEntity>(new CapitalCityQueryRepository());

            GetCapitalCityLoadOperation = new GetSingleLinkedEntityQueryOperation <CapitalCityEntity>
            {
                GetLinkedEntity = (repository, entity, user) =>
                                  ((CapitalCityQueryRepository)repository).GetForCountry(RootEntity.Id),

                GetLinkedEntityAsync = async(repository, entity, user) =>
                                       await((CapitalCityQueryRepository)repository).GetForCountryAsync(RootEntity.Id)
            };

            QueryOperations.Enqueue(
                GetCapitalCityLoadOperation
                );
        }
Exemplo n.º 7
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
                        }
                    })
                        );
                }
            }
        }