示例#1
0
        static string GetNormalStringOfTransactions()
        {
            string rez = "";

            TransactionInfoClient[] transactionInfos = ParkingServiceHTTPMethods.GetLastTransactions().Result;
            for (int i = 0; i < transactionInfos.Length; i++)
            {
                rez += $"{transactionInfos[i].TimeTransaction:T} -- {transactionInfos[i].VehicleId}  {transactionInfos[i].Sum}\n";
            }
            return(rez);
        }
示例#2
0
        static void MainMethod()
        {
            string number = Console.ReadLine();

            try
            {
                switch (number)
                {
                case "1":
                    Console.WriteLine($"Current balance is {ParkingServiceHTTPMethods.GetParkingHttp("balance").Result}\n");
                    break;

                case "2":
                    Console.WriteLine($"The capacity of the parking is {ParkingServiceHTTPMethods.GetParkingHttp("capacity").Result}\n");
                    break;

                case "3":
                    Console.WriteLine($"Amount free place of parking is {ParkingServiceHTTPMethods.GetParkingHttp("freePlaces").Result}");
                    break;

                case "4":
                    Console.WriteLine($"The history of transactions for current period is {GetNormalStringOfTransactions()}");
                    break;

                case "5":
                    ReadOnlyCollection <VehicleClient> clients = new ReadOnlyCollection <VehicleClient>(ParkingServiceHTTPMethods.GetVehicles().Result);
                    for (int i = 0; i < clients.Count; i++)
                    {
                        Console.Write(clients[i].Id + " with balance " + clients[i].Balance + "\n");
                    }
                    break;

                case "6":
                    Console.WriteLine("Enter transport id, type" +
                                      "(1 - Bus, 2 - PassengerCar, 3 - Truck and 4 - Motorcycle) and how much money you give");
                    string        id      = Console.ReadLine();
                    int           type    = Convert.ToInt32(Console.ReadLine());
                    decimal       money   = Convert.ToDecimal(Console.ReadLine());
                    VehicleClient vehicle = new VehicleClient(id, type, money);
                    string        rez     = ParkingServiceHTTPMethods.AddVehicle(vehicle).Result;
                    Console.WriteLine($"{rez}\n");
                    break;

                case "7":
                    Console.WriteLine("Enter the id of transport you want to remove:");
                    string idRemove = Console.ReadLine();
                    string rezRev   = ParkingServiceHTTPMethods.RemoveVehicle(idRemove).Result;
                    Console.WriteLine(rezRev + "\n");
                    break;

                case "8":
                    Console.WriteLine("Enter sum and id of transport:");
                    decimal       sum      = Convert.ToDecimal(Console.ReadLine());
                    string        ids      = Console.ReadLine();
                    VehicleClient rezTopUp = ParkingServiceHTTPMethods.TopUpVehicle(ids, sum).Result;
                    Console.WriteLine($"Now {rezTopUp.Id} is staying on parking with balance {rezTopUp.Balance}\n");
                    break;

                case "9":
                    Console.WriteLine("Enter the id of transport:");
                    string        IdTr   = Console.ReadLine();
                    VehicleClient rezGet = ParkingServiceHTTPMethods.GetVehicleById(IdTr).Result;
                    Console.WriteLine($"Vehicle with id {rezGet.Id} with balance {rezGet.Balance} is staying now on the parking\n");
                    break;

                case "10":
                    Console.WriteLine(ParkingServiceHTTPMethods.GetAllTransactions().Result);
                    break;

                case "11":
                    Console.Clear();
                    break;

                case "12":
                    Environment.Exit(0);
                    break;

                default:
                    Console.WriteLine("Entered incorrect number, try again");
                    break;
                }
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine($"Mistake:{ex.Message}");
            }

            catch (InvalidOperationException ex)
            {
                Console.WriteLine($"Mistake:{ex.Message}");
            }
            catch (FormatException ex)
            {
                Console.WriteLine($"Mistake:{ex.Message}");
            }
            catch (AggregateException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Mistake:{ex.Message}");
            }
            finally
            {
                DisplayMainMessage();
                MainMethod();
            }
        }