public ActionResult Login(LoginModel model, string returnUrl) { if (ModelState.IsValid) { var user = _db.Admins.FirstOrDefault(item => item.Name == model.Name && item.Password == model.Password); if (user != null) { Session["user"] = new MainUser() { Id = user.Id, Name = user.Name, LastName = user.LastName, Category = user.AdminCategoryId }; return RedirectToAction("Index", "Home"); } } return View(model); }
public static void CreateUser(MainUser user) { HttpContext.Current.Session["user"] = user; }