Beispiel #1
0
        public async Task <IActionResult> UpdateLearningProfile([FromBody] UpdateTutorLearningProfileDto learningProfile)
        {
            var response = await _mediator.Send(new UpdateTutorLearningProfileRequest
            {
                UpdateTutorLearningProfileDto = learningProfile
            });

            if (response.CompletedWithSuccess)
            {
                return(NoContent());
            }

            else
            {
                Log.Error(response.ErrorMessage.Title);
                Log.Error(response.ErrorMessage.Message);

                return(BadRequest(response.ErrorMessage));
            }
        }
        public async Task <ApiResponse> UpdateLearningProfileAsync(Guid tutorId, UpdateTutorLearningProfileDto tutorLearningProfileToUpdate)
        {
            if (tutorId == null || tutorId == Guid.Empty)
            {
                return(new ApiResponse().SetAsFailureResponse(Errors.Lesson.TutorIdForLessonIsEmpty()));
            }

            var tutorLearningProfile = await _tutorLearningProfileRepository.GetByTutorIdAsync(tutorId);

            if (tutorLearningProfile == null)
            {
                return(new ApiResponse().SetAsFailureResponse(Errors.Tutor.TutorLearningProfileNotFound()));
            }

            else if (tutorLearningProfile.TutorId != tutorId)
            {
                return(new ApiResponse().SetAsFailureResponse(Errors.Tutor.TutorLearningProfileNotFound()));
            }

            else
            {
                tutorLearningProfile.PricePerHour = tutorLearningProfileToUpdate.PricePerHour;
                if (tutorLearningProfileToUpdate.LessonTopicCategories == null)
                {
                    return(new ApiResponse().SetAsFailureResponse(Errors.Tutor.TutorLearningProfileLessonCategoryNotFound()));
                }
                tutorLearningProfile.LessonTopicCategories = tutorLearningProfileToUpdate.LessonTopicCategories
                                                             .Select(c => new LessonTopicCategory
                {
                    Id           = c.Id,
                    CategoryName = c.CategoryName
                }).ToList();


                await _tutorLearningProfileRepository.UpdateAsync(tutorLearningProfile);

                return(new ApiResponse());
            }
        }