public ActionResult Login(LoginModel model) { if (ModelState.IsValid) { // поиск пользователя в бд User user = null; using (HostelContext db = new HostelContext()) { user = db.Users.FirstOrDefault(u => u.Login == model.Name && u.Password == model.Password); } if (user != null) { FormsAuthentication.SetAuthCookie(model.Name, true); //return RedirectToAction("Index", "Home"); if (user.RoleId == 1) { return(RedirectToAction("Index", "Admin")); } else if (user.RoleId == 2) { return(RedirectToAction("Index", "Home")); } } else { ModelState.AddModelError("", "Пользователя с таким логином и паролем нет"); } } return(View(model)); }
public BaseApiController() { hostelContext = new HostelContext(); }
public ContextService(DbSet <T> dbset, HostelContext hostelContext) { this.hostelContext = hostelContext; this.hostelContext.Database.EnsureCreated(); this.dbset = dbset; }