コード例 #1
0
        public async Task<ActionResult> ManageProfile()
        {
            var userId = User.Identity.GetUserId();
            var um = UserManager.FindById(userId);

            var model = new ManageProfileViewModel
            {
                Email = await UserManager.GetEmailAsync(userId),
                UserName = User.Identity.GetUserName(),
                FirstName = um.FirstName,
                LastName = um.LastName,
                Birthday = um.Birthday,
                City = um.City,
                State = um.State,
                Private = um.IsPrivate,
                AllowEmails = um.AllowsEmails
            };
            return View(model);
        }
コード例 #2
0
        public async Task<ActionResult> ManageProfile(ManageProfileViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = UserManager.FindById(User.Identity.GetUserId());
                user.FirstName = model.FirstName;
                user.LastName = model.LastName;
                user.Birthday = model.Birthday;
                user.City = model.City;
                user.State = model.State;
                user.IsPrivate = model.Private;
                user.AllowsEmails = model.AllowEmails;
                user.UserName = model.UserName;
                user.Email = model.Email;

                var result = await UserManager.UpdateAsync(user);
                if (result.Succeeded)
                    return RedirectToAction("Index", "Manage");
                AddErrors(result);
            }
            return View(model);
        }