コード例 #1
0
        public async Task <IActionResult> Index(IndexViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                await _signInManager.SignOutAsync();

                return(RedirectToAction("Index", "Home", new { area = "" }));
            }

            var email = user.Email;

            if (model.Email != email && model.Email != null)
            {
                var setEmailResult = await _userManager.SetEmailAsync(user, model.Email);

                if (!setEmailResult.Succeeded)
                {
                    throw new ApplicationException($"Unexpected error occurred setting email for user with ID '{user.Id}'.");
                }
            }

            var phoneNumber = user.PhoneNumber;

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

                if (!setPhoneResult.Succeeded)
                {
                    throw new ApplicationException($"Unexpected error occurred setting phone number for user with ID '{user.Id}'.");
                }
            }
            var ouruser = user.Id;
            await _users.SetFirstNameAsync(ouruser, model.FirstName);

            await _users.SetLastNameAsync(ouruser, model.LastName);

            await _users.SetDateOfBirthAsync(ouruser, model.DateOfBirth);

            await _users.SetSkillsAsync(ouruser, model.Skills);

            await _users.SetAddressAsync(ouruser, model.Address);

            StatusMessage = "Your profile has been updated";
            return(RedirectToAction(nameof(Index)));
        }