Esempio n. 1
0
 private void addCar(string name, string colour)
 {
     using (CarsDBEntities entities = new CarsDBEntities())
     {
         Car car = new Car {
             Name = name, Colour = colour
         };
         entities.Cars.Add(car);
         entities.SaveChanges();
     }
 }
Esempio n. 2
0
        private void updateCar(string name, string colour)
        {
            int carId = Convert.ToInt32(carDataGridView.SelectedRows[0].Cells[0].Value);

            using (CarsDBEntities entities = new CarsDBEntities())
            {
                Car car = (from c in entities.Cars where c.CarsId == carId select c).FirstOrDefault();
                car.Name   = name;
                car.Colour = colour;
                entities.SaveChanges();
            }
        }
Esempio n. 3
0
        private void removeCar()
        {
            int carId = Convert.ToInt32(carDataGridView.SelectedRows[0].Cells[0].Value);

            using (CarsDBEntities entities = new CarsDBEntities())
            {
                if (isCarRowSelected())
                {
                    Car car = (from r in entities.Cars where r.CarsId == carId select r).FirstOrDefault();
                    entities.Cars.Remove(car);
                    entities.SaveChanges();
                }
            }
        }