Esempio n. 1
0
        public async Task <IActionResult> CreateLearningProfile([FromBody] AddTutorLearningProfileDto tutorlearningProfile)
        {
            var response = await _mediator.Send(new CreateTutorLearningProfileRequest
            {
                CreateTutorLearningProfileDto = tutorlearningProfile
            });

            if (response.CompletedWithSuccess)
            {
                return(CreatedAtAction(nameof(GetLearningProfile), response.Result));
            }

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

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

            var existingProfile = await _tutorLearningProfileRepository.GetByTutorIdAsync(tutorId);

            if (existingProfile != null)
            {
                return(new ApiResponse <TutorLearningProfileDto>()
                       .SetAsFailureResponse(Errors.Tutor.TutorLearningProfileAlreadyExists()));
            }

            if (tutorLearningProfile.LessonTopicCategories == null)
            {
                return(new ApiResponse <TutorLearningProfileDto>()
                       .SetAsFailureResponse(Errors.Tutor.TutorLearningProfileLessonCategoryNotFound()));
            }


            var learningProfile = new TutorLearningProfile
            {
                Id = Guid.NewGuid(),
                LessonTopicCategories = tutorLearningProfile.LessonTopicCategories.Select(c => new LessonTopicCategory
                {
                    Id           = c.Id,
                    CategoryName = c.CategoryName
                }).ToList(),
                PricePerHour = tutorLearningProfile.PricePerHour,
                TutorId      = tutorId
            };

            var addedLearningProfile = await _tutorLearningProfileRepository.AddAsync(learningProfile);

            var tutorProfile = await _identityRepository.GetProfile(tutorId);

            var addedTutorLearninfProfileDto = new TutorLearningProfileDto
            {
                Id                    = addedLearningProfile.Id,
                FirstName             = tutorProfile.FirstName,
                LastName              = tutorProfile.LastName,
                Mail                  = tutorProfile.Email,
                Phone                 = tutorProfile.Phone,
                LessonTopicCategories = addedLearningProfile.LessonTopicCategories.Select(c => new LessonTopicCategoryDto
                {
                    Id           = c.Id,
                    CategoryName = c.CategoryName
                }).ToList(),
                PricePerHour = tutorLearningProfile.PricePerHour,
                TutorId      = tutorId
            };

            return(new ApiResponse <TutorLearningProfileDto>
            {
                Result = addedTutorLearninfProfileDto
            });
        }