public ReplaceStudentsAggregate(RepositoryContext context, Guid classId, Guid[] studentsId) : base(context)
        {
            RootEntity = new ClassEnrollmentEntity
            {
                Id = new ClassEnrollmentEntityId
                {
                    ClassId = classId
                }
            };

            var removeBinaryEntities = new DeleteLinksCommandOperation <ClassEnrollmentEntity>(RootEntity, selector: null);

            Enqueue(removeBinaryEntities);

            foreach (var studentId in studentsId)
            {
                RootEntity = new ClassEnrollmentEntity
                {
                    Id = new ClassEnrollmentEntityId
                    {
                        ClassId   = classId,
                        StudentId = studentId
                    },
                    StartedDateTime = DateTime.Now
                };

                var insertBinaryEntity = new InsertEntityCommandOperation <ClassEnrollmentEntity>(RootEntity);

                Enqueue(insertBinaryEntity);
            }
        }
Ejemplo n.º 2
0
        public ClassEnrollmentCommandAggregate(RepositoryContext context, ClassEnrollmentDto classEnrollment) : base(context)
        {
            RootEntity = new ClassEntity
            {
                Name = classEnrollment.Name
            };

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

            if (classEnrollment.StudentsToEnroll?.Any() == true)
            {
                foreach (var studentToEnroll in classEnrollment.StudentsToEnroll)
                {
                    var studentEntity = new StudentEntity
                    {
                        FirstName = studentToEnroll.FirstName
                    };

                    StudentsToEnroll.Add(studentEntity);

                    var createStudentOperation = new InsertEntityCommandOperation <StudentEntity>(studentEntity);

                    Enqueue(createStudentOperation);

                    var classEnrollmentEntity = new ClassEnrollmentEntity
                    {
                        StartedDateTime = studentToEnroll.StartedDateTime
                    };

                    ClassEnrollments.Add(classEnrollmentEntity);

                    var createEnrollmentOperation = new InsertEntityCommandOperation <ClassEnrollmentEntity>(
                        classEnrollmentEntity,
                        new EntityDependency[]
                    {
                        new EntityDependency
                        {
                            Entity = RootEntity
                        },
                        new EntityDependency
                        {
                            Entity = studentEntity
                        }
                    });

                    Enqueue(createEnrollmentOperation);
                }
            }
        }
Ejemplo n.º 3
0
        public PersonFriendsCommandAggregate(RepositoryContext context, PersonWithFriendsDto personWithFriends) : base(context)
        {
            RootEntity = new PersonEntity
            {
                FirstName = personWithFriends.FirstName
            };

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

            foreach (var friend in personWithFriends.Friends)
            {
                var friendEntity = new PersonEntity
                {
                    FirstName = friend.FirstName
                };

                var createFriend = new SaveEntityCommandOperation <PersonEntity>(friendEntity);

                Enqueue(createFriend);

                var binaryEntity = new FriendshipEntity
                {
                    AcceptedDateTime = friend.AcceptedDateTime
                };

                var addBinaryEntity = new InsertEntityCommandOperation <FriendshipEntity>(
                    binaryEntity,
                    new EntityDependency[]
                {
                    new EntityDependency
                    {
                        Entity = RootEntity
                    },
                    new EntityDependency
                    {
                        Entity = friendEntity
                    }
                }
                    );

                Enqueue(addBinaryEntity);
            }
        }