public ActionResult ChangePassword(ChangePasswordViewModel model) { if (ModelState.IsValid) { var user = Context.Users.Where( u => u.UserId == User.UserId && u.Password == model.OldPassword) .FirstOrDefault(); if (user == null) { ModelState.AddModelError("", "Old Password is not valid"); return View(model); } Context.Entry(user).State = EntityState.Modified; user.Password = model.Password; Context.SaveChanges(); var last = Request.UrlReferrer.ToString(); if (user.Roles.Select(m => m.RoleName).ToArray().Contains("Admin")) { return RedirectToAction("Index", "Admin"); } else { return RedirectToAction("Index", "Books"); } } return View(model); }