Exemplo n.º 1
0
        public async Task <Result> Handle(Query request, CancellationToken cancellationToken)
        {
            var source = _dbContext.Set <ModelTimetable>().Include(x => x.School) as IQueryable <ModelTimetable>;

            ModelTimetable timetable = null;

            if (request.TimetableID.HasValue)
            {
                timetable = await source.SingleOrDefaultAsync(x => x.Id == request.TimetableID.Value);
            }
            else
            {
                timetable = await source
                            .Where(x => x.School.ID == request.SchoolID.Value)
                            .Where(x => x.ValidFrom <= request.ValidOn.Value)
                            .OrderByDescending(x => x.ValidFrom)
                            .FirstOrDefaultAsync();
            }

            if (timetable == null)
            {
                throw new Exceptions.ResourceNotFoundException("Nie znaleziono planu zajęć");
            }

            return(Convert(timetable));
        }
Exemplo n.º 2
0
 private Result Convert(ModelTimetable source)
 {
     return(new Result()
     {
         Timetable = new TimetableConverter().Convert(source)
     });
 }
Exemplo n.º 3
0
 public EngineTimetable Convert(ModelTimetable timetable)
 {
     return(new EngineTimetable(
                timetable.TimeSlots.Select(Convert).ToList(),
                timetable.Lessons.ToDictionary(x => x.Key, x => Convert(timetable.Lessons[x.Key])),
                timetable.ValidFrom,
                timetable.Id,
                timetable.School?.ID
                ));
 }