예제 #1
0
 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"));
 }
예제 #2
0
        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));
        }
예제 #3
0
 public bool CheckUserLogin()
 {
     if (_read.ReadCookie("User") != null)
     {
         return(true);
     }
     return(false);
 }
예제 #4
0
        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)));
        }
예제 #5
0
        public User GetUserFromCookie()
        {
            string user = _read.ReadCookie("User");

            if (user != null)
            {
                User newUser = JsonConvert.DeserializeObject <User>(user);
                return(newUser);
            }
            return(null);
        }
예제 #6
0
        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);
        }
예제 #7
0
        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!");
        }
예제 #8
0
        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));
        }