Example #1
0
 public void CreatedCategory(Category category)
 {
     using (var db = new NorthwindConnect())
     {
         db.Categories.Add(category);
         db.SaveChanges();
     }
 }
Example #2
0
 public Category CreateCategory(string v1, string v2)
 {
     using (var db = new NorthwindConnect())
     {
         var category = new Category(v1, v2);
         db.Categories.Add(category);
         db.SaveChanges();
         return(db.Categories.Last());
     }
 }
Example #3
0
        /*public void DeleteCategory(object id)
         * {
         *  using (var db = new NorthwindConnect())
         *  {
         *      db.Categories.Remove(db.Categories.Find(id));
         *      db.SaveChanges();
         *  }
         * }*/

        public bool DeleteCategory(int id)
        {
            using (var db = new NorthwindConnect())
            {
                var category = db.Categories.Find(id);
                if (category == null)
                {
                    return(false);
                }
                db.Categories.Remove(db.Categories.Find(id));
                db.SaveChanges();
                return(true);
            }
        }
Example #4
0
 public bool UpdateCategory(int id, string name, string description)
 {
     using (var db = new NorthwindConnect())
     {
         var category = db.Categories.Find(id);
         if (category == null)
         {
             return(false);
         }
         category.Id          = id;
         category.Name        = name;
         category.Description = description;
         db.SaveChanges();
         return(true);
     }
 }