public async Task <DataResult> Handle(Command request, CancellationToken cancellationToken)
        {
            User participant = await _context.Users.Where(x => x.Id == request.ParticipantId).FirstOrDefaultAsync(cancellationToken);

            if (participant is null)
            {
                return(DataResult.Error(PolishReadableMessage.Presence.ParticipantNotFound));
            }

            ClassTime classTime = await _context.ClassTimes
                                  .Where(x => x.Id == request.ClassTimeId)
                                  .Include(x => x.PresenceParticipants)
                                  .FirstOrDefaultAsync(cancellationToken);

            if (classTime is null)
            {
                return(DataResult.Error(PolishReadableMessage.Presence.ClassNotFound));
            }

            ClassTimeAggregate   classTimeAggregate   = ClassTimeAggregate.FromState(classTime);
            ParticipantClassTime participantClassTime = classTimeAggregate.AddParticipant(participant, PresenceType.Help);

            participantClassTime.WasPresence = true;
            await _context.AddAsync(participantClassTime, cancellationToken);

            _context.Update(classTimeAggregate.State);
            await _context.SaveChangesAsync(cancellationToken);

            return(DataResult.Success());
        }
Exemple #2
0
        public async Task <bool> Handle(Command request, CancellationToken cancellationToken)
        {
            Room room = new Room()
                        .WithColor(request.Color)
                        .WithName(request.Name);

            bool isRoomExist = await _context.Rooms
                               .AnyAsync(x => x.NormalizeName == room.NormalizeName, cancellationToken);

            if (isRoomExist)
            {
                throw new AddRoomException(PolishReadableMessage.Room.NameDuplicate);
            }

            await _context.AddAsync(room, cancellationToken);

            await _context.SaveChangesAsync(cancellationToken);

            return(true);
        }
        private async Task GenerateNextPass(CancellationToken cancellationToken, List <Model.Domain.Pass> passes, DateTime startDate,
                                            ParticipantClassTime participantPresence)
        {
            Model.Domain.Pass lastPass = passes.Where(x => x.Status == Model.Domain.Pass.PassStatus.NotActive)
                                         .OrderBy(x => x.PassNumber).First();
            Model.Domain.Pass newPass          = lastPass.Copy();
            PassAggregate     newPassAggregate = PassAggregate.FromState(newPass);

            newPassAggregate.AsActive()
            .WithStartDate(startDate)
            .WithPassNumber(passes.Count)
            .AsGenerateAutomatically();
            newPassAggregate.UsePass(participantPresence);

            await _context.AddAsync(newPassAggregate.State, cancellationToken);

            _context.Update(participantPresence);

            await _context.SaveChangesAsync(cancellationToken);
        }