//
        // GET: /Manage/Index
        public async Task <ActionResult> Index(ManageMessageId?message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
                : message == ManageMessageId.Error ? "An error has occurred."
                : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
                : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                : "";

            var Db = new KennelsContext();

            var userId = User.Identity.GetUserId();
            var user   = Db.Users.SingleOrDefault(u => u.Id == userId);

            var model = new EditUserViewModel
            {
                Address     = user.Address,
                County      = user.County,
                Fname       = user.Fname,
                Lname       = user.Lname,
                PhoneNumber = user.PhoneNumber
            };

            return(View(model));
        }
        //Get: /Manage/Edit
        public ActionResult Edit()
        {
            var Db     = new KennelsContext();
            var userId = User.Identity.GetUserId();
            var user   = Db.Users.SingleOrDefault(u => u.Id == userId);
            //gets the model of the current user and displays for editing
            var model = new EditUserViewModel(user);

            return(View(model));
        }
        public async Task <ActionResult> Edit(EditUserViewModel model)
        {
            if (ModelState.IsValid)
            {
                var Db     = new KennelsContext();
                var userId = User.Identity.GetUserId();
                var user   = Db.Users.SingleOrDefault(u => u.Id == userId);
                //Updates the data changed by the user.
                user.Fname       = model.Fname;
                user.Lname       = model.Lname;
                user.Address     = model.Address;
                user.County      = model.County;
                user.PhoneNumber = model.PhoneNumber;

                Db.Entry(user).State = EntityState.Modified;
                await Db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            // Redisplays form if some input not valid.
            return(View(model));
        }
Пример #4
0
 public KennelsController()
 {
     db      = new KennelsContext();
     manager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db));
 }