public async Task <ApiResponse <IReadOnlyList <LessonDto> > > GetPlannedLessons(Guid tutorId)
        {
            if (tutorId == null || tutorId == Guid.Empty)
            {
                return(new ApiResponse <IReadOnlyList <LessonDto> >()
                       .SetAsFailureResponse(Errors.Lesson.TutorIdForLessonIsEmpty()));
            }

            else
            {
                var plannedLessons = await _lessonRepository.GetPlannedForTutor(tutorId);

                if (plannedLessons == null)
                {
                    return(new ApiResponse <IReadOnlyList <LessonDto> >()
                           .SetAsFailureResponse(Errors.Lesson.NoActiveLessonForTutor()));
                }

                else
                {
                    var plannedLessonsDtos = plannedLessons.Select(lesson => new LessonDto
                    {
                        Id = lesson.Id,
                        AcceptedByTutor    = lesson.AcceptedByTutor,
                        CanceledByTutor    = lesson.CanceledByTutor,
                        CancelledByStudent = lesson.CancelledByStudent,
                        Length             = lesson.Length,
                        Location           = lesson.Location,
                        StudentId          = lesson.StudentId,
                        Term          = lesson.Term,
                        TopicCategory = new LessonTopicCategoryDto
                        {
                            Id           = lesson.TopicCategory.Id,
                            CategoryName = lesson.TopicCategory.CategoryName
                        },
                        TutorId = lesson.TutorId
                    }).ToList();

                    return(new ApiResponse <IReadOnlyList <LessonDto> >
                    {
                        Result = plannedLessonsDtos
                    });
                }
            }
        }
        public async Task <ApiResponse <LessonDto> > OrderLessonAsync(Guid studentId, OrderLessonDto lesson)
        {
            if (studentId == null || studentId == Guid.Empty)
            {
                return(new ApiResponse <LessonDto>()
                       .SetAsFailureResponse(Errors.Lesson.StudentIdForLessonIsEmpty()));
            }

            var tutorPlannedLessons = await _lessonRepository.GetPlannedForTutor(lesson.TutorId);

            foreach (var tutorPlannedLesson in tutorPlannedLessons)
            {
                if (tutorPlannedLesson.Term != lesson.Term)
                {
                    double timeDifferenceBetweenLessons = tutorPlannedLesson.Term.Subtract(lesson.Term).TotalMinutes;
                    if (timeDifferenceBetweenLessons < 30)
                    {
                        return(new ApiResponse <LessonDto>()
                               .SetAsFailureResponse(Errors.Lesson.TooShortTimePeriodBetweenLessons()));
                    }
                }

                else
                {
                    return(new ApiResponse <LessonDto>()
                           .SetAsFailureResponse(Errors.Lesson.TutorAlreadyBookedForLessonProposedTime()));
                }
            }

            var newLesson = new Lesson
            {
                Length        = lesson.Length,
                Location      = lesson.Location,
                Term          = lesson.Term,
                TopicCategory = new LessonTopicCategory
                {
                    Id           = lesson.TopicCategory.Id,
                    CategoryName = lesson.TopicCategory.CategoryName
                },
                TutorId = lesson.TutorId
            };

            var orderedLesson = await _lessonRepository.AddAsync(newLesson);

            var orderedLessonDto = new LessonDto
            {
                Id = orderedLesson.Id,
                AcceptedByTutor    = orderedLesson.AcceptedByTutor,
                CanceledByTutor    = orderedLesson.CanceledByTutor,
                CancelledByStudent = orderedLesson.CancelledByStudent,
                Length             = orderedLesson.Length,
                Location           = orderedLesson.Location,
                StudentId          = orderedLesson.StudentId,
                Term          = orderedLesson.Term,
                TopicCategory = new LessonTopicCategoryDto
                {
                    Id           = orderedLesson.TopicCategory.Id,
                    CategoryName = orderedLesson.TopicCategory.CategoryName
                },
                TutorId = orderedLesson.TutorId
            };

            return(new ApiResponse <LessonDto>
            {
                Result = orderedLessonDto
            });
        }