Exemplo n.º 1
0
 public Product GetById(int id)
 {
     using (ETradeContext context = new ETradeContext())
     {// first or default ilkini alır single or default 1 den fazla ise hata fırlatır
         var result = context.Products.SingleOrDefault(p => p.Id == id);
         return(result);
     }
 }
Exemplo n.º 2
0
 public void Add(Product product)
 {
     using (ETradeContext context = new ETradeContext())
     {
         context.Products.Add(product); //context deki products a product ekle
         context.SaveChanges();         //veri tabanına yaz
     }
 }
Exemplo n.º 3
0
 public Product GetById(int id)//verilen id e gore product getirir
 {
     using (ETradeContext context = new ETradeContext())
     {
         var result = context.Products.FirstOrDefault(p => p.Id == id);//FirstorDefault girilen id varsa product getirir yoksa null getirir
         return(result);
     }
 }
Exemplo n.º 4
0
 public List <Product> GetAll()
 {
     /*using kullanarak dispose işlemi yapılır garbage collector çalışır. Method bitince memory temizlenir.*/
     using (ETradeContext context = new ETradeContext())
     {
         return(context.Products.ToList());
     }
 }
Exemplo n.º 5
0
 public void Add(Product product)
 {
     using (ETradeContext context = new ETradeContext())
     {
         context.Products.Add(product); // içine verdiğimiz nesneyi ekliyor.
         context.SaveChanges();         // yaptığımız işlemleri commit ediyoruz.
     }
 }
Exemplo n.º 6
0
 public List <Product> GetByName(string key)
 {
     using (ETradeContext context = new ETradeContext())
     {
         // bu işlemi veri tabanında yapmak daha hızlı sonuç verir.
         return(context.Products.Where(p => p.Name.Contains(key)).ToList());
     }
 }
Exemplo n.º 7
0
 public List <Product> GetByUnitPrice(decimal price)
 {
     // Min max parametreleri arasında bulunan unitprice a sahip ürünleri döndürür.
     using (ETradeContext context = new ETradeContext())
     {
         return(context.Products.Where(p => p.UnitPrice >= price).ToList());
     }
 }
Exemplo n.º 8
0
 internal List <Product> GetByUnitPrice(decimal min, decimal max) //iki fiyat arası için filtreleme
 {
     using (ETradeContext context = new ETradeContext())
     {
         return(context.Products.Where(p => p.UnitPrice >= min && p.UnitPrice <= max).ToList());
         //burada veri tabanını sorgulayıp ürünleri filtreleyip iki fiyat arasındaki verileri almak için kod yazdık
     }
 }
Exemplo n.º 9
0
 internal List <Product> GetByUnitPrice(decimal price) //fiyat olarak aramak istersek
 {
     using (ETradeContext context = new ETradeContext())
     {
         return(context.Products.Where(p => p.UnitPrice >= price).ToList());
         //burada veri tabanını sorgulayıp ürünleri filtreleyip fiyat sorgulamak için bir kod yazdık
     }
 }
Exemplo n.º 10
0
 public Product GetById(int id)
 {
     using (ETradeContext context = new ETradeContext())
     {
         return(context.Products.FirstOrDefault(p => p.Id == id));
         //return context.Products.SingleOrDefault(p => p.Id == id); Eğer aynı değerde birden fazla veri bulursa hata fırlatır.
     }
 }
Exemplo n.º 11
0
 //App.Config içerisine sql bağlantımızı aldık.
 public List <Product> GetAll()
 {
     using (ETradeContext context = new ETradeContext()
            )                               //ETradeContext pahalı bir nesne bu bağlamda method bittiği zaman bellekten atar GarbageCollector Dispose yapar direk!!!
     {
         return(context.Products.ToList()); //veritabanındaki tabloya erişip listeledik.
     }
 }
Exemplo n.º 12
0
 public List <Product> GetAll()
 {
     //Bu blok içerisinde context'i kullanır daha sonrasında bellekten atar. (Dispose eder.)
     using (ETradeContext context = new ETradeContext())
     {
         return(context.Products.ToList());
     }
 }
Exemplo n.º 13
0
        public List<Product> GetAll()
        {
            using (ETradeContext context = new ETradeContext())
            {
                return context.Products.ToList();
            }

        }
Exemplo n.º 14
0
 public List <Product> GetByUnitPrice(decimal min, decimal max)
 {
     using (ETradeContext context = new ETradeContext())
     {   //parametre olarak gelen key ile veri tabanındaki UnitPrice karşılaştırılır. min-max arasında yer alan veriler döndürülür.
         var result = context.Products.Where(p => p.UnitPrice >= min && p.UnitPrice <= max).ToList();
         return(result);
     }
 }
Exemplo n.º 15
0
 public List <Product> GetByName(string key)
 {
     using (ETradeContext context = new ETradeContext())
     { //parametre olarak gelen key veri tabanında sorgulanır ve eşleşen değerler geri döndürülür.
         var result = context.Products.Where(p => p.Name.Contains(key)).ToList();
         return(result);
     }
 }
Exemplo n.º 16
0
 public List <Product> GetByUnitPrice(decimal price)
 {
     using (ETradeContext context = new ETradeContext())
     {   //parametre olarak gelen price ile veri tabanındaki UnitPrice karşılaştırılır. price a eşit veya daha yüksek veriler döndürülür.
         var result = context.Products.Where(p => p.UnitPrice >= price).ToList();
         return(result);
     }
 }
Exemplo n.º 17
0
 public List <Product> GetByUnitPrice(decimal min, decimal max)
 {
     //Veri Tabanına erişme ve listeleme
     using (ETradeContext context = new ETradeContext())
     {
         return(context.Products.Where(p => p.UnitPrice >= min && p.UnitPrice <= max).ToList());
     }
 }
Exemplo n.º 18
0
 public List <Product> GetAll()
 {
     //Veri Tabanına erişme ve listeleme
     using (ETradeContext context = new ETradeContext())
     {
         return(context.Products.ToList());
     }
 }
Exemplo n.º 19
0
 public void Add(Product product)
 {
     using (ETradeContext context = new ETradeContext())
     {
         context.Products.Add(product);
         context.SaveChanges();
     }
 }
Exemplo n.º 20
0
 public List <Product> GetById(int id)
 {
     using (ETradeContext context = new ETradeContext())
     {
         var result = context.Products.FirstOrDefault(p => p.Id == id);
         return(result);
     }
 }
Exemplo n.º 21
0
 public Product GetById(int id)
 {
     using (ETradeContext context = new ETradeContext())
     {
         var result = context.Products.SingleOrDefault(p => p.Id == id);
         return(result);
     }
 }
Exemplo n.º 22
0
 public List <Product> GetName(string key)
 {
     using (ETradeContext context = new ETradeContext())
     {
         //Burası veri tabanına Where ile sorgu atar. Sql de küçük büyük harf duyarlılığı yoktur.
         return(context.Products.Where(p => p.Name.Contains(key)).ToList());
     }
 }
Exemplo n.º 23
0
 public Product GetById(int id)
 {
     using (ETradeContext context = new ETradeContext()) //Nesneyi zorla bellekten atarak garbage collector ı beklemeden boşaltır.
     {
         var result = context.Products.SingleOrDefault(p => p.Id == id);
         return(result);
     }
 }
Exemplo n.º 24
0
 public List <Product> GetByName(string key)
 {
     //Veri Tabanına erişme ve listeleme
     using (ETradeContext context = new ETradeContext())
     {
         return(context.Products.Where(p => p.Name.Contains(key)).ToList());
     }
 }
Exemplo n.º 25
0
 public void Add(Product product)
 {
     using (ETradeContext context = new ETradeContext())
     {
         var entity = context.Entry(product);                 //oluşturulan var entity contextle bağlantı kurup gönderilen parametreyi karşılaştırılır.
         entity.State = System.Data.Entity.EntityState.Added; //EntityState de yer alan ekleme fonksiyonu çalıştırılır.
         context.SaveChanges();                               //değişiklikler kaydedilir.
     }
 }
Exemplo n.º 26
0
 public Product GetById(int id)
 {
     //Veri Tabanına erişme ve listeleme
     using (ETradeContext context = new ETradeContext())
     {
         var result = context.Products.FirstOrDefault(p => p.Id == id);
         return(result);
     }
 }
Exemplo n.º 27
0
 public void Update(Product product)
 {
     using (ETradeContext context = new ETradeContext())
     {
         var entity = context.Entry(product);
         entity.State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
Exemplo n.º 28
0
 public void Delete(Product product)
 {
     using (ETradeContext context = new ETradeContext())
     {
         var entity = context.Entry(product);
         entity.State = System.Data.Entity.EntityState.Deleted;//EntityState de yer alan silme fonksiyonu çalıştırılır.
         context.SaveChanges();
     }
 }
Exemplo n.º 29
0
 public void Delete(Product product)
 {
     using (ETradeContext context = new ETradeContext())
     {
         var entity = context.Entry(product);
         entity.State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
Exemplo n.º 30
0
 public void Delete(Product product)
 {
     using (ETradeContext context = new ETradeContext())
     {
         var entity = context.Entry(product); //contexte abone ol product için gönderdiğimiz productu veritabanındaki product ile eşitliyor
         entity.State = EntityState.Deleted;  //id üzerinden eşitler primary key olduğu için
         context.SaveChanges();
     }
 }