public async Task <IActionResult> Post([FromBody] Subject subject) { _dbcontext.Subjects.Add(subject); await _dbcontext.SaveChangesAsync(); return(Ok()); }
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 <IActionResult> Create([Bind("Id,Name,Lastname")] Teacher teacher) { if (ModelState.IsValid) { _context.Add(teacher); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(teacher)); }
public async Task <IActionResult> Create([Bind("Id,Name,Hours,TeacherId")] Course course) { if (ModelState.IsValid) { _context.Add(course); await _context.SaveChangesAsync(); 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 <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()); }
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()); }
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 <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()); }
public async Task <DataResult> Handle(Command request, CancellationToken cancellationToken) { User user = await _context.Users.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken); _context.Remove(user); await _context.SaveChangesAsync(cancellationToken); return(DataResult.Success()); }
public async Task <bool> Handle(Command request, CancellationToken cancellationToken) { Room room = await _context.Rooms.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken); if (room is null) { throw new RemoveRoomException(PolishReadableMessage.Room.RoomNotExist); } _context.Remove(room); await _context.SaveChangesAsync(cancellationToken); return(true); }
public async Task <DataResult> Handle(Command request, CancellationToken cancellationToken) { Model.Domain.GroupClass groupClass = await _context.GroupClass.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken); if (groupClass is null) { return(DataResult.Error(PolishReadableMessage.GroupClass.NotFound)); } _context.Remove(groupClass); 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) { Model.Domain.Pass pass = await _context.Passes.Where(x => x.Id == request.Id).FirstOrDefaultAsync(cancellationToken); if (pass is null) { return(DataResult.Error(PolishReadableMessage.Pass.NotFound)); } PassAggregate.FromState(pass).UpdateByCommand(request); _context.Passes.Update(pass); 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 <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); }
public async Task <DataResult> Handle(Command request, CancellationToken cancellationToken) { GroupClassAggregate groupClassAggregate = GroupClassAggregate.New(); groupClassAggregate.UpdateAll(request); await AddAnchors(request, groupClassAggregate, cancellationToken); await AddRoom(request, groupClassAggregate, cancellationToken); await AddGroupLevel(request, groupClassAggregate, cancellationToken); await AddParticipants(request, groupClassAggregate, cancellationToken); groupClassAggregate.UpdateDaysOfWeek(request, _context).CreateSchedule(request); await _context.GroupClass.AddAsync(groupClassAggregate.State, cancellationToken); await _context.SaveChangesAsync(cancellationToken); return(DataResult.Success()); }
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> 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); }
public async Task Put(int id, [FromBody] Staff staff) { _dbcontext.Entry(_dbcontext.Staffs.Where(X => X.Mobile == id).FirstOrDefault()).CurrentValues.SetValues(staff); await _dbcontext.SaveChangesAsync(); }