public IHttpActionResult GetVehicleModel(int id) { CarSalesVehicleModel vehicleModel = db.VehicleModels.Where(e => e.ID == id). Select(carSalesVehicleModel => new CarSalesVehicleModel() { ID = carSalesVehicleModel.ID, VehicleMakeID = carSalesVehicleModel.VehicleMakeID, VehicleModel1 = carSalesVehicleModel.VehicleModel1, } ) .FirstOrDefault(); if (vehicleModel == null) { return(NotFound()); } return(Ok(vehicleModel)); }
public IHttpActionResult PostVehicleModel(CarSalesVehicleModel carSalesVehicleModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } VehicleModel vehicleModel = new VehicleModel() { ID = carSalesVehicleModel.ID, VehicleMakeID = carSalesVehicleModel.VehicleMakeID, VehicleModel1 = carSalesVehicleModel.VehicleModel1 }; db.VehicleModels.Add(vehicleModel); db.SaveChanges(); carSalesVehicleModel.ID = vehicleModel.ID; return(CreatedAtRoute("DefaultApi", new { id = vehicleModel.ID }, carSalesVehicleModel)); }
public IHttpActionResult DeleteVehicleModel(int id) { VehicleModel vehicleModel = db.VehicleModels.Find(id); if (vehicleModel == null) { return(NotFound()); } CarSalesVehicleModel carSalesVehicleModel = new CarSalesVehicleModel() { ID = vehicleModel.ID, VehicleMakeID = vehicleModel.VehicleMakeID, VehicleModel1 = vehicleModel.VehicleModel1 }; db.VehicleModels.Remove(vehicleModel); db.SaveChanges(); return(Ok(vehicleModel)); }
public IHttpActionResult PutVehicleModel(int id, CarSalesVehicleModel carSalesVehicleModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != carSalesVehicleModel.ID) { return(BadRequest()); } VehicleModel vehicleModel = new VehicleModel() { ID = carSalesVehicleModel.ID, VehicleMakeID = carSalesVehicleModel.VehicleMakeID, VehicleModel1 = carSalesVehicleModel.VehicleModel1 }; db.Entry(vehicleModel).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!VehicleModelExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }