public static LoginModel Login(LoginModel loginMdl, HttpContext context) { loginMdl = MollShopContext.UserLogin(loginMdl); int result = loginMdl.UserId; if (result <= 0) { //Authentication unsuccessful switch (result) { case 0: loginMdl.Message = "Wrong password!"; break; case -1: loginMdl.Message = "Account has not been found!"; break; case -2: loginMdl.Message = "Something went wrong on our end. Please contact support."; break; case -3: loginMdl.Message = "Hello, " + loginMdl.UserName + ". It seems you have not yet activated your account. Please check your mail!"; break; default: break; } } else { //Authentication was successful context.Session.SetInt32("UserId", loginMdl.UserId); context.Session.SetString("User", loginMdl.EmailAddress); context.Session.SetString("UserName", loginMdl.UserName); context.Session.SetString("LoggedIn", "true"); context.Session.SetString("Admin", loginMdl.Admin.ToString()); //If the user has logged in, we need to check if they have any items added to their Shopping cart cookies, and add it to the database List <string> items = context.Request.Cookies.Keys.Where(s => s.StartsWith("SC")).ToList(); foreach (string item in items) { int fld_offeredserviceid = Convert.ToInt32(item.Substring(2)); AddtoShoppingCart(fld_offeredserviceid, loginMdl.UserId); } } return(loginMdl); }
public IActionResult Login(string Password, string EmailAddress) { LoginModel loginMdl = new LoginModel(EmailAddress, Password); MollShopContext context = HttpContext.RequestServices.GetService(typeof(TestWebApp.Models.MollShopContext)) as MollShopContext; int result = context.UserLogin(loginMdl); if (result == 1) { return(RedirectToAction("LI_index", "Page")); } else { return(View()); } }