/// <summary>
        /// Update quality for product variation when checkout
        /// </summary>
        /// <param name="models"></param>
        private void UpdateQuanlityProductVariation(IList <ShoppingCartDetailModel> models)
        {
            if (models != null)
            {
                foreach (var item in models)
                {
                    var proVa      = _productVariationService.GetById(item.ProductVariation_Id);
                    var cartDetail = _shoppingCartDetailService.GetById(item.Id);
                    proVa.StockQuantity = proVa.StockQuantity - cartDetail.Quantity;

                    _productVariationService.Update(proVa);
                }
            }
        }
Esempio n. 2
0
        public ActionResult AddOrEditProductVariation(Guid?id, ProVarationViewModel model, IEnumerable <HttpPostedFileBase> imageList)
        {
            try
            {
                bool   isNew     = !id.HasValue;
                string localFile = Server.MapPath("~/Content/img/product-men");

                // isNew = true update UpdatedDate of product
                // isNew = false get it by id
                var productVariation = isNew ? new ProductVariation
                {
                    UpdatedDate = DateTime.Now
                } : _productVariationService.GetById(id.Value);

                productVariation.Product_Id    = model.Product_Id;
                productVariation.SKU           = model.SKU;
                productVariation.Volume        = model.Volume;
                productVariation.Price         = model.Price;
                productVariation.StockQuantity = model.StockQuantity;
                productVariation.IsActive      = true;

                // if model.DiscountPrice != null then DiscountPrice =  model.DiscountPrice  else equal 0
                productVariation.DiscountPrice = (model.DiscountPrice.ToString() != null) ? model.DiscountPrice : 0;

                if (isNew)
                {
                    productVariation.CreatedDate = DateTime.Now;
                    productVariation.Id          = Guid.NewGuid();
                    _productVariationService.Insert(productVariation);

                    // add many image for product variation
                    AddImageOnProductImageTable(imageList, productVariation.Id);
                }
                else
                {
                    _productVariationService.Update(productVariation);

                    // Delete list image of product variation
                    DeleteListImageOnProductImageTable(imageList, productVariation.Id);
                    // add many image for product variation
                    AddImageOnProductImageTable(imageList, productVariation.Id);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(RedirectToAction("Index"));
        }