private void AddVehicle() { string name; string maxSpeed; string startSpeed; string message = ""; _view.GetData(out name, out startSpeed, out maxSpeed); if (_verificatinService.VerificationDataForElectricVehicle(name, maxSpeed, startSpeed, ref message)) { ElectricVehicle motorVehicle = _creator.Creator(name, Double.Parse(startSpeed), Double.Parse(maxSpeed)); Vehicle vehicle = motorVehicle; if (!_transportService.AddVehicle(vehicle, ref message)) { _view.ShowMessage(message); } else { _view.Close(); } } else { _view.ShowMessage(message); } }
private float getAmountOfEnergyToAdd(ElectricVehicle i_vehicle, ref eExitOrCont io_ExitOrCont) { float amountOfEnergyToFill, maxAmountToAdd; bool isValid; string amountOfEnergyToFillStr; Console.WriteLine("Please enter amount of energy to charge, or press -1 to go back to the main menu"); amountOfEnergyToFillStr = Console.ReadLine(); putExitIfMinus1(amountOfEnergyToFillStr, ref io_ExitOrCont); isValid = float.TryParse(amountOfEnergyToFillStr, out amountOfEnergyToFill); while ((!m_Garage.CheckValidEnergyToAdd(i_vehicle, amountOfEnergyToFill, out maxAmountToAdd) || !isValid) && (io_ExitOrCont != eExitOrCont.Exit)) { if (!isValid) { Console.WriteLine("Please enter a float number, max float to add is " + maxAmountToAdd); amountOfEnergyToFillStr = Console.ReadLine(); isValid = float.TryParse(amountOfEnergyToFillStr, out amountOfEnergyToFill); } else { Console.WriteLine("Please enter a valid eneregy amount to add, min amount is 0 ,max amount possible is " + maxAmountToAdd); amountOfEnergyToFillStr = Console.ReadLine(); isValid = float.TryParse(amountOfEnergyToFillStr, out amountOfEnergyToFill); } putExitIfMinus1(amountOfEnergyToFillStr, ref io_ExitOrCont); } return(amountOfEnergyToFill); }
public async Task <ActionResult <Battery> > PostBatteries(ElectricVehicle evs) { Guid g = Guid.NewGuid(); evs.ElectricVehicleId = g.ToString(); _context.ElectricVehicles.Add(evs); await _context.SaveChangesAsync(); return(CreatedAtAction("GetElectricVehicle", new { id = evs.ElectricVehicleId }, evs)); }
public void ChargingAnElectricVehicle() { int index = 0; string licenseNumber = GetLicenseNumber(ref index); string input; bool isLegalNumber = false; bool isLegalCharge = false; ElectricVehicle compare = null; float minutsInput; if (m_Garage.m_VehicleList[index] is FuelVehicle) { throw new IncompatibleEnergyType(); } compare = m_Garage.m_VehicleList[index] as ElectricVehicle; string msg = string.Format( @"Currently loaded in a battery {0} hours out of a maximum of {1} hours. How many minutes would you like to charge? (in minuts)", compare.RemainingBattery, compare.MaxBattery); Console.WriteLine(msg); do { input = Console.ReadLine(); isLegalNumber = float.TryParse(input, out minutsInput); if (isLegalNumber) { if ((compare.RemainingBattery + (minutsInput / k_MinutsInHour)) <= compare.MaxBattery) { if (minutsInput >= k_Zero) { compare.RemainingBattery += minutsInput / k_MinutsInHour; compare.UpdateEnergyPercentage(); isLegalCharge = true; } } else { throw new ValueOutOfRangeException(0, compare.MaxBattery - compare.RemainingBattery); } } if (!isLegalNumber || !isLegalCharge) { WrongInput(); } }while (!isLegalNumber || !isLegalCharge); }
private static void reCharge(string i_LicencePlate) { float ValidBatteryHours; int indexOfVehicleInGarage; if ((indexOfVehicleInGarage = s_MyGarage.CheckIfVehicleInGarage(i_LicencePlate)) == s_MyGarage.VehicleNotInGarage) { notRegisteredVehiclesMessages(); } else { if (s_MyGarage.VehiclesInGarage[indexOfVehicleInGarage] is FuelVehicle) { throw new ArgumentException("NOT an Electric vehicle"); } ElectricVehicle electricVehicle = s_MyGarage.VehiclesInGarage[indexOfVehicleInGarage] as ElectricVehicle; if (electricVehicle.BatteryHourCapacity.Equals(electricVehicle.BatteryLeft)) { Console.WriteLine(MessagesEnglish.k_BatteryFullyChargedMessage); Console.WriteLine(MessagesEnglish.k_GoingBackToMainMenuMessage); Thread.Sleep(1500); } else { ValidBatteryHours = enterEnergyToFill(MessagesEnglish.k_BatteryToChargeMessage); try { s_MyGarage.Recharge(i_LicencePlate, ValidBatteryHours); Console.WriteLine(MessagesEnglish.k_VehicleRechargedMessage); Console.WriteLine(MessagesEnglish.k_GoingBackToMainMenuMessage); Thread.Sleep(1000); } catch (ValueOutOfRangeException vore) { Console.WriteLine(vore.Message); Thread.Sleep(3000); Ex02.ConsoleUtils.Screen.Clear(); reCharge(i_LicencePlate); } catch (ArgumentException ae) { Console.WriteLine(ae.Message + Environment.NewLine + MessagesEnglish.k_GoingBackToMainMenuMessage); Thread.Sleep(1000); } } } Thread.Sleep(1000); Ex02.ConsoleUtils.Screen.Clear(); }
/// <summary> /// Retrieves all vehicles associated to the user /// </summary> /// TODO: C'Tor needs to take a VIN/Identifier of some type to allow which car to pick from the list. For now we will take the primary private void GetVehicles() { RestRequest getVehiclesRequest = new RestRequest($"users/{_userInfo.UserId}/vehicles?primaryOnly=false", Method.GET, DataFormat.Json); IRestResponse response = _vehicleClient.Execute(getVehiclesRequest); if (!response.IsSuccessful) { throw new InvalidOperationException("Error retrieving associated vehicles"); } DummyVehicleCollection vehicleData = JsonConvert.DeserializeObject <DummyVehicleCollection>(response.Content); _vehicles = new VehicleCollection(); // Create specific vehicle classes depending on the fuel type foreach (DummyVehicle vehicle in vehicleData.vehicles) { vehicle.SetVehicleRequestClient(_vehicleClient, this); vehicle.AutoRefreshTokens = AutoRefreshTokens; // Grab attributes so we can answer the information below vehicle.GetVehicleAttributes(); Vehicle specificVehicle = null; if (vehicle.FuelType == VehicleFuelType.Gasoline) { specificVehicle = new GasVehicle(vehicle); } else if (vehicle.FuelType == VehicleFuelType.Ev) { specificVehicle = new ElectricVehicle(vehicle); } if (specificVehicle == null) { throw new Exception($"Unidentified vehicle fuel type"); } Trace.TraceInformation($"Processing vehicle model \"{vehicle.Model}\""); specificVehicle.SetVehicleRequestClient(_vehicleClient, this); specificVehicle.GetVehicleStatusReport(); specificVehicle.GetVehicleAttributes(); _vehicles.Vehicles.Add(specificVehicle); } }
public async Task <IActionResult> PutElectricVehicle(ElectricVehicle batteries) { _context.Entry(batteries).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EVExists(batteries.ElectricVehicleId)) { return(NotFound()); } else { throw; } } return(NoContent()); }
void FillUp(ElectricVehicle c) { c.FillUpEnergy(...); }
public void ChargeBattery(ElectricVehicle i_Ev, float i_HoursToCharge) { RemainingBatteryTime = AddEnergy(i_Ev, r_MaximalBatteryTime, RemainingBatteryTime, i_HoursToCharge); }