commiting errors

This commit is contained in:
Aneliya Konarcheva
2021-03-10 12:15:21 +02:00
parent 4b1b438381
commit 08fd6e67e8
10 changed files with 20 additions and 3 deletions

View File

@@ -0,0 +1,65 @@
using System.Collections.Generic;
using System.Linq;
using Business.Businesses;
using Models.Models;
namespace Business.Businesses
{
public class ProductBusiness
{
private ProductContext productContext;
public List<Product> GetAll()
{
using (productContext = new ProductContext())
{
return productContext.Products.ToList();
}
}
public Product Get(int id)
{
using (productContext = new ProductContext())
{
return productContext.Products.Find(id);
}
}
public void Buy(Product product)
{
using (productContext = new ProductContext())
{
productContext.Products.Add(product);
productContext.SaveChanges();
}
}
public void Update(Product product)
{
using (productContext = new ProductContext())
{
var item = productContext.Products.Find(product.Id);
if (item != null)
{
productContext.Entry(item).CurrentValues.SetValues(product);
productContext.SaveChanges();
}
}
}
public void Sell(int id)
{
using (productContext = new ProductContext())
{
var product = productContext.Products.Find(id);
if (product != null)
{
productContext.Products.Remove(product);
productContext.SaveChanges();
}
}
}
}
}