コード例 #1
0
 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());
     };
 }
コード例 #2
0
 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());
     };
 }
コード例 #3
0
 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);
         }
     }
 }
コード例 #4
0
 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);
         }
     };
 }
コード例 #5
0
 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);
         }
     };
 }