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 }); }
public async Task <ApiResponse <TutorLearningProfileDto> > GetLearningProfileAsync(Guid tutorId) { if (tutorId == null || tutorId == Guid.Empty) { return(new ApiResponse <TutorLearningProfileDto>() .SetAsFailureResponse(Errors.Lesson.TutorIdForLessonIsEmpty())); } var learningProfile = await _tutorLearningProfileRepository.GetByTutorIdAsync(tutorId); if (learningProfile == null) { return(new ApiResponse <TutorLearningProfileDto>() .SetAsFailureResponse(Errors.Tutor.TutorLearningProfileNotFound())); } else { var tutorProfile = await _identityRepository.GetProfile(tutorId); var tutorLearningProfile = new TutorLearningProfileDto { Id = learningProfile.Id, TutorId = learningProfile.TutorId, FirstName = tutorProfile.FirstName, LastName = tutorProfile.LastName, Mail = tutorProfile.Email, Phone = tutorProfile.Phone, PricePerHour = learningProfile.PricePerHour, LessonTopicCategories = learningProfile.LessonTopicCategories.Select(c => new LessonTopicCategoryDto { Id = c.Id, CategoryName = c.CategoryName }).ToList() }; return(new ApiResponse <TutorLearningProfileDto> { Result = tutorLearningProfile }); } }