public async Task <IOutput> Handle(EditGroupInput request, CancellationToken cancellationToken) { var item = await _context.Groups.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken : cancellationToken); item.Name = request.Name; await _context.SaveChangesAsync(cancellationToken); return(ObjectOutput.CreateWithId(request.Id)); }
public async Task <IOutput> Handle(CreateTeacherInput request, CancellationToken cancellationToken) { var teacher = new Entities.Teacher { Name = request.Name }; _context.Teachers.Add(teacher); await _context.SaveChangesAsync(cancellationToken); return(ObjectOutput.CreateWithId(teacher.Id)); }
public async Task <IOutput> Handle(CreateSubjectInput request, CancellationToken cancellationToken) { var subject = new Entities.Subject { Name = request.Name, TeacherId = request.TeacherId }; _context.Subjects.Add(subject); await _context.SaveChangesAsync(cancellationToken); return(ObjectOutput.CreateWithId(subject.Id)); }
public async Task <IOutput> Handle(UpdateSubjectInput request, CancellationToken cancellationToken) { var subject = await _context.Subjects.FirstOrDefaultAsync(x => x.Id == request.SubjectId, cancellationToken); if (subject is null) { return(ObjectOutput.CreateWithId(1)); } subject.Name = request.Name; subject.TeacherId = request.TeacherId; await _context.SaveChangesAsync(cancellationToken); return(ObjectOutput.CreateWithId(subject.Id)); }
public async Task <IOutput> Handle(CreateGroupInput request, CancellationToken cancellationToken) { using var unit = _unitOfWork.CreateUnitOfWork(); var exist = await _context.Groups.AnyAsync(x => x.Name == request.Name, cancellationToken); if (exist) { return(Failure("Такая группа уже существует")); } var group = new Entities.Group(request.Name); _context.Groups.Add(group); await _context.SaveChangesAsync(cancellationToken); await unit.Apply(); return(ObjectOutput.CreateWithId(group.Id)); }
public async Task <IOutput> Handle(CreateScheduleInput request, CancellationToken cancellationToken) { var group = await _context.Groups .Include(x => x.GroupSubjects) .FirstOrDefaultAsync(x => x.Id == request.GroupId, cancellationToken); if (group is null) { return(Failure("Группа не найдена")); } var subject = await _context.Subjects .FirstOrDefaultAsync(x => x.Id == request.SubjectId, cancellationToken); if (subject is null) { return(Failure("Предмет не найден")); } var groupSubject = new GroupSubject { DurationInMinutes = request.DurationInMinutes, StartDate = request.StartDate, Group = group, GroupId = group.Id, Subject = subject, SubjectId = subject.Id, ManualCreated = true, }; _context.GroupSubjects.Add(groupSubject); await _context.SaveChangesAsync(cancellationToken); return(ObjectOutput.CreateWithId(groupSubject.Id)); }