public ActionResult Register(RegisterViewModel model) { if (ModelState.IsValid) { using (TheFoodyContext db = new TheFoodyContext()) { User usr = new User(); usr.email = model.Email; usr.fname = model.FirstName; usr.lname = model.LastName; usr.password = model.Password; usr.status = "Active"; usr.user_type = "Admin"; usr.created_date = DateTime.Now; db.Users.Add(usr); db.SaveChanges(); } Session["UserEmail"] = model.Email; return(RedirectToAction("Index", "Home")); } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return(View(model)); } using (TheFoodyContext db = new TheFoodyContext()) { //var usr = db.Users.Single(u => u.email == model.Email && u.password == model.Password); var usr = db.Users.Where(u => u.email == model.Email && u.password == model.Password).FirstOrDefault(); if (usr == null) { ModelState.AddModelError("", "Invalid Email or password"); } else { Session["UserEmail"] = usr.email.ToString(); return(RedirectToAction(returnUrl)); } } return(View(model)); }