public IActionResult AfterLogin([FromServices] LoginService ls, string username, string password, [FromServices] BrowseService bs, [FromServices] CartService cs, string query1 = "") { int val = ls.Login(username, password, HttpContext.Session); if (val == 1) { TempData["err"] = "Username does not exist"; return(RedirectToAction("Login", "Home")); } else if (val == 2) { TempData["err"] = "Incorrect password"; return(RedirectToAction("Login", "Home")); } else if (val == 3) { ViewData["username"] = username; HttpContext.Session.SetString("username", username); ViewData["username"] = HttpContext.Session.GetString("username"); } if (ViewData["username"] != null) { List <Product> products = bs.GetProducts(query1); ViewData["products"] = products; var customerId = HttpContext.Session.GetInt32("customerId") ?? 0; var sessionCart = HttpContext.Session.GetString("Cart"); if (sessionCart != null) { var cart = JsonConvert.DeserializeObject <Cart>(sessionCart); cs.AddCartWithCustomer(customerId, cart); ViewData["ItemCount"] = cart.Quantity; } else { ViewData["ItemCount"] = cs.GetNumberOfCartItem(customerId); } } return(View()); }