public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
        {
            var school = await _dbContext.Set <School>()
                         .SingleOrDefaultAsync(x => x.ID == request.SchoolID);

            var timetable = new TimetableConverter().Convert(request.Timetable);

            timetable.School = school ?? throw new Domain.Exceptions.ValidationException(nameof(request.SchoolID), "Szkoła o podanym ID nie istnieje");

            _dbContext.Add(timetable);

            return(Unit.Value);
        }
Beispiel #2
0
        public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
        {
            var oldTimetable = await _dbContext.Set <Szlem.Models.Schools.Timetable>()
                               .Include(x => x.School)
                               .SingleOrDefaultAsync(x => x.Id == request.Timetable.ID);

            if (oldTimetable == null)
            {
                throw new Exceptions.InvalidRequestException("Nie znaleziono planu zajęć o podanym ID");
            }

            var newTimetable = new TimetableConverter().Convert(request.Timetable);

            newTimetable.School = oldTimetable.School;

            _dbContext.Remove(oldTimetable);
            _dbContext.Add(newTimetable);

            return(Unit.Value);
        }