public UserSession CustomerLogin(CustomerLoginModels model) { try { using (var cxt = new CMS_Context()) { var data = cxt.CMS_Customers.Where(x => (x.Email == model.UserName || x.Phone == model.UserName) && (x.Password == model.Password || x.Password2 == model.Password) && x.IsActive && x.Status != (int)Commons.CustomerStatus.Watting) .Select(x => new UserSession { Email = x.Email, UserName = x.LastName, UserFullName = x.FirstName + " " + x.LastName, Phone = x.Phone, TotalCredits = x.TotalCredit, UserId = x.Id, IsAuthenticated = true }).FirstOrDefault(); return(data); } } catch (Exception ex) { NSLog.Logger.Error("CustomerLogin", ex); } return(null); }
public ActionResult Index(CustomerLoginModels model) { try { if (!ModelState.IsValid) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return(View(model)); } model.Password = CommonHelper.Encrypt(model.Password); var data = fac.CustomerLogin(model); if (data == null) { ModelState.AddModelError("UserName", "Your username or password not correct"); return(View(model)); } Session["UserC"] = data; } catch (Exception ex) { } return(RedirectToAction("Index", "Home")); }