public async Task <ActionResult> ChangeLastName(String NewLastName, [Bind("NewLastName")] ChangeLastNameModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            AppUser userLoggedIn = await _userManager.FindByNameAsync(User.Identity.Name);

            userLoggedIn.LastName = NewLastName;
            _db.SaveChanges();

            IndexViewModel ivm = new IndexViewModel();

            //populate the view model
            ivm.Email       = userLoggedIn.Email;
            ivm.UserName    = userLoggedIn.UserName;
            ivm.HasPassword = true;
            ivm.UserID      = userLoggedIn.Id;
            ivm.FirstName   = userLoggedIn.FirstName;
            ivm.LastName    = userLoggedIn.LastName;
            ivm.PhoneNumber = userLoggedIn.PhoneNumber;
            ivm.Address     = userLoggedIn.StAddress + " , " + userLoggedIn.City + ", " + userLoggedIn.State + " " + userLoggedIn.ZipCode;


            return(View("Index", ivm));
        }
Beispiel #2
0
        public ActionResult ChangeLastName(ChangeLastNameModel model)
        {
            if (ModelState.IsValid)
            {
                if (User.IsInRole("Klant"))
                {
                    var userId = User.Identity.GetUserId();

                    var CurrentKlant = db.klants.Where(m => m.AspNetUserID == userId).FirstOrDefault();

                    CurrentKlant.achternaam = model.NewLastname;
                }
                else if (User.IsInRole("Medewerker"))
                {
                    var userId = User.Identity.GetUserId();

                    var CurrentMedewerker = db.medewerkers.Where(m => m.AspNetUserID == userId).FirstOrDefault();

                    CurrentMedewerker.achternaam = model.NewLastname;
                }
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }