public List <Vehicle> getall() { using (mydemoEntities mde = new mydemoEntities()) { return(mde.VehicleEntities.Select(ve => new Vehicle { ID = ve.ID, Year = ve.Year.Value, Make = ve.Make, Model = ve.Model }).ToList()); }; }
public Vehicle get(string id) { using (mydemoEntities mde = new mydemoEntities()) { int nid = Convert.ToInt32(id); return(mde.VehicleEntities.Where(ve => ve.ID == nid).Select(ve => new Vehicle { ID = ve.ID, Year = ve.Year.Value, Make = ve.Make, Model = ve.Model }).First()); }; }
public bool delete(Vehicle vehicle) { using (mydemoEntities mde = new mydemoEntities()) { try { int id = Convert.ToInt32(vehicle.ID); VehicleEntity ve = mde.VehicleEntities.Single(v => v.ID == id); mde.VehicleEntities.Remove(ve); mde.SaveChanges(); return(true); } catch (Exception) { return(false); } } }
public bool edit(Vehicle vehicle) { using (mydemoEntities mde = new mydemoEntities()) { try { int id = Convert.ToInt32(vehicle.ID); VehicleEntity ve = mde.VehicleEntities.Single(v => v.ID == id); ve.Year = vehicle.Year; ve.Make = vehicle.Make; ve.Model = vehicle.Model; mde.SaveChanges(); return(true); } catch (Exception) { return(false); } }; }
public bool create(Vehicle vehicle) { using (mydemoEntities mde = new mydemoEntities()) { try { VehicleEntity ve = new VehicleEntity(); ve.Year = vehicle.Year; ve.Make = vehicle.Make; ve.Model = vehicle.Model; mde.VehicleEntities.Add(ve); mde.SaveChanges(); return(true); } catch (Exception) { return(false); } }; }