public void Delete(int Id)
 {
     using (ApplicationDbContext db = new ApplicationDbContext())
     {
         Product product = db.Products.Find(Id);
         if (product != null)
         {
             db.Products.Remove(product);
             db.SaveChanges();
             ImageManage.Delete(product.ImagePath);
         }
     }
 }
Пример #2
0
        public void Delete(int Id)
        {
            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                Category       category = db.Categories.Find(Id);
                List <Product> list     = db.Products.Where(m => m.CategoryId == Id).ToList();

                foreach (var a in list)
                {
                    ImageManage.Delete(a.ImagePath);
                }

                if (category != null)
                {
                    db.Categories.Remove(category);
                    db.SaveChanges();
                    ImageManage.Delete(category.ImagePath);
                }
            }
        }
        public bool Add(Product product, List <HttpPostedFileBase> images)
        {
            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                if (db.Products.FirstOrDefault(m => m.Name == product.Name) != null)
                {
                    return(false);
                }

                product.ImagePath = "/Images/Product/" + product.CategoryId + "/" + product.Name.Replace(" ", "_") + "/";
                if (ImageManage.Add(product.ImagePath, images))
                {
                    db.Products.Add(product);
                    db.SaveChanges();

                    return(true);
                }
                return(false);
            }
        }
Пример #4
0
        public bool Add(Category category, List <HttpPostedFileBase> images)
        {
            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                if (db.Categories.FirstOrDefault(m => m.Name == category.Name) != null)
                {
                    return(false);
                }

                category.ImagePath = "/Images/Category/" + category.Name + "/";

                if (ImageManage.Add(category.ImagePath, images))
                {
                    db.Categories.Add(category);
                    db.SaveChanges();
                    return(true);
                }
                return(false);
            }
        }