public class ProductDal : IProductDal
{
public void Add(Product product)
{
using (ETradeContext context = new ETradeContext())
{
context.Products.Add(product);
context.SaveChanges();
}
}
public void Delete(Product product)
{
using (ETradeContext context = new ETradeContext())
{
var productInDb = context.Entry(product);
productInDb.State = EntityState.Deleted;
context.SaveChanges();
}
}
public void Update(Product product)
{
using (ETradeContext context = new ETradeContext())
{
var productInDb = context.Entry(product);
productInDb.State = EntityState.Modified;
context.SaveChanges();
}
}