public List <CartProductsModel> GetCartProducts(int userId)
        {
            List <CartProductsModel> cartProducts = new List <CartProductsModel>();
            var   cartData = CartProcessor.LoadCartProducts(userId);
            float total    = 0.0f;

            if (cartData != null)
            {
                foreach (var row in cartData)
                {
                    cartProducts.Add(new CartProductsModel
                    {
                        Id                 = row.Id,
                        ProductId          = row.ProductId,
                        ProductDescription = ProductProcessor.GetProduct(row.ProductId).Description,
                        ProductImagePath   = ProductProcessor.GetProduct(row.ProductId).ImagePath,
                        ProductQty         = row.ProductQty,
                        ProductPrice       = row.ProductPrice,
                        AddedDate          = row.AddedDate
                    });
                    total = total + (row.ProductQty * row.ProductPrice);
                }
            }
            ViewBag.Total = total;
            return(cartProducts);
        }
        public List <ProductModel> GetFeatured()
        {
            Apriori ap = new Apriori(OrderProcessor.GetTransactionProductIdList(), 0.5f, 0.3f);
            var     featuredCollection = ap.Calculate();
            var     products           = new List <ProductModel>();

            foreach (var productId in featuredCollection)
            {
                products.Add(ProductProcessor.GetProduct(productId));
            }

            return(products);
        }
        public ActionResult ShowProduct(int productId)
        {
            if (IsActiveSession())
            {
                var data = ProductProcessor.GetProduct(productId);
                List <ProductModel> products = new List <ProductModel>();
                ProductModel        product  = new ProductModel
                {
                    Id            = data.Id,
                    ProductCode   = data.ProductCode,
                    Description   = data.Description,
                    UnitOfMeasure = data.UnitOfMeasure,
                    Category      = data.Category,
                    Price         = data.Price,
                    ImageTitle    = data.ImageTitle,
                    ImagePath     = data.ImagePath,
                    IsActive      = data.IsActive
                };
                products.Add(product);
                if (TempData["productAdded"] != null)
                {
                    ViewBag.productAdded = (bool)TempData["productAdded"];
                }
                else
                {
                    ViewBag.productAdded = false;
                }

                //getting cart products
                int userId = (int)Session["userId"];
                List <CartProductsModel> cartProducts = GetCartProducts(userId);

                //setting store products
                StoreViewModel storeViewModel = new StoreViewModel
                {
                    StoreProducts = products,
                    CartProducts  = cartProducts
                };
                return(View(storeViewModel));
            }
            return(RedirectToAction("Login", "Login", null));
        }
Esempio n. 4
0
 public ActionResult ProductDetail(int id)
 {
     if (IsActiveSession())
     {
         var          data    = ProductProcessor.GetProduct(id);
         ProductModel product = new ProductModel
         {
             Id            = data.Id,
             ProductCode   = data.ProductCode,
             Description   = data.Description,
             UnitOfMeasure = data.UnitOfMeasure,
             Category      = data.Category,
             Price         = data.Price,
             ImageTitle    = data.ImageTitle,
             ImagePath     = data.ImagePath,
             IsActive      = data.IsActive
         };
         return(View(product));
     }
     return(RedirectToAction("Login", "Login", null));
 }
        public ActionResult AddProductToCart(int productId, int productQty)
        {
            int userId         = (int)Session["userId"];
            int recordsCreated = CartProcessor.AddProductToCart(userId, productId, productQty, ProductProcessor.GetProduct(productId).Price);

            TempData["productAdded"] = true;
            return(RedirectToAction("ShowProduct", new { productId = productId }));
        }
 // GET: api/Product/5
 public ProductModel Get(int id)
 {
     return(ProductProcessor.GetProduct(id));
 }