Exemplo n.º 1
0
        public async Task <ApiResponse <UserDto> > GetProfileAsync(Guid userId)
        {
            var userProfile = await _userIdentityRepository.GetProfile(userId);

            if (userProfile == null)
            {
                return(new ApiResponse <UserDto>().SetAsFailureResponse(Errors.User.UserProfileNotFound()));
            }

            else
            {
                var userProfileDto = new UserDto
                {
                    Id          = userProfile.Id,
                    FirstName   = userProfile.FirstName,
                    LastName    = userProfile.LastName,
                    AccountType = userProfile.AccountType,
                    Email       = userProfile.Email,
                    Phone       = userProfile.Phone
                };

                return(new ApiResponse <UserDto>
                {
                    Result = userProfileDto
                });
            }
        }
        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
            });
        }