public ActionResult Login()
 {
     var viewModel = new LoginViewModel();
     if (Request.UrlReferrer != null)
         viewModel.RedirectUrl = Request.UrlReferrer.ToString();
     return View(viewModel);
 }
 public ActionResult Login(LoginViewModel viewModel)
 {
     var user = _db.Users.SingleOrDefault(x => x.Username == viewModel.Username);
     if (user == null || user.Password != viewModel.Password)
     {
         ModelState.AddModelError("credentials", "Invalid username or password.");
         return View();
     }
     FormsAuthentication.SetAuthCookie(user.Id.ToString(), true);
     if (viewModel.RedirectUrl != null)
         return Redirect(viewModel.RedirectUrl);
     else
         return RedirectToAction("Index", "Home");
 }