Example #1
0
        public async Task <IActionResult> UpdateProfileData()
        {
            var user = await userManager.GetUserAsync(User);

            EditAccountSettingsViewModel model = new EditAccountSettingsViewModel
            {
                Email       = user.Email,
                PhoneNumber = user.PhoneNumber,
                City        = user.City,
                FirstName   = user.FirstName,
                LastName    = user.LastName
            };

            return(View(model));
        }
Example #2
0
        public async Task <IActionResult> UpdateProfileData(EditAccountSettingsViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await userManager.GetUserAsync(User);

                if (user == null)
                {
                    ViewBag.ErrorMessage = $"User with Id = {user.Id} cannot be found";
                    return(View("NotFound"));
                }
                else
                {
                    user.Email       = model.Email;
                    user.City        = model.City;
                    user.FirstName   = model.FirstName;
                    user.LastName    = model.LastName;
                    user.PhoneNumber = model.PhoneNumber;
                }

                var result = await userManager.UpdateAsync(user);

                if (result.Succeeded)
                {
                    ViewBag.Title           = "Success";
                    ViewBag.OperationResult = "Success";
                    ViewBag.Message         = "Account data successfully updated";
                    ViewBag.Action          = "Index";
                    ViewBag.NextAction      = "Home Page";
                    ViewBag.Controller      = "Home";

                    return(View("ResultView"));
                }

                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError("", error.Description);
                }
            }
            return(View(model));
        }