示例#1
0
        public void Delete(Product pro)
        {
            if (pro != null)
            {
                ImageHandeler.DeleteImage(pro.Image, hostingEnvironment.WebRootPath);

                db.Remove(pro);
                db.SaveChanges();
            }
        }
示例#2
0
        public void AddProduct(CreateProductVM model)
        {
            string imagePath = ImageHandeler.UploadImage(model.PhotoBinary, hostingEnvironment.WebRootPath);

            Product pro = new Product
            {
                Name     = model.Name,
                Price    = model.Price,
                Image    = imagePath,
                Type     = model.Type,
                Category = model.Category
            };

            db.Products.Add(pro);
            db.SaveChanges();
        }
示例#3
0
        public void Update(CreateProductVM updatedPro)
        {
            Product OldProduct = db.Products.Find(updatedPro.Id);

            //delete old image.

            if (updatedPro.PhotoBinary != null)
            {
                bool output = ImageHandeler.DeleteImage(OldProduct.Image, hostingEnvironment.WebRootPath);
                OldProduct.Image = ImageHandeler.UploadImage(updatedPro.PhotoBinary, hostingEnvironment.WebRootPath);
            }

            OldProduct.Name     = updatedPro.Name;
            OldProduct.Price    = updatedPro.Price;
            OldProduct.Category = updatedPro.Category;
            OldProduct.Type     = updatedPro.Type;
            db.SaveChanges();
        }