/// <summary> /// Transforms the base <paramref name="assignments"/> in a Domain friendly manner. /// </summary> /// <param name="context"></param> /// <param name="assignments"></param> /// <returns></returns> private static IEnumerable <(RouteAssignmentItem index, (TVehicle vehicle, TNode node, TNode previousNode) domain)> OnTransformAssignments( TContext context, params RouteAssignmentItem[] assignments) { TNode OnTransformNode(int?node) => context.Nodes.ElementAtOrDefault(node ?? -1); (RouteAssignmentItem index , (TVehicle vehicle, TNode node, TNode previousNode) domain) OnTransformAssignment( RouteAssignmentItem index) => (index, (context.Vehicles.ElementAt(index.Vehicle) , OnTransformNode(index.Node), OnTransformNode(index.PreviousNode) )); foreach (var _ in assignments) { yield return(OnTransformAssignment(_)); } }
public static bool InflateTiresToTheMaxIfExist(string i_LiecenceID) { bool isExist = false; if (IsLicenceIDExistInGarage(i_LiecenceID)) { isExist = true; if (GetIndexOfByLiecenceID(i_LiecenceID) != -1) { foreach (Tire tire in Vehicles.ElementAt(GetIndexOfByLiecenceID(i_LiecenceID)).Tires) { tire.InflateTire(tire.MaxPressure - tire.CurrentPressure); } } } return(isExist); }
public static bool ChargeVehicleIfExist(string i_LiecenceID, float i_AmountToCharge) { bool isExist = false; if (IsLicenceIDExistInGarage(i_LiecenceID)) { isExist = true; if (GetIndexOfByLiecenceID(i_LiecenceID) != -1) { if (Vehicles.ElementAt(GetIndexOfByLiecenceID(i_LiecenceID)).Engine.TypeOfEngine != eTypeOfEngine.ELECTRIC) { throw new FormatException("This is Electric Engine Vehicle"); } GasStation.ChargeBattery(Vehicles.ElementAt(GetIndexOfByLiecenceID(i_LiecenceID)).Engine, i_AmountToCharge); } } return(isExist); }
public static bool FillVehicleWithGasIfExist(string i_LiecenceID, eFuelType i_FuelType, float i_AmountToFill) { bool isExist = false; if (IsLicenceIDExistInGarage(i_LiecenceID)) { isExist = true; if (GetIndexOfByLiecenceID(i_LiecenceID) != -1) { if (Vehicles.ElementAt(GetIndexOfByLiecenceID(i_LiecenceID)).Engine.TypeOfEngine != eTypeOfEngine.FUEL) { throw new FormatException("This is Fuel Engine Vehicle"); } GasStation.FillFuel(Vehicles.ElementAt(GetIndexOfByLiecenceID(i_LiecenceID)).Engine, i_FuelType, i_AmountToFill); } } return(isExist); }
public static string GetAllVehicleDetailIfExist(string i_LiecenceID) { StringBuilder sb = new StringBuilder(); if (IsLicenceIDExistInGarage(i_LiecenceID)) { if (GetIndexOfByLiecenceID(i_LiecenceID) != -1) { sb.AppendLine(" Vehicle Details:"); sb.AppendLine(Vehicles.ElementAt(GetIndexOfByLiecenceID(i_LiecenceID)).ToString()); sb.AppendLine(); sb.AppendLine("Contact details"); sb.AppendLine(); sb.AppendLine(Customers.ElementAt(GetIndexOfByLiecenceID(i_LiecenceID)).ToString()); } else { sb.AppendLine("vehicle with this licence does not exist in the garage."); } } return(sb.ToString()); }
public static void GetFullEnergy(string i_LiecenceID) { GasStation.FillToTheMax(Vehicles.ElementAt(GetIndexOfByLiecenceID(i_LiecenceID)).Engine); }