private void displayCars() { using (CarsDBEntities entities = new CarsDBEntities()) { entities.Cars.Load(); carDataGridView.DataSource = entities.Cars.Local; } }
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(); } }
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(); } }
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(); } } }