Esempio n. 1
0
 public static void AddCustomHooks()
 {
     new RealTimeSellData();
     GlobalProductCache.SetUp();
     DiscountProvider.DiscountsManager     = new DiscountsOfTheDayAutoHandler();
     StickerManagerProvider.StickerManager = new StickerManager();
 }
Esempio n. 2
0
        public ActionResult Delete(int productId)
        {
            Product deletedProduct = _pRepository.DeleteProduct(productId);

            if (deletedProduct != null)
            {
                TempData["message"] = string.Format("{0} was deleted",
                                                    deletedProduct.Name);
            }
            GlobalProductCache.RemoveProduct(productId);
            GlobalCache.GetCache().ClearCachedItem <ProductModel>(productId);
            return(RedirectToAction("Index"));
        }
Esempio n. 3
0
 public ActionResult ClearAllDiscounts()
 {
     foreach (var p in _pRepository.Products.ToList())
     {
         if (p.Discount > 0)
         {
             p.Discount = 0;
             _pRepository.SaveProduct(p);
         }
     }
     GlobalProductCache.ProductCache.Clear();
     GlobalProductCache.SetUp();
     return(Redirect(Request.UrlReferrer.ToString()));
 }
Esempio n. 4
0
        // affiliate orders only come in one at a time
        public void ProcessAffiliateOrder(Product e, ShippingDetails shippingDetails, string affiliateId)
        {
            var ph = new Purchase
            {
                PurchaseDate    = DateTime.Now.ToString(),
                ShippingDetails = shippingDetails,
                ProductName     = e.Name,
                ProductCount    = 1,
                UserId          = affiliateId,
                Price           = e.Discount > 0 ? Helpers.CalculateDiscount(e.Price, e.Discount) : e.Price,
                ProductId       = e.ProductID,
                AffiliateId     = e.AffiliateId,
            };

            e.Quantity -= 1;
            _pRepository.SaveProduct(e);
            GlobalProductCache.UpdateProduct(e);
            RealTimeSellData.ReplaceOrUpdateTrackedProduct(e, 1);
            GlobalCache.GetCache().ClearCachedItem <ProductModel>(e.ProductID);
            _prRepository.SavePurchase(ph);
        }
Esempio n. 5
0
 public void ProcessOrder(Cart cart, ShippingDetails shippingDetails, string userId)
 {
     cart.CartEntries.ForEach(e => {
         var ph = new Purchase
         {
             PurchaseDate    = DateTime.Now.ToString(),
             ShippingDetails = shippingDetails,
             ProductName     = e.Product.Name,
             ProductCount    = e.Quantity,
             UserId          = userId,
             Price           = e.Product.Discount > 0 ? Helpers.CalculateDiscount(e.Product.Price, e.Product.Discount) : e.Product.Price,
             ProductId       = e.Product.ProductID,
             AffiliateId     = e.Product.AffiliateId
         };
         e.Product.Quantity -= e.Quantity;
         _pRepository.SaveProduct(e.Product);
         GlobalProductCache.UpdateProduct(e.Product);
         RealTimeSellData.ReplaceOrUpdateTrackedProduct(e.Product, e.Quantity);
         GlobalCache.GetCache().ClearCachedItem <ProductModel>(e.Product.ProductID);
         _prRepository.SavePurchase(ph);
     });
 }
Esempio n. 6
0
        public ActionResult Edit(Product product)
        {
            if (ModelState.IsValid)
            {
                _pRepository.SaveProduct(product);
                CheckIfDiscountChanged(product);
                TempData["message"] = string.Format("{0} has been saved", product.Name);
                ViewBag.Message     = $"Edit {product.Name} success";

                // clear the cached ProductModel so the edit gets propagated
                GlobalCache.GetCache().ClearCachedItem <ProductModel>(product.ProductID);

                // also update the global product cache
                GlobalProductCache.UpdateProduct(product);
                return(View(product));
            }
            else
            {
                // there is something wrong with the data values
                ViewBag.Message = ("Something went wrong");
                return(View(product));
            }
        }