Example #1
0
        public IActionResult AddToCart(int ProductID, int FamilyID)
        {
            Product product = new Product();
            Cart    cart    = new Cart();

            try
            {
                if (!CuponSession.IsUserLogin(HttpContext.Session))
                {
                    return(RedirectToAction("Register", "Account"));
                }
                product = ProductRepository.Read(ProductID);
                product.DiscountAmount = string.Format("{0:0.##}", (product.Prize - ((product.Prize * product.Discount) / 100)));
                cart.Quantity          = 1;
                cart.Total             = Convert.ToDecimal(product.DiscountAmount);
                cart.ProductID         = ProductID;
                cart.UserID            = CuponSession.GetUser(HttpContext.Session).UserID;
                CartRepository.Insert(cart);
            }
            catch (Exception ex)
            {
                ViewData["ErrorMessage"] = ex.Message;
            }
            return(RedirectToAction("Cart", new { FamilyID }));
        }
Example #2
0
 public IActionResult Delete(int cartID)
 {
     try
     {
         if (!CuponSession.IsUserLogin(HttpContext.Session))
         {
             return(RedirectToAction("Register", "Account"));
         }
         CartRepository.Delete(cartID);
     }
     catch (Exception ex)
     {
         ViewData["ErrorMessage"] = ex.Message;
     }
     return(RedirectToAction("Cart"));
 }
Example #3
0
 public IActionResult Cart(int FamilyID)
 {
     try
     {
         if (!CuponSession.IsUserLogin(HttpContext.Session))
         {
             return(RedirectToAction("Register", "Account"));
         }
         CartVewModel          = new CartVewModel(CuponSession.GetUser(HttpContext.Session).UserID);
         CartVewModel.FamilyID = FamilyID;
         CartVewModel.Products = CartVewModel.Products.Where(x => x.DepartmentID == CuponSession.GetDepartmentID(HttpContext.Session)).ToList();
     }
     catch (Exception ex)
     {
         ViewData["ErrorMessage"] = ex.Message;
     }
     return(View(CartVewModel));
 }