public void Put(int id, [FromBody] Vehicle vehicle) { using (var context = new RentARideContext( serviceProvider.GetRequiredService < DbContextOptions <RentARideContext> >()) ) { var outputParamUpdate = new SqlParameter("@outputMessage", System.Data.SqlDbType.Bit) { Direction = System.Data.ParameterDirection.Output }; var vehicleId = context.Database.ExecuteSqlCommand("Exec dbo.updateVehicle @rarVehicleID, @VIN, @make, @model, @modelYear, @purchaseDate, @purchasePrice, @salePrice, @vehicleType, @fleetStatus, @outputMessage OUT", new SqlParameter("@rarVehicleID", id), new SqlParameter("@VIN", vehicle.VIN), new SqlParameter("@make", vehicle.Make), new SqlParameter("@model", vehicle.Model), new SqlParameter("@modelYear", vehicle.ModelYear), new SqlParameter("@purchaseDate", vehicle.PurchaseDate), new SqlParameter("@purchasePrice", vehicle.PurchasePrice), new SqlParameter("@salePrice", vehicle.salePrice), new SqlParameter("@vehicleType", vehicle.VehicleType), new SqlParameter("@fleetStatus", vehicle.FleetStatus), outputParamUpdate); Console.WriteLine(outputParamUpdate.Value); } }
public ActionResult <string> Get() { using (var context = new RentARideContext( serviceProvider.GetRequiredService < DbContextOptions <RentARideContext> >()) ) { SqlParameter returnParam = new SqlParameter(); returnParam.Direction = System.Data.ParameterDirection.ReturnValue; var outputParamUpdate = new SqlParameter("@JSON", System.Data.SqlDbType.VarChar, 100000) { Direction = System.Data.ParameterDirection.Output }; string VehicleList = context.Database.ExecuteSqlCommand("Exec dbo.listVehicles @JSON OUT", outputParamUpdate, returnParam).ToString(); return(outputParamUpdate.Value.ToString()); } /* * List<Vehicle> VehicleList = new List<Vehicle> * { * * //new Vehicle("Toyota","Yaris",2010,7500.00m), * new Vehicle{ * Make = "Toyota", * Model = "4Runner", * ModelYear = 2010, * PurchasePrice = 7500.00m}, * new Vehicle{ * Make = "Nissan", * Model = "XTerra", * ModelYear = 2010, * PurchasePrice = 10000.00m }, * new Vehicle{ * Make = "Tesla", * Model = "Model S", * ModelYear = 2019, * PurchasePrice = 20000.00m }, * new Vehicle{ * Make = "Toyota", * Model = "4Runner", * ModelYear = 2010, * PurchasePrice = 7500.00m}, * new Vehicle{ * Make = "Nissan", * Model = "XTerra", * ModelYear = 2010, * PurchasePrice = 10000.00m }, * new Vehicle{ * Make = "Tesla", * Model = "Model S", * ModelYear = 2019, * PurchasePrice = 20000.00m }, * * }; */ }
public void Delete(int id) { using (var context = new RentARideContext( serviceProvider.GetRequiredService < DbContextOptions <RentARideContext> >()) ) { var outputParam = new SqlParameter("@outputMessage", System.Data.SqlDbType.Bit) { Direction = System.Data.ParameterDirection.Output }; var vehicleId = context.Database.ExecuteSqlCommand("Exec dbo.deleteVehicle @rarVehicleID, @outputMessage OUT", new SqlParameter("@rarVehicleID", id), outputParam); Console.WriteLine(outputParam.Value); } }
public ActionResult <string> Get() { using (var context = new RentARideContext( serviceProvider.GetRequiredService < DbContextOptions <RentARideContext> >()) ) { SqlParameter returnParam = new SqlParameter(); returnParam.Direction = System.Data.ParameterDirection.ReturnValue; // location pickup time drop time var outputParamUpdate = new SqlParameter("@JSON", System.Data.SqlDbType.VarChar, 100000) { Direction = System.Data.ParameterDirection.Output }; string ReservationList = context.Database.ExecuteSqlCommand("Exec dbo.listReservations @JSON OUT", outputParamUpdate, returnParam).ToString(); return(outputParamUpdate.Value.ToString()); } }
// explicitly declares the name of the route // would be .../vehicle/addvehicle instead of .../vehicle // [Route("AddVehicle")] public void Post([FromBody] Vehicle vehicle) { using (var context = new RentARideContext( serviceProvider.GetRequiredService < DbContextOptions <RentARideContext> >()) ) { var outputParam = new SqlParameter("@VehicleID", vehicle.rarVehicleID) { Direction = System.Data.ParameterDirection.Output }; var vehicleId = context.Database.ExecuteSqlCommand("Exec dbo.AddVehicle @VIN, @Make, @Model, @ModelYear, @PurchasePrice, @VehicleType, @VehicleID OUT", new SqlParameter("@VIN", vehicle.VIN), new SqlParameter("@Make", vehicle.Make), new SqlParameter("@Model", vehicle.Model), new SqlParameter("@ModelYear", vehicle.ModelYear), new SqlParameter("@PurchasePrice", vehicle.PurchasePrice), new SqlParameter("@VehicleType", vehicle.VehicleType), outputParam); // Logs the ID of the newly created vehicle Console.WriteLine(outputParam.Value); } }