Exemplo n.º 1
0
 /// <summary>
 /// Persist a product
 /// </summary>
 /// <param name="product"></param>
 public void Create(ProductEntity product)
 {
     using (EFContext context = new EFContext())
     {
         context.Products.Add(product);
         context.SaveChanges();
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Return a product by id
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public ProductEntity Get(Int32 id)
 {
     using (EFContext context = new EFContext())
     {
         ProductEntity query = context.Products.FirstOrDefault(p => p.Id == id);
         return query;
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Update stock and state from a product
 /// </summary>
 /// <param name="product"></param>
 public void Update(ProductEntity product)
 {
     using (EFContext context = new EFContext())
     {
         context.Products.Attach(product);
         context.Entry(product).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Archive a product
 /// </summary>
 /// <param name="id"></param>
 public void Archive(Int32 id)
 {
     using (EFContext context = new EFContext())
     {
         ProductEntity product = context.Products.FirstOrDefault(p => p.Id == id);
         product.IsActive = false;
         context.SaveChanges();
     }
 }