/// <summary> /// Update the record. /// </summary> public static int Update(VehicleHistory vehicleHistory, Database pDb = null) { Database db; if (pDb == null) { db = new Database(); db.Connect(); } else { db = (Database)pDb; } SqlCommand command = db.CreateCommand(SQL_UPDATE); PrepareCommand(command, vehicleHistory); int ret = db.ExecuteNonQuery(command); if (pDb == null) { db.Close(); } return(ret); }
/// <summary> /// Select the record. /// </summary> /// <param name="id">user id</param> public static VehicleHistory Select(int id, Database pDb = null) { Database db; if (pDb == null) { db = new Database(); db.Connect(); } else { db = (Database)pDb; } SqlCommand command = db.CreateCommand(SQL_SELECT_ID); command.Parameters.AddWithValue("@id", id); SqlDataReader reader = db.Select(command); Collection <VehicleHistory> VehicleHistories = Read(reader); VehicleHistory VehicleHistory = null; if (VehicleHistories.Count == 1) { VehicleHistory = VehicleHistories[0]; } reader.Close(); if (pDb == null) { db.Close(); } return(VehicleHistory); }
public bool CreateVehicleHistory(VehicleHistoryCreate model) { var entity = new VehicleHistory() { VehicleHistoryOwnerId = _vehicleHistoryUserId, VehicleHistoryId = model.VehicleHistoryId, FirstName = model.FirstName, LastName = model.LastName, VehicleMake = model.VehicleMake, VehicleModel = model.VehicleModel, VehicleYear = model.VehicleYear, LicenseNo = model.LicenseNo, VinNo = model.VinNo, ServiceDate = model.ServiceDate, OdometerMileage = model.OdometerMileage, ServiceOne = model.ServiceOne, ServiceTwo = model.ServiceTwo, ServiceThree = model.ServiceThree, ServiceFour = model.ServiceFour, ServiceFive = model.ServiceFive, ServiceOneCost = model.ServiceOneCost, ServiceTwoCost = model.ServiceTwoCost, ServiceThreeCost = model.ServiceThreeCost, ServiceFourCost = model.ServiceFourCost, ServiceFiveCost = model.ServiceFiveCost }; using (var ctx = new ApplicationDbContext()) { ctx.VehicleHistorys.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Delete(int id) { VehicleHistory vehicleHistory = _db.VehicleHistorys.Find(id); _db.VehicleHistorys.Remove(vehicleHistory); _db.SaveChanges(); return(RedirectToAction("Index")); }
/// <summary> /// Prepare a command. /// </summary> private static void PrepareCommand(SqlCommand command, VehicleHistory VehicleHistory) { command.Parameters.AddWithValue("@id", VehicleHistory.Id); command.Parameters.AddWithValue("@evidence_id", VehicleHistory.EvidenceId); command.Parameters.AddWithValue("@start_date", VehicleHistory.StartDate); command.Parameters.AddWithValue("@end_date", VehicleHistory.EndDate); command.Parameters.AddWithValue("@car_license_plate", VehicleHistory.CarLicensePlate); command.Parameters.AddWithValue("@podtyp", VehicleHistory.Podtyp); }
public ActionResult Edit(VehicleHistory vehicleHistory) { if (ModelState.IsValid) { _db.Entry(vehicleHistory).State = EntityState.Modified; _db.SaveChanges(); return(RedirectToAction("Index")); } return(View(vehicleHistory)); }
public void deleteFuelPurchasesTest() { CarList car = new CarList(); // this is just a sample data double FuelQuantity = double.Parse("30"); double FuelPrice = double.Parse("1.5"); FuelPurchase fuelPurchase = new FuelPurchase(FuelQuantity, FuelPrice); fuelPurchase.VId = Guid.NewGuid(); CarList.fuelPurchases.Add(fuelPurchase); // it will return true if its deleted Assert.IsTrue(VehicleHistory.deleteFuelPurchases(fuelPurchase)); }
public void deleteServiceTest() { CarList car = new CarList(); Service service = new Service(); // this is just a sample data service.vehicleID = Guid.NewGuid(); service.ServiceOdometer = int.Parse("100"); service.ServiceDate = DateTime.Now; // add to service list CarList.services.Add(service); // this is to check if its deleted or not // it will return true if it does Assert.IsTrue(VehicleHistory.deleteService(service)); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } VehicleHistory vehicleHistory = _db.VehicleHistorys.Find(id); if (vehicleHistory == null) { return(HttpNotFound()); } return(View(vehicleHistory)); }
private static Collection <VehicleHistory> Read(SqlDataReader reader) { Collection <VehicleHistory> vehicleHistories = new Collection <VehicleHistory>(); while (reader.Read()) { int i = -1; VehicleHistory vehicleHistory = new VehicleHistory(); vehicleHistory.Id = reader.GetInt32(++i); vehicleHistory.EvidenceId = reader.GetString(++i); vehicleHistory.StartDate = reader.GetDateTime(++i); vehicleHistory.StartDate = reader.GetDateTime(++i); vehicleHistory.CarLicensePlate = !reader.IsDBNull(++i)?reader.GetString(i):""; vehicleHistory.vehicle = VehicleTable.Select(reader.GetInt32(++i)); vehicleHistory.city = CityTable.Select(reader.GetInt32(++i)); vehicleHistory.depot = DepotTable.Select(reader.GetInt32(++i)); vehicleHistory.Podtyp = reader.GetString(++i); vehicleHistories.Add(vehicleHistory); } return(vehicleHistories); }