Пример #1
0
 //private int DiscountRate = 0;
 public BuyOneFreeOne(ProductAbstract product)
     : base(product)
 {
     OptionCode = "BuyOneFreeOne";
     Price      = 0;
 }
 public DiscountDecorator(ProductAbstract product)
     : base(product)
 {
     this.OptionCode = "Discount";
     this.Price      = 0;
 }
Пример #3
0
        public async Task <IActionResult> InsertProductConfirm(ProductViewModel model)
        {
            string nvm;
            var    currentUser = await userManager.FindByNameAsync(User.Identity.Name);

            if (ModelState.IsValid == false)
            {
                nvm = NotificationHandler.SerializeMessage <string>(NotificationHandler.Wrong_Values, contentRootPath);
                return(RedirectToAction("ShowProduct", new { notification = nvm }));
            }
            //Check Unique Product Code -- Start
            var IsCodeExist = dbProductFeature.GetAll().Where(e => e.ProductCode == model.Code).FirstOrDefault();

            if (IsCodeExist != null)
            {
                nvm = NotificationHandler.SerializeMessage <string>(NotificationHandler.DuplicatedValue, contentRootPath);
                return(RedirectToAction("ShowProduct", new { notification = nvm }));
            }
            //Check Unique Product Code -- End
            try
            {
                ProductAbstract productAbstract = new ProductAbstract()
                {
                    Name             = model.Name,
                    BrandId          = model.BrandI,
                    CategoryId       = model.CategoryId,
                    Status           = model.Status,
                    UserId           = currentUser.Id,
                    BasePrice        = model.BasePrice,
                    ContentAvailable = model.ContentAvailable,
                    RegDateTime      = DateTime.Now
                };
                int id = dbProductAbstract.Insert(productAbstract);

                ProductFeature productFeature = new ProductFeature()
                {
                    ProductAbstractId = id,
                    ProductCode       = model.Code,
                    Status            = model.Status,
                    UserId            = currentUser.Id,
                    RegDateTime       = DateTime.Now,
                    Count             = 10
                };
                dbProductFeature.Insert(productFeature);

                //Insert Main Image - Start
                if (model.MainImage != null)
                {
                    ProductImage productImage = new ProductImage()
                    {
                        ProductId   = id,
                        UserId      = currentUser.Id,
                        GrayScale   = false,
                        Compressed  = false,
                        IsMainImage = true
                    };

                    string folderPath = _configuration.GetSection("DefaultPaths").GetSection("ProductImage").Value;

                    string savePath = await FileManager.SaveImageInDirectory(contentRootPath, folderPath, model.MainImage, true, id);

                    string thumnailSavePath = FileManager.SaveThumbnail(savePath, contentRootPath, folderPath, ImageFormat.Png, true, id);

                    productImage.ImagePath          = savePath;
                    productImage.ImageThumbnailPath = thumnailSavePath;

                    dbProductImage.Insert(productImage);
                }
                //Insert Main Image - End
                //Insert Other Images -Start
                if (model.img != null)
                {
                    foreach (var item in model.img)
                    {
                        ProductImage productImage = new ProductImage()
                        {
                            ProductId  = id,
                            UserId     = currentUser.Id,
                            GrayScale  = false,
                            Compressed = false
                        };

                        string folderPath = _configuration.GetSection("DefaultPaths").GetSection("ProductImage").Value;

                        string savePath = await FileManager.SaveImageInDirectory(contentRootPath, folderPath, item, true, id);

                        string thumnailSavePath = FileManager.SaveThumbnail(savePath, contentRootPath, folderPath, ImageFormat.Png, true, id);

                        productImage.ImagePath          = savePath;
                        productImage.ImageThumbnailPath = thumnailSavePath;

                        dbProductImage.Insert(productImage);
                    }
                }
                //Insert Other Images -End
                nvm = NotificationHandler.SerializeMessage <string>(NotificationHandler.Success_Insert, contentRootPath);
                return(RedirectToAction("ShowProduct", new { notification = nvm }));
            }
            catch (Exception)
            {
                nvm = NotificationHandler.SerializeMessage <string>(NotificationHandler.Failed_Insert, contentRootPath);
                return(RedirectToAction("ShowProduct", new { notification = nvm }));
            }
        }