public class ProductDal { public List GetAll() { using (TestContext context = new TestContext()) { return context.Products.ToList(); } } public List GetByName(string key) { using (TestContext context = new TestContext()) { return context.Products.Where(p => p.Name.Contains(key)).ToList(); } } //public List GetByUnitPrice(decimal min,decimal max) //{ // using (TestContext context = new TestContext()) // { // return context.Products.Where(p => p.UnitPrice>=min && p.UnitPrice<=max).ToList(); // } //} //public Product GetByID(int id) //tek değer döndürüyoruz //{ // using (TestContext context = new TestContext()) // { // var result= context.Products.FirstOrDefault(p => p.ID == id); // return result; // } //} public void Add(Product product) { using (TestContext context = new TestContext()) { context.Products.Add(product); //var entity = context.Entry(product); //entity.State = EntityState.Added; context.SaveChanges(); } } public void Update(Product product) { using (TestContext context = new TestContext()) { var entity = context.Entry(product); entity.State = EntityState.Modified; context.SaveChanges(); } } public void Delete(Product product) { using (TestContext context = new TestContext()) { var entity = context.Entry(product); entity.State = EntityState.Deleted; context.SaveChanges(); } } }