示例#1
0
 public Category GetCategory(int ID)
 {
     using (var context = new MvcComContext())
     {
         return(context.Categories.Find(ID));
     }
 }
示例#2
0
 public List <Category> GetCategory()
 {
     using (var context = new MvcComContext())
     {
         return(context.Categories.ToList());
     }
 }
示例#3
0
 public Product GetProduct(int ID)
 {
     using (var context = new MvcComContext())
     {
         return(context.Products.Find(ID));
     }
 }
示例#4
0
 public List <Product> GetProducts()
 {
     using (var context = new MvcComContext())
     {
         return(context.Products.ToList());
     }
 }
示例#5
0
 public void UpdateCategory(Category category)
 {
     using (var context = new MvcComContext())
     {
         context.Entry(category).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
示例#6
0
 public void UpdateProduct(Product product)
 {
     using (var context = new MvcComContext())
     {
         context.Entry(product).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
示例#7
0
        public void SaveCategory(Category category)
        {
            using (var context = new MvcComContext())
            {
                context.Categories.Add(category);

                context.SaveChanges();
            }
        }
示例#8
0
        public void SaveProduct(Product product)
        {
            using (var context = new MvcComContext())
            {
                context.Products.Add(product);

                context.SaveChanges();
            }
        }
示例#9
0
 public void DeleteCategory(int ID)
 {
     using (var context = new MvcComContext())
     {
         var category = context.Categories.Find(ID);
         //context.Entry(category).State = System.Data.Entity.EntityState.Deleted;
         //both will work
         context.Categories.Remove(category);
         context.SaveChanges();
     }
 }