Esempio n. 1
0
        public async Task <DataResult> Handle(Command request, CancellationToken cancellationToken)
        {
            ParticipantGroupClass member = await _context.GroupClassMembers
                                           .Where(x => x.Id == request.MemberId)
                                           .Include(x => x.Passes)
                                           .FirstOrDefaultAsync(cancellationToken);

            Model.Domain.Pass pass = member.Passes.FirstOrDefault();
            if (pass != null)
            {
                pass.Paid = request.Status;
                _context.Update(pass);
            }

            await _context.SaveChangesAsync(cancellationToken);

            return(DataResult.Success());
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public async Task <DataResult <PassMessage> > Handle(Command request, CancellationToken cancellationToken)
        {
            ParticipantClassTime participantPresence = await _context.ParticipantPresences
                                                       .Where(x => x.Id == request.ParticipantClassTimeId)
                                                       .FirstOrDefaultAsync(cancellationToken);

            var classTimes = await _context.ClassTimes.Where(x => x.Id == participantPresence.ClassTimeId).Select(x => new { x.GroupClassId, x.StartDate }).FirstOrDefaultAsync(cancellationToken);


            List <Model.Domain.Pass> passes = await _context.Passes
                                              .Include(x => x.ParticipantGroupClass)
                                              .Where(x => x.ParticipantId == participantPresence.ParticipantId)
                                              .Where(x => x.ParticipantGroupClass.GroupClassId == classTimes.GroupClassId)
                                              .ToListAsync(cancellationToken);

            Model.Domain.Pass activePass = passes
                                           .Where(x => x.Status == Model.Domain.Pass.PassStatus.Active)
                                           .OrderBy(x => x.PassNumber)
                                           .FirstOrDefault();

            if (activePass is null)
            {
                await GenerateNextPass(cancellationToken, passes, classTimes.StartDate, participantPresence);

                return(DataResult <PassMessage> .Success(PassMessage.Error("Brak ważnego karnetu")));
            }

            PassAggregate passAggregate = PassAggregate.FromState(activePass);

            passAggregate.UsePass(participantPresence);
            _context.Update(passAggregate.State);
            _context.Update(participantPresence);
            await _context.SaveChangesAsync(cancellationToken);

            return(DataResult <PassMessage> .Success(PassMessage.Success("Udanej nauki!")));
        }
Esempio n. 4
0
        public async Task <DataResult> Handle(Command request, CancellationToken cancellationToken)
        {
            ParticipantClassTime participantPresence = await _context.ParticipantPresences
                                                       .Include(x => x.Pass)
                                                       .Where(x => x.ParticipantId == request.ParticipantId)
                                                       .Where(x => x.ClassTimeId == request.ClassTimeId)
                                                       .FirstOrDefaultAsync(cancellationToken);

            Model.Domain.Pass pass = participantPresence.Pass;
            if (pass is null)
            {
                if (participantPresence.PresenceType != PresenceType.Help)
                {
                    return(DataResult.Error("Karnet nie został zarejestrowany "));
                }

                return(DataResult.Success());
            }
            PassAggregate passAggregate = PassAggregate.FromState(pass);

            passAggregate.ReturnPass(participantPresence);

            if (pass.WasGenerateAutomatically && pass.Used == 0)
            {
                _context.Remove(pass);
            }
            else
            {
                _context.Update(pass);
            }

            _context.Update(participantPresence);
            await _context.SaveChangesAsync(cancellationToken);

            return(DataResult.Success());
        }