示例#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 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();
        }