public static List<OCar> Cars() { var carsList = new List<OCar>(); using (CarDBEntities2 cars = new CarDBEntities2()) { foreach (Car c in cars.Cars) { carsList.Add(new OCar() { ImageUrl = c.ImageUrl, Year = c.Year, Description = c.Description, Id = c.Id, Model = c.Model, Make = c.Make, Price = c.Price, Title = c.Title }); } } return carsList; }
public void AddCar(OCar oCar) { //car.Id = Cars.Max(c => c.Id) + 1; using (CarDBEntities2 cars = new CarDBEntities2()) { cars.Cars.Add(new Car() { Model = oCar.Model, Make = oCar.Make, Description = oCar.Description, ImageUrl = oCar.ImageUrl, Price = oCar.Price, Title = oCar.Title, Year = oCar.Year }); cars.SaveChanges(); } }