Esempio n. 1
0
        public async Task <IActionResult> OnPostAsync()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."));
            }

            if (!ModelState.IsValid)
            {
                await LoadAsync(user);

                return(Page());
            }

            var phoneNumber = await _userManager.GetPhoneNumberAsync(user);

            if (Input.PhoneNumber != phoneNumber)
            {
                var setPhoneResult = await _userManager.SetPhoneNumberAsync(user, Input.PhoneNumber);

                if (!setPhoneResult.Succeeded)
                {
                    var userId = await _userManager.GetUserIdAsync(user);

                    throw new InvalidOperationException($"Unexpected error occurred setting phone number for user with ID '{userId}'.");
                }
            }
            string currentUserId = await _userManager.GetUserIdAsync(user);

            // TODO Find a better way to implement this.
            if (user.ModelInformation == null)
            {
                await _modelService.InsertModelInformation(currentUserId);
            }

            if (Input.FirstName != user.FirstName)
            {
                await _modelService.ChangeUserFirstName(user, Input.FirstName);
            }

            if (Input.LastName != user.LastName)
            {
                await _modelService.ChangeUserLastName(user, Input.LastName);
            }

            var modelInformation = await _modelService.GetModelById <ChangeUserInformationInputModel>(currentUserId);

            if (Input.Age != user.ModelInformation.Age)
            {
                await _modelService.ChangeUserAge(user, Input.Age);
            }

            if (Input.Gender != user.ModelInformation.Gender)
            {
                await _modelService.ChangeUserGender(user, Input.Gender);
            }

            if (Input.Ethnicity != user.ModelInformation.Ethnicity)
            {
                await _modelService.ChangeUserEthnicity(user, Input.Ethnicity);
            }

            if (Input.Height != user.ModelInformation.Height)
            {
                await _modelService.ChangeUserValues(user, Input.Height, "height");
            }

            if (Input.Height != user.ModelInformation.Waist)
            {
                await _modelService.ChangeUserValues(user, Input.Waist, "waist");
            }

            if (Input.Height != user.ModelInformation.Bust)
            {
                await _modelService.ChangeUserValues(user, Input.Bust, "bust");
            }

            if (Input.Height != user.ModelInformation.Hips)
            {
                await _modelService.ChangeUserValues(user, Input.Hips, "hips");
            }

            if (Input.ModelType != user.ModelInformation.ModelType)
            {
                await _modelService.ChangeUserStringValues(user, Input.ModelType, "modelType");
            }

            //int val = int.TryParse(Input.Country, out var tempVal) ? tempVal : (int) 0;

            //var countryToString = ((Country)tempVal).ToString();
            if (Input.Country != user.ModelInformation.Country)
            {
                await _modelService.ChangeUserStringValues(user, Input.Country, "country");
            }

            if (Input.City != user.ModelInformation.City)
            {
                await _modelService.ChangeUserStringValues(user, Input.City, "city");
            }

            if (Input.Nationality != user.ModelInformation.Nationality)
            {
                await _modelService.ChangeUserStringValues(user, Input.Nationality, "nationality");
            }

            if (Input.InstagramUrl != user.ModelInformation.InstagramUrl)
            {
                await _modelService.ChangeUserStringValues(user, Input.InstagramUrl, "instagramUrl");
            }

            if (Input.FacebookUrl != user.ModelInformation.FacebookUrl)
            {
                await _modelService.ChangeUserStringValues(user, Input.FacebookUrl, "facebookUrl");
            }

            await _signInManager.RefreshSignInAsync(user);

            this.StatusMessage = "Your profile has been updated";
            return(RedirectToPage());
        }