Пример #1
0
 private Product Create(Product product)
 {
     using (var productContext = new ProductContext())
     {
         var result = productContext.Products.Add(product);
         productContext.SaveChanges();
         return productContext.Products.Add(result);
     }
 }
Пример #2
0
 public Product Get(Guid productId)
 {
     Product result = null;
     using (var productContext = new ProductContext())
     {
         result = productContext.Products.Include("ChildProducts").SingleOrDefault(p => p.Id == productId);
     }
     return result;
 }
Пример #3
0
 private Product Update(Product product)
 {
     using (var productContext = new ProductContext())
     {
         productContext.Products.Attach(product);
         productContext.Entry(product).State = EntityState.Modified;
         productContext.SaveChanges();
         return product;
     }
 }
Пример #4
0
 public IEnumerable<Product> Get()
 {
     List<Product> result = null;
     using (var productContext = new ProductContext())
     {
         result = productContext.Products.ToList();
     }
     if (result == null)
     {
         return new List<Product>();
     }
     return result;
 }
Пример #5
0
 public void Delete(Guid productId)
 {
     Product toDel = null;
     using (var productContext = new ProductContext())
     {
         toDel = productContext.Products.Include("ChildProducts").SingleOrDefault(p => p.Id == productId);
         if (toDel != null)
         {
             productContext.Products.Remove(toDel);
             productContext.SaveChanges();
         }
         else
         {
             throw new ArgumentException();
         }
     }
 }