Ejemplo n.º 1
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"));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Add Product Variation With product Id and volume
        /// </summary>
        /// <param name="product_Id">Product Id</param>
        /// <param name="volume">Volume of product variation</param>
        public void AddProductVariation(Guid product_Id, string volume)
        {
            var item = new ProductVariation
            {
                Id            = Guid.NewGuid(),
                Product_Id    = product_Id,
                Volume        = volume,
                Price         = 0,
                SKU           = "Empty",
                StockQuantity = 0,
                CreatedDate   = DateTime.Now,
                IsActive      = true
            };

            _productVariationService.Insert(item);
        }