Example #1
0
        public async Task <DataContracts.ViewModels.User.UserProfileModel> GetUserData(Guid userId)
        {
            var data = await _userRepository.GetUserById(userId);

            var categoryData = await _categoryRepository.GetAllAsync();

            var professionalFormData = await _userRepository.GetProfessionalFormById(userId);

            //#region Steps Completed


            ////Logic to set steps complete
            //var stepsCompleted = 5;

            //if (data.Role.Name == RoleType.Professional.ToString())
            //{
            //    ProfessionalProfile professional = new ProfessionalProfile
            //    {
            //        WorkExperience = data.WorkExperience,
            //        Documents = new DataContracts.ViewModels.User.Documents
            //        {
            //            ProofOfAddress = professionalFormData.ProofOfAddress,
            //            BusinessInsurrance = professionalFormData.BusinessInsurrance,
            //            CarInsurance = professionalFormData.CarInsurance,
            //            DrivingLicence = professionalFormData.DrivingLicence,
            //            MOTCert = professionalFormData.MOTCert,
            //            QualificationDocument = professionalFormData.QualificationDocument
            //        },
            //        Activation = new Activation
            //        {
            //            Tools = professionalFormData.Tools,
            //            AreasAroundPostcode = professionalFormData.AreasAroundPostcode,
            //            OwnMaterialTools = professionalFormData.OwnMaterialTools
            //        }
            //    };
            //    //if any work experience not submitted yet
            //    if (professional.WorkExperience.GetType().GetProperties()
            //                                .Where(pi => pi.PropertyType == typeof(string))
            //                                .Select(pi => (string)pi.GetValue(professional.WorkExperience))
            //                                .Any(value => !string.IsNullOrEmpty(value)))
            //        stepsCompleted -= 1; //decrease steps completed
            //    else if (professional.Documents.GetType().GetProperties()
            //                                .Where(pi => pi.PropertyType == typeof(string))
            //                                .Select(pi => (string)pi.GetValue(professional.Documents))
            //                                .Any(value => !string.IsNullOrEmpty(value)))
            //        stepsCompleted -= 1; //If any documents not submitted yet.
            //    else if (professional.Activation.OwnMaterialTools == null)
            //        stepsCompleted -= 1;
            //}

            //if (string.IsNullOrEmpty(data.Firstname) && string.IsNullOrEmpty(data.Firstname))
            //    stepsCompleted -= -1;
            //else if (data.Address.GetType().GetProperties()
            //                            .Where(pi => pi.PropertyType == typeof(string))
            //                            .Select(pi => (string)pi.GetValue(data.Address))
            //                            .Any(value => !string.IsNullOrEmpty(value)))
            //    stepsCompleted -= -1;

            //#endregion

            #region Stripe check

            if (data.Role.Name == RoleType.Professional.ToString())
            {
                if (string.IsNullOrEmpty(professionalFormData.StripeAccountId))
                {
                    StripeService stripeService = new StripeService(_userRepository, Configuration);
                    await stripeService.AddStripeCustomer(data.Email);
                }
            }


            #endregion

            UserProfileModel model = new UserProfileModel
            {
                Firstname      = data.Firstname,
                Lastname       = data.Lastname,
                Email          = data.Email,
                PhoneNumber    = data.PhoneNumber,
                ProfileImage   = data.ProfileImage,
                UserId         = data.Id,
                UserProfile    = data.UserProfile,
                Address        = data.Address,
                WorkExperience = new WorkExperience
                {
                    WorkExperienceId    = data.WorkExperience.WorkExperienceId,
                    Category            = data.WorkExperience.Category,
                    CategoryName        = categoryData.Where(c => c.Id == data.WorkExperience.Category).Select(c => c.Name).FirstOrDefault(),
                    SubCategory         = data.WorkExperience.SubCategory,
                    SubCategoryName     = categoryData.Where(c => c.Id == data.WorkExperience.SubCategory).Select(c => c.Name).FirstOrDefault(),
                    YearsOfExperience   = data.WorkExperience.YearsOfExperience,
                    WorkEligibilityInUk = data.WorkExperience.WorkEligibilityInUk
                }
            };
            if (data.Role.Name == RoleType.Professional.ToString())
            {
                model.StripeAccountId   = data.Role.Name == RoleType.Professional.ToString() ? professionalFormData.StripeAccountId : string.Empty;
                model.StripeOnBoarded   = data.Role.Name == RoleType.Professional.ToString() ? professionalFormData.StripeOnBoarded : false;
                model.StripeConnectLink = data.Role.Name == RoleType.Professional.ToString() || !model.StripeOnBoarded ? GenerateStripeLink(professionalFormData.StripeAccountId) : string.Empty;
            }

            return(model);
        }