Ejemplo n.º 1
0
 public IEnumerable <Product> GetProducts()
 {
     using (var productContext = new ProductCatalogContext())
     {
         return(productContext.Products.ToList());
     }
 }
Ejemplo n.º 2
0
 public List <Product> GetById(string id)
 {
     using (var productContext = new ProductCatalogContext())
     {
         return(productContext.Products.Where(x => x.productId == id).ToList());
     }
 }
Ejemplo n.º 3
0
 public bool Post(Product product)
 {
     using (var productContext = new ProductCatalogContext())
     {
         productContext.Products.Add(product);
         productContext.SaveChanges();
         return(true);
     }
 }
Ejemplo n.º 4
0
 public bool Update(Product product)
 {
     using (var productContext = new ProductCatalogContext())
     {
         productContext.Products.AddOrUpdate(x => x.productId, product);
         productContext.SaveChanges();
         return(true);
     }
 }
Ejemplo n.º 5
0
 public bool Remove(string id)
 {
     using (var productContext = new ProductCatalogContext())
     {
         Product prod = productContext.Products.Where(x => x.productId == id).SingleOrDefault();
         productContext.Products.Remove(prod);
         productContext.SaveChanges();
         return(true);
     }
 }