public void LoginUser(LoginStudentBm bind, string sessionId) { if (!this.Context.Logins.Any(login => login.SessionId == sessionId)) { this.Context.Logins.Add(new Login() { SessionId = sessionId }); this.Context.SaveChanges(); } Login mylogin = this.Context.Logins.FirstOrDefault(login => login.SessionId == sessionId); mylogin.IsActive = true; Student model = this.Context.Students.FirstOrDefault( user => user.Username == bind.Username && user.Password == bind.Password); mylogin.Student = model; this.Context.SaveChanges(); }
public ActionResult Login(LoginStudentBm bind, string returnUrl) { //var httpCookie = this.Request.Cookies.Get("sessionId"); //if (httpCookie != null && AuthenticationManager.IsAuthenticated(httpCookie.Value)) //{ // return this.RedirectToAction("All", "Course"); //} if (ModelState.IsValid) { if (authProvider.Authenticate(bind.Username, bind.Password)) { return(Redirect(returnUrl ?? Url.Action("All", "Admin"))); } else { this.repository.LoginUser(bind, this.Session.SessionID); this.Response.SetCookie(new HttpCookie("sessionId", Session.SessionID)); return(this.RedirectToAction("All", "Course")); } } return(this.View(new LoginViewModel())); }