Ejemplo n.º 1
0
        public async Task <DataResult> Handle(Command request, CancellationToken cancellationToken)
        {
            ClassTime classTime = await _context.ClassTimes
                                  .Include(x => x.PresenceParticipants)
                                  .Where(x => x.Id == request.ClassTimeId)
                                  .Include(x => x.PresenceParticipants)
                                  .FirstOrDefaultAsync(cancellationToken);

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

            ParticipantClassTime participantClassTime = classTime.PresenceParticipants.FirstOrDefault(x => x.ParticipantId == request.ParticipantId);

            if (participantClassTime is null)
            {
                return(DataResult.Error(PolishReadableMessage.Presence.ParticipantNotFound));
            }
            if (participantClassTime.PresenceType != PresenceType.Help)
            {
                return(DataResult.Error(PolishReadableMessage.Presence.RemoveWrongType));
            }
            ClassTimeAggregate classTimeAggregate = ClassTimeAggregate.FromState(classTime);

            classTimeAggregate.RemoveParticipant(participantClassTime.ParticipantId);
            _context.Remove(participantClassTime);
            _context.Update(classTimeAggregate.State);
            await _context.SaveChangesAsync(cancellationToken);

            return(DataResult.Success());
        }
Ejemplo n.º 2
0
        public async Task <DataResult> Handle(Command request, CancellationToken cancellationToken)
        {
            ClassTime classTime = await _context.ClassTimes.Where(x => x.Id == request.Id)
                                  .Include(x => x.GroupClass)
                                  .FirstOrDefaultAsync(cancellationToken);

            ClassTimeAggregate.FromState(classTime)
            .WithDate(request.Start, request.End);

            //Update order
            List <ClassTime> allClasses = await _context.ClassTimes.Where(x => x.Id != request.Id)
                                          .Where(x => x.GroupClassId == classTime.GroupClassId)
                                          .OrderBy(x => x.StartDate)
                                          .ToListAsync(cancellationToken);

            allClasses.Add(classTime);
            allClasses = allClasses.OrderBy(x => x.StartDate).ToList();
            int nextNumber = 1;

            allClasses.ForEach(x =>
            {
                x.NumberOfClass   = nextNumber++;
                x.NumberOfClasses = classTime.GroupClass.NumberOfClasses;
            });



            _context.UpdateRange(allClasses);
            await _context.SaveChangesAsync(cancellationToken);

            return(DataResult.Success());
        }
Ejemplo n.º 3
0
        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());
        }