public bool NoCars() { using (var db = new CarSalesDb()) { return(!db.Cars.Any()); } }
public Car FindCar(int id) { using (var db = new CarSalesDb()) { return(db.Cars.Find(id)); } }
//public class CarSalesDb : DbContext //{ // public DbSet<Car> Cars { get; set; } //} public List <Car> GetCars() { using (var db = new CarSalesDb()) { return(db.Cars.Any() ? db.Cars.ToList() : new List <Car>()); } }
public void EditCar(Car car) { using (var db = new CarSalesDb()) { db.Entry(car).State = EntityState.Modified; db.SaveChanges(); } }
public void CreateCar(Car car) { using (var db = new CarSalesDb()) { db.Cars.Add(car); db.SaveChanges(); } }
public void SaveEnquiry(Enquiry enquiry) { using (var db = new CarSalesDb()) { db.Enquiries.Add(enquiry); db.SaveChanges(); } }
public void DeleteCar(int carId) { using (var db = new CarSalesDb()) { var carToRemove = db.Cars.FirstOrDefault(c => c.Id == carId); db.Cars.Remove(carToRemove); db.SaveChanges(); } }
public void CreateCars(List <Car> cars) { using (var db = new CarSalesDb()) { foreach (var car in cars) { db.Cars.Add(car); db.SaveChanges(); } } }