public HttpResponseMessage Login(string user, string pass) { if (Request.Method == HttpMethod.Options) { return(new HttpResponseMessage(HttpStatusCode.OK)); } WebServiceResult retVal = new WebServiceResult() { Message = "OK", Result = "" }; try { UserBusinessLayer bl = new UserBusinessLayer(); retVal = bl.Login(user, pass); var status = HttpStatusCode.OK; if (retVal.Message != "OK") { status = HttpStatusCode.InternalServerError; } if (retVal.Message != "OK") { return new HttpResponseMessage(status) { Content = new StringContent(JsonConvert.SerializeObject(retVal), Encoding.UTF8, "application/json") } } ; else { return new HttpResponseMessage(status) { Content = new StringContent(JsonConvert.SerializeObject(retVal.Result), Encoding.UTF8, "application/json") } }; } catch (Exception ex) { return(new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent(JsonConvert.SerializeObject(ex), Encoding.UTF8, "application/json") }); } }
public ActionResult Index(users model) { if (ModelState.IsValid) { var userbusinesslayer = new UserBusinessLayer(); var result = userbusinesslayer.Login(model.name, model.password); if (result) { var user = userbusinesslayer.getUserByID(model.name); var userSession = new users(); userSession.id = user.id; userSession.name = user.name; Session.Add(SessionString.USER_SESSION, userSession); return(RedirectToAction("Index", "Project")); } else { ModelState.AddModelError("", "Tên đăng nhập hoặc mật khẩu không chính xác"); } } return(View()); }