Esempio n. 1
0
 public bool DeleteCategory(int id)
 {
     try
     {
         using (var db = new NorthwindContex())
         {
             var delCat = new Category()
             {
                 Id = id
             };
             db.Categories.Attach(delCat);
             db.Categories.Remove(delCat);
             db.SaveChanges();
             if (delCat != null)
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
     }
     catch (Exception) { } return(false);
 }
 public bool UpdateCategory(int categoryId, String name, String description)
 {
     using (var db = new NorthwindContex())
     {
         var category = db.Categories.FirstOrDefault(x => x.Id == categoryId);
         if (category != null)
         {
             category.Name        = name;
             category.Description = description;
             db.SaveChanges();
             return(true);
         }
         return(false);
     }
 }
Esempio n. 3
0
 public Category CreateCategory(string name, string description)
 {
     using (var db = new NorthwindContex())
     {
         var count  = GetCategories();
         var newCat = new Category()
         {
             Id          = count.Count() + 1,
             Name        = name,
             Description = description
         };
         db.Categories.Add(newCat);
         db.SaveChanges();
         return(newCat);
     }
 }
        public bool DeleteCategory(int id)
        {
            using (var db = new NorthwindContex())
            {
                var category = db.Categories.FirstOrDefault(x => x.Id == id);

                if (category != null)
                {
                    db.Categories.Remove(category);

                    db.SaveChanges();

                    return(true);
                }
                return(false);
            }
        }