Example #1
0
 public Brand Get(Expression <Func <Brand, bool> > filter)
 {
     using (MyDatabaseContext context = new MyDatabaseContext())
     {
         return(context.Set <Brand>().SingleOrDefault(filter));
     }
 }
Example #2
0
 public Color GetById(Expression <Func <Color, bool> > filter)
 {
     using (MyDatabaseContext context = new MyDatabaseContext())
     {
         return(context.Set <Color>().SingleOrDefault(filter));
     }
 }
Example #3
0
 public void Update(Color entity)
 {
     using (MyDatabaseContext context = new MyDatabaseContext())
     {
         var updatedEntity = context.Entry(entity);  //Referansı yakala
         updatedEntity.State = EntityState.Modified; //Bu güncellenecek bir nesne
         context.SaveChanges();                      //Değişikliği kaydet
     }
 }
Example #4
0
 public void Delete(Color entity)
 {
     using (MyDatabaseContext context = new MyDatabaseContext())
     {
         var deletedEntity = context.Entry(entity); //Referansı yakala
         deletedEntity.State = EntityState.Deleted; //Bu silinecek bir nesne
         context.SaveChanges();                     //Değişikliği kaydet
     }
 }
Example #5
0
 public void Add(Color entity)
 {
     using (MyDatabaseContext context = new MyDatabaseContext()) //using içine yazdığımız şeyler bitince atılacak.
     {
         var addedEntity = context.Entry(entity);                //Referansı yakala.
         addedEntity.State = EntityState.Added;                  //Bu eklenecek bir nesne
         context.SaveChanges();                                  //Değişikliği kaydet
     }
 }
Example #6
0
 public List <Color> GetAll(Expression <Func <Color, bool> > filter = null)
 {
     using (MyDatabaseContext context = new MyDatabaseContext())
     {
         return(filter == null                                //Filtre null mı ?
             ? context.Set <Color>().ToList()                 //Evetse bura çalışır
             : context.Set <Color>().Where(filter).ToList()); //Değilse bura çalışır
     }
 }
Example #7
0
 public void Update(Car entity)
 {
     using (MyDatabaseContext context = new MyDatabaseContext())
     {
         var updatedEntity = context.Entry(entity);
         updatedEntity.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Example #8
0
 public List <Car> GetAll(Expression <Func <Car, bool> > filter = null)
 {
     using (MyDatabaseContext context = new MyDatabaseContext())
     {
         return(filter == null
             ? context.Set <Car>().ToList()
             : context.Set <Car>().Where(filter).ToList());
     }
 }
Example #9
0
 public void Delete(Car entity)
 {
     using (MyDatabaseContext context = new MyDatabaseContext())
     {
         var deletedEntity = context.Entry(entity);
         deletedEntity.State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
Example #10
0
        public void Add(Car entity)
        {
            if (entity.Description.Length >= 2 && entity.DailyPrice > 0)
            {
                using (MyDatabaseContext context = new MyDatabaseContext())

                {
                    var addedEntity = context.Entry(entity);
                    addedEntity.State = EntityState.Added;
                    context.SaveChanges();
                }
            }
            else
            {
                Console.WriteLine("Araba ismi iki karakterden uzun olmalı ve günlük ücreti 0 tl'den fazla olmalıdır.");
            }
        }