Exemplo n.º 1
0
        public async Task <DataResult> Handle(Command request, CancellationToken cancellationToken)
        {
            Model.Domain.GroupClass groupClass = await _context.GroupClass
                                                 .Include(x => x.Anchors)
                                                 .ThenInclude(x => x.User)
                                                 .Include(x => x.GroupLevel)
                                                 .Include(x => x.Participants)
                                                 .ThenInclude(x => x.User)
                                                 .Include(x => x.Room)
                                                 .Include(x => x.Schedule)
                                                 .Include(x => x.ClassDaysOfWeek)
                                                 .Where(x => x.Id == request.GroupClassId)
                                                 .FirstOrDefaultAsync(cancellationToken);

            GroupClassAggregate groupClassAggregate = GroupClassAggregate.FromState(groupClass).UpdateAll(request);


            await UpdateAnchors(request, groupClassAggregate, cancellationToken);

            await UpdateRoom(request, groupClass, groupClassAggregate, cancellationToken);

            await UpdateGroupLevel(request, groupClass, groupClassAggregate, cancellationToken);

            await UpdateMembers(request, groupClassAggregate, cancellationToken);

            groupClassAggregate.UpdateDaysOfWeek(request, _context).CreateSchedule(request);

            _context.GroupClass.Update(groupClass);
            await _context.SaveChangesAsync(cancellationToken);

            return(DataResult.Success());
        }
Exemplo n.º 2
0
        private async Task AddParticipantsToGroup(Command request, CancellationToken cancellationToken,
                                                  List <GroupUser> users, List <User> usersToGroup)
        {
            Model.Domain.GroupClass groupClass = await _context
                                                 .GroupClass
                                                 .Include(x => x.Participants)
                                                 .Include(x => x.Schedule)
                                                 .ThenInclude(x => x.PresenceParticipants)
                                                 .Where(x => x.Id == request.GroupId)
                                                 .FirstOrDefaultAsync(cancellationToken);

            GroupClassAggregate groupClassAggregate = GroupClassAggregate.FromState(groupClass);

            foreach (User user in usersToGroup)
            {
                if (groupClassAggregate.IsParticipantExists(user.Id))
                {
                    continue;
                }
                PassAggregate passAggregate = PassAggregate.New()
                                              .WithStartDate(groupClass.StartClasses)
                                              .WithPrice(groupClass.PassPrice)
                                              .WithNumberOfEntry(groupClass.NumberOfClasses)
                                              .WithParticipant(user);
                GroupUser groupUser = users.First(x => x.Email == user.Email);
                groupClassAggregate.AddParticipant(user, groupUser.Role, passAggregate);
            }

            _context.GroupClass.Update(groupClass);
        }
Exemplo n.º 3
0
        private async Task UpdateRoom(Command request, Model.Domain.GroupClass groupClass, GroupClassAggregate groupClassAggregate,
                                      CancellationToken cancellationToken)
        {
            if (request.RoomId != default && request.RoomId != groupClass.Room?.Id)
            {
                Room room = await _context.Rooms.Where(x => x.Id == request.RoomId.Value)
                            .FirstOrDefaultAsync(cancellationToken);

                groupClassAggregate.WithRoom(room);
            }
        }
Exemplo n.º 4
0
        private async Task UpdateGroupLevel(Command request, Model.Domain.GroupClass groupClass, GroupClassAggregate groupClassAggregate,
                                            CancellationToken cancellationToken)
        {
            if (request.GroupLevelId != default && request.GroupLevelId != groupClass.GroupLevel?.Id)
            {
                GroupLevel groupLevel = await _context.GroupLevel.Where(x => x.Id == request.GroupLevelId.Value)
                                        .FirstOrDefaultAsync(cancellationToken);

                groupClassAggregate.WithGroupLevel(groupLevel);
            }
        }