public Dictionary <int, bool> UploadImage([Bind(Include = "Files, IsDisplayPosition")] ProductDetailModel productDetailModel)
        {
            Image image = new Image();
            Dictionary <int, bool> lstImageID = new Dictionary <int, bool>();
            int position = 1;

            foreach (HttpPostedFileBase file in productDetailModel.Files)
            {
                string fname = FileMng.UploadFile(file, "/Images");
                image.path   = "Images\\" + fname;
                image.IconID = _dbContext.Icon.Max(i => i.IconID);
                _dbContext.Image.Add(image);
                _dbContext.SaveChanges();

                if (position == productDetailModel.IsDisplayPosition)
                {
                    lstImageID.Add(_dbContext.Image.Max(i => i.ImageID), true);  //set us display
                }
                else
                {
                    lstImageID.Add(_dbContext.Image.Max(i => i.ImageID), false);
                }
                position++;
            }
            return(lstImageID);
        }
        private void ChangeIconAndDirectoryPath([Bind(Include = "IconID, IconFile")] ProductDetailModel productDetailModel)
        {
            Icon icon = new Icon();
            HttpPostedFileBase file = productDetailModel.IconFile;
            string             path = "Images\\AddImageIcon\\" + FileMng.UploadFile(file, "/Images/AddImageIcon");

            icon.IconID = productDetailModel.IconID;
            icon.icon1  = path; //new path
            _dbContext.Entry(icon).State = EntityState.Modified;
            _dbContext.SaveChanges();
        }
        private void ChangeImage([Bind(Include = "Files, FileToRemove")] ProductDetailModel productDetailModel)
        {
            int[] arrImgID = productDetailModel.FileToRemove.Where(f => f != 0).ToArray();
            int   indx     = 0;

            foreach (HttpPostedFileBase file in productDetailModel.Files)
            {
                Image image = _dbContext.Image.Find(arrImgID[indx++]);
                image.path = "Images\\" + FileMng.UploadFile(file, "/Images");
                _dbContext.SaveChanges();
            }
        }
        public void CreateProductDetail([Bind] ProductDetailModel productDetailModel)
        {
            //upload icon path
            productDetailModel.IconPath = "Images\\AddImageIcon\\" + FileMng.UploadFile(productDetailModel.IconFile, "/Images/AddImageIcon");
            _productDetailRepository.CreateNewIcon(new ProductDetailModel()
            {
                IconPath = productDetailModel.IconPath
            });
            //create product size and color
            List <int> ListingProductDetailID = _productDetailRepository.CreateProductSizeAndColor(new ProductDetailModel {
                ProductID = productDetailModel.ProductID, ColorID = productDetailModel.ColorID, SizeID = productDetailModel.SizeID
            });
            //upload images
            Dictionary <int, bool> ListingImageID = _productDetailRepository.UploadImage(new ProductDetailModel {
                Files = productDetailModel.Files, IsDisplayPosition = productDetailModel.IsDisplayPosition
            });

            _productDetailRepository.CreateProductDetail(productDetailModel, ListingProductDetailID, ListingImageID);
            _productDetailRepository.CreateDisplayDetail(new ProductDetailModel {
                ProductID = productDetailModel.ProductID
            }, ListingImageID.Where(i => i.Value == true).FirstOrDefault().Key);
        }