public async Task <DataResult <int> > Handle(Command request, CancellationToken cancellationToken) { User participant = await _context.Users.Where(x => x.Id == request.ParticipantId).FirstOrDefaultAsync(cancellationToken); if (participant is null) { return(DataResult <int> .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 <int> .Error(PolishReadableMessage.Presence.ClassNotFound)); } var makeUpClassTime = await _context.ParticipantPresences .Include(x => x.ClassTime) .Where(x => x.ParticipantId == request.ParticipantId) .Where(x => !x.WasPresence) .Where(x => x.PresenceType == PresenceType.None) .Where(x => x.ClassTime.StartDate < classTime.StartDate) .OrderBy(x => x.ClassTime.StartDate) .FirstOrDefaultAsync(cancellationToken); if (makeUpClassTime is null) { return(DataResult <int> .Error(PolishReadableMessage.Presence.MakeUpClassNotFound)); } ClassTimeAggregate classTimeAggregate = ClassTimeAggregate.FromState(classTime); ParticipantClassTime participantClassTime = classTimeAggregate.AddParticipant(participant, makeUpClassTime); participantClassTime.WasPresence = true; await _context.AddAsync(participantClassTime, cancellationToken); _context.Update(makeUpClassTime); _context.Update(classTimeAggregate.State); await _context.SaveChangesAsync(cancellationToken); return(DataResult <int> .Success(makeUpClassTime.Id)); }
public async Task <DataResult <ClaimsPrincipal> > Handle(Command request, CancellationToken cancellationToken) { Model.Domain.User user = await _signInManager.UserManager.FindByEmailAsync(request.Email); if (user == null) { return(DataResult <ClaimsPrincipal> .Error(PolishReadableMessage.Auth.WrongLoginOrPassword)); } SignInResult resultPassword = await _signInManager.CheckPasswordSignInAsync(user, request.Password, false); if (resultPassword.Succeeded) { if (user.EmailConfirmed) { user.UtcOffsetInMinutes = request.UtcOffsetInMinutes; _context.Update(user); await _context.SaveChangesAsync(cancellationToken); await _signInManager.SignInAsync(user, request.RememberMe); ClaimsPrincipal claimsPrincipal = await _signInManager.CreateUserPrincipalAsync(user); return(DataResult <ClaimsPrincipal> .Success(claimsPrincipal)); } return(DataResult <ClaimsPrincipal> .Error(PolishReadableMessage.Auth.AccountNotActive)); } return(DataResult <ClaimsPrincipal> .Error(PolishReadableMessage.Auth.WrongLoginOrPassword)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Hours,TeacherId")] Course course) { if (id != course.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(course); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CourseExists(course.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["TeacherId"] = new SelectList(_context.Teachers, "Id", "Id", course.TeacherId); return(View(course)); }
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()); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Lastname")] Teacher teacher) { if (id != teacher.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(teacher); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TeacherExists(teacher.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(teacher)); }
public async Task <DataResult> Handle(Command request, CancellationToken cancellationToken) { Model.Domain.Pass pass = await _context.Passes .Where(x => x.Id == request.Id) .Include(x => x.ParticipantClassTimes) .FirstOrDefaultAsync(cancellationToken); if (pass is null) { return(DataResult.Error(PolishReadableMessage.Pass.NotFound)); } if (pass.Used == 0 && !pass.ParticipantClassTimes.Any()) { _context.Remove(pass); await _context.SaveChangesAsync(cancellationToken); return(DataResult.Success()); } PassAggregate.FromState(pass) .AsRemoved(); _context.Update(pass); await _context.SaveChangesAsync(cancellationToken); return(DataResult.Success()); }
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!"))); }
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()); }
public async Task <DataResult <int> > Handle(Command request, CancellationToken cancellationToken) { ParticipantClassTime participantClassTime = await _context.ParticipantPresences .Where(x => x.ParticipantId == request.ParticipantId && x.ClassTimeId == request.ClassTimeId) .FirstOrDefaultAsync(cancellationToken); if (participantClassTime is null) { return(DataResult <int> .Error(PolishReadableMessage.Presence.ParticipantNotFound)); } participantClassTime.WasPresence = request.IsPresence; _context.Update(participantClassTime); await _context.SaveChangesAsync(cancellationToken); return(DataResult <int> .Success(participantClassTime.Id)); }
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()); }
public async Task <DataResult> Handle(Command request, CancellationToken cancellationToken) { PassAggregate passAggregate = PassAggregate.New(); passAggregate.UpdateByCommand(request); ParticipantGroupClass participantGroupClass = await _context.GroupClassMembers.Where(x => x.Id == request.MemberId) .Include(x => x.Passes) .Include(x => x.User) .Include(x => x.GroupClass) .FirstOrDefaultAsync(cancellationToken); passAggregate.WithParticipant(participantGroupClass.User) .WithPassNumber(participantGroupClass.Passes.Count) .WithStartDate(participantGroupClass.GroupClass.StartClasses); participantGroupClass.Passes.Add(passAggregate.State); _context.Update(participantGroupClass); await _context.Passes.AddAsync(passAggregate.State, cancellationToken); await _context.SaveChangesAsync(cancellationToken); return(DataResult.Success()); }
public async Task <bool> Handle(Command request, CancellationToken cancellationToken) { Room room = await _context.Rooms.Where(x => x.Id == request.Id).FirstOrDefaultAsync(cancellationToken); Room newRoom = new Room().WithName(request.Name); if (newRoom.NormalizeName != room.NormalizeName) { bool isNameExist = await _context.Rooms.AnyAsync(x => x.NormalizeName == newRoom.NormalizeName, cancellationToken); if (isNameExist) { throw new EditRoomException(PolishReadableMessage.Room.NameDuplicate); } room.WithName(newRoom.Name); } room.WithColor(request.Color); _context.Update(room); await _context.SaveChangesAsync(cancellationToken); return(true); }