Exemplo n.º 1
0
        public ActionResult ChangeUserData()
        {
            var dbModel = AspUserManager.FindById(User.Identity.GetUserId());

            UserDataViewModel viewModel = new UserDataViewModel
            {
                Name = dbModel.FirstName,
                Surname = dbModel.LastName,
                UserCity = dbModel.City,
                UserHouseNumber = dbModel.HouseNumber,
                UserPhone = dbModel.PhoneNumber,
                UserPostalCode = dbModel.PostalCode,
                UserStreet = dbModel.Street
            };

            return View(viewModel);
        }
Exemplo n.º 2
0
        public async Task<ActionResult> ChangeUserData(UserDataViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = AspUserManager.FindById(User.Identity.GetUserId());

                user.City = model.UserCity;
                user.HouseNumber = model.UserHouseNumber;
                user.PostalCode = model.UserPostalCode;
                user.PhoneNumber = model.UserPhone;
                user.Street = model.UserStreet;
                user.FirstName = model.Name;
                user.LastName = model.Surname;

                var result = await AspUserManager.UpdateAsync(user);

                if (result.Succeeded)
                    return RedirectToAction("Index", new { Message = ManageMessageId.ChangeUserDataSuccess });
                else
                    return RedirectToAction("Index", new { Message = ManageMessageId.Error });
            }
            else
                return View(model);
        }