Пример #1
0
        public async Task <LectureResponseModel> Map(LectureResponseModel lecture)
        {
            var lectureTheatre = await _lectureTheatreService.GetById(Guid.Parse(lecture.LectureTheatre.Id));

            lecture.LectureTheatre = _mapper.Map <LectureTheatre, LectureTheatreResponseModel>(lectureTheatre);

            return(lecture);
        }
        public async Task <LectureTheatreResponseModel> Handle(GetLectureTheatreByIdQuery request,
                                                               CancellationToken cancellationToken)
        {
            var theatre = await _lectureTheatreService.GetById(request.Id);

            var response = _mapper.Map <LectureTheatreResponseModel>(theatre);

            return(response);
        }
Пример #3
0
        public async Task <bool> ExceedsCapacity(Guid subjectId)
        {
            var subject = await _subjectService.GetById(subjectId);

            var lectureTheatreIds = subject.Lectures
                                    .Select(_ => _.LectureTheatreId);

            var theatres = await _lectureTheatreService.GetById(lectureTheatreIds);

            var minCapacity = theatres
                              .Select(_ => _.Capacity)
                              .Min();

            var studentCount = subject.Students.Count;

            return(studentCount + 1 > minCapacity);
        }
        public async Task <LectureResponseModel> Handle(CreateLectureCommand request, CancellationToken cancellationToken)
        {
            if (!await _subjectService.IsExists(request.Id))
            {
                throw new SubjectIdDoesNotExistsException(request.Id.ToString());
            }

            if (!await _lectureTheatreService.IsExists(request.LectureTheatreId))
            {
                throw new LectureTheatreIdDoesNotExistsException(request.LectureTheatreId.ToString());
            }

            if (!await _lectureTheatreService.IsValidLectureTime(
                    request.LectureTheatreId,
                    request.StartTime,
                    request.EndTime))
            {
                throw new InvalidLectureTimingsException(
                          request.LectureTheatreId.ToString(),
                          request.StartTime, request.EndTime);
            }

            var subject = await _subjectService.GetById(request.Id);

            var lectureTheatreId = await _lectureTheatreService.GetById(request.LectureTheatreId);

            var lecture = subject.AddLecture(
                request.DayOfWeek,
                request.StartTime,
                request.EndTime,
                lectureTheatreId);

            await _subjectService.Save(subject);

            var response = _mapper.Map <LectureResponseModel>(lecture);

            return(await _entityMapperService.Map(response));
        }