示例#1
0
 public bool NoCars()
 {
     using (var db = new CarSalesDb())
     {
         return(!db.Cars.Any());
     }
 }
示例#2
0
 public Car FindCar(int id)
 {
     using (var db = new CarSalesDb())
     {
         return(db.Cars.Find(id));
     }
 }
示例#3
0
        //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>());
            }
        }
示例#4
0
 public void EditCar(Car car)
 {
     using (var db = new CarSalesDb())
     {
         db.Entry(car).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
示例#5
0
 public void CreateCar(Car car)
 {
     using (var db = new CarSalesDb())
     {
         db.Cars.Add(car);
         db.SaveChanges();
     }
 }
示例#6
0
 public void SaveEnquiry(Enquiry enquiry)
 {
     using (var db = new CarSalesDb())
     {
         db.Enquiries.Add(enquiry);
         db.SaveChanges();
     }
 }
示例#7
0
 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();
     }
 }
示例#8
0
 public void CreateCars(List <Car> cars)
 {
     using (var db = new CarSalesDb())
     {
         foreach (var car in cars)
         {
             db.Cars.Add(car);
             db.SaveChanges();
         }
     }
 }