public FleetVehicleModel UpdateCarOnFleet(FleetVehicleModel fleet) { FleetVehicle fleetVehicle = DB.FleetVehicles.SingleOrDefault(f => f.Id == fleet.ID); if (fleetVehicle == null) { return(null); } fleetVehicle.Vin = fleet.Vin; fleetVehicle.ModelId = fleet.ModelID; fleetVehicle.Color = fleet.Color; fleetVehicle.PurchaseDate = fleet.PurchaseDate; fleetVehicle.CarYear = fleet.CarYear; fleetVehicle.Mileage = fleet.Mileage; fleetVehicle.CarImg = fleet.CarImg; fleetVehicle.Gearbox = fleet.Gearbox; fleetVehicle.ToUsed = fleet.ToUsed; fleetVehicle.CarFixed = fleet.CarFixed; fleetVehicle.BranchId = fleet.BranchID; DB.SaveChanges(); return(fleet); }
public FleetVehicle GetOneCar(int id) { FleetVehiclesLogic fleetVehiclesLogic = new FleetVehiclesLogic(DB); FleetVehicle fleetVehicle = fleetVehiclesLogic.GetOneCarFromFleet(id).ConvertToCar(); return(fleetVehicle); }
public void UpdateUsed(int id) { FleetVehicle car = DB.FleetVehicles.SingleOrDefault(f => f.Id == id); car.ToUsed = "no"; DB.SaveChanges(); }
public void DeleteCarFromFleet(int id) { FleetVehicle fleetVehicle = DB.FleetVehicles.SingleOrDefault(f => f.Id == id); if (fleetVehicle == null) { return; } DB.FleetVehicles.Remove(fleetVehicle); DB.SaveChanges(); }
public FleetVehicleModel(FleetVehicle fleetVehicle) { ID = fleetVehicle.Id; Vin = fleetVehicle.Vin; ModelID = fleetVehicle.ModelId; Color = fleetVehicle.Color; PurchaseDate = fleetVehicle.PurchaseDate; CarYear = fleetVehicle.CarYear; Mileage = fleetVehicle.Mileage; CarImg = fleetVehicle.CarImg; Gearbox = fleetVehicle.Gearbox; ToUsed = fleetVehicle.ToUsed; CarFixed = fleetVehicle.CarFixed; BranchID = fleetVehicle.BranchId; Branch = fleetVehicle.Branch; CarModel = fleetVehicle.Model; }
public FleetVehicleModel AddCarToFleet(FleetVehicleModel fleetVehicleModel) { string extension = Path.GetExtension(fleetVehicleModel.CarImg); fleetVehicleModel.CarImg = Guid.NewGuid() + extension; using (FileStream fileStream = File.Create("Uploads/" + fleetVehicleModel.CarImg)) { fleetVehicleModel.Image.CopyTo(fileStream); } fleetVehicleModel.Image = null; FleetVehicle fleetVehicle = fleetVehicleModel.ConvertToCar(); DB.FleetVehicles.Add(fleetVehicle); DB.SaveChanges(); fleetVehicleModel.ID = fleetVehicle.Id; return(fleetVehicleModel); }
public FleetVehicle ConvertToCar() { FleetVehicle fleetVehicle = new FleetVehicle { Id = ID, Vin = Vin, ModelId = ModelID, Color = Color, PurchaseDate = PurchaseDate, CarYear = CarYear, Mileage = Mileage, CarImg = CarImg, Gearbox = Gearbox, ToUsed = ToUsed, CarFixed = CarFixed, BranchId = BranchID, Branch = Branch, Model = CarModel }; return(fleetVehicle); }