public IActionResult Logout() { _logger.WriteLog($"User :{_read.ReadCookie("user")} ", Catgory.User); _write.DeleteCookies("User"); _write.DeleteSession("User"); _emptyCart.EmptyCart(_read.ReadCookie("Cart")); _write.DeleteCookies("Cart"); return(RedirectToAction("Index", "Home")); }
public IActionResult Index() { List <Product> products = new List <Product>(); string cart = _read.ReadCookie("Cart"); if (cart == null) { return(View(products)); } ShoppingCart shoppingCart = JsonConvert.DeserializeObject <ShoppingCart>(cart); var productListIDs = _cartManager.GetCartProducts(shoppingCart); var productList = _repositoryProducts.GetCartProducts(productListIDs); return(View(productList)); }
public bool CheckUserLogin() { if (_read.ReadCookie("User") != null) { return(true); } return(false); }
public IActionResult MyProducts() { if (_check.CheckUserLogin() == false) { return(RedirectToAction("Index", "Login")); } User user = JsonConvert.DeserializeObject <User>(_read.ReadCookie("User")); return(View(_repositoryProducts.GetProductsOfUser(user.UserId))); }
public User GetUserFromCookie() { string user = _read.ReadCookie("User"); if (user != null) { User newUser = JsonConvert.DeserializeObject <User>(user); return(newUser); } return(null); }
public int GetNumOfProduct() { string jsonCart = _read.ReadCookie("Cart"); if (jsonCart == null) { return(0); } ShoppingCart cart = JsonConvert.DeserializeObject <ShoppingCart>(jsonCart); if (cart == null) { return(0); } return(cart.ProductIDs.Count); }
private void EmailForList(List <Product> list) { string user = _readFromBrowser.ReadCookie("User"); if (user == null) { return; } User thisUser = JsonConvert.DeserializeObject <User>(user); string message = ""; foreach (var prod in list) { message += $"<h4>Product : {prod.Title} with the price of : {(double)prod.Price * 0.9} was purchased</h4>"; } _emailManger.SendEmail(message, thisUser.Email, "Purchased Notification!"); }
public IActionResult Index(string sortOrder) { string user = _read.ReadCookie("User"); if (user != null) { //if user exist _write.WriteToSession("User", user); User CurrectUser = JsonConvert.DeserializeObject <User>(user); ViewData["Name"] = CurrectUser.FirstName; } else { string UserPP = _read.ReadSession("User"); if (UserPP != null) { User CurrectUser = JsonConvert.DeserializeObject <User>(UserPP); ViewData["Name"] = CurrectUser.FirstName; } } var prods = _repositoryProducts.GetAllProducts(); switch (sortOrder) { case "name": prods = prods.OrderByDescending(p => p.Title).ToList(); break; case "date": prods = prods.OrderBy(p => p.Date).ToList(); break; case "price": prods = prods.OrderBy(p => p.Price).ToList(); break; default: prods = prods.OrderBy(p => p.Title).ToList(); break; } return(View(prods)); }