public void AddCar(CarRequest request) { if (request.userId == null || request.userId != "Admin") { throw new FaultException("You don't have permission to execute this method"); } try { logic.AddCar(request.inputs.registrationNumber, request.inputs.brand, request.inputs.model, request.inputs.year); } catch (ArgumentException) { throw new FaultException("Invalid request inputs"); } }
static void ExecuteCommand(string command) { try { switch (command) { case "quit": Environment.Exit(0); return; case "clear": Console.Clear(); break; case "addcar": Logic.AddCar( GetStringParameterInput("registration number"), GetStringParameterInput("brand"), GetStringParameterInput("model"), GetIntParameterInput("year")); Console.WriteLine("Added car"); break; case "removecar": Logic.RemoveCar(GetObjectFromListInput(Logic.GetCars(), "car")); Console.WriteLine("Removed car"); break; case "addcustomer": Logic.AddCustomer( GetStringParameterInput("first name"), GetStringParameterInput("last name"), GetStringParameterInput("telephone number"), GetStringParameterInput("email")); Console.WriteLine("Added customer"); break; case "changecustomer": Logic.ChangeCustomer( GetObjectFromListInput(Logic.GetCustomers(), "customer"), new Customer { FirstName = GetStringParameterInput("first name"), LastName = GetStringParameterInput("last name"), TelephoneNumber = GetStringParameterInput("telephone number"), Email = GetStringParameterInput("email") }); Console.WriteLine("Changed customer"); break; case "removecustomer": Logic.RemoveCustomer(GetObjectFromListInput(Logic.GetCustomers(), "customer")); Console.WriteLine("Removed customer"); break; case "getavailablecars": List <Car> cars = Logic.GetAvailableCars( GetDateTimeParameterInput("from date"), GetDateTimeParameterInput("to date")); if (cars.Count == 0) { Console.WriteLine("No available cars"); } else { Console.WriteLine("[AVAILABLE CARS]"); foreach (Car c in cars) { Console.WriteLine(c.ToString()); } } break; case "createbooking": DateTime fromDate = GetDateTimeParameterInput("booking start time"); DateTime toDate = GetDateTimeParameterInput("booking end time"); Logic.CreateBooking( GetObjectFromListInput(Logic.GetAvailableCars(fromDate, toDate), "car"), GetObjectFromListInput(Logic.GetCustomers(), "customer"), fromDate, toDate); Console.WriteLine("Created booking"); break; case "removebooking": Logic.RemoveBooking(GetObjectFromListInput(Logic.GetActiveBookings(false), "booking")); Console.WriteLine("Removed booking"); break; case "returncar": Logic.ReturnCar(GetObjectFromListInput(Logic.GetActiveBookings(true), "booking")); Console.WriteLine("Returned car"); break; default: Console.WriteLine($"There's no current support for command \"{command}\""); break; } } catch (ArgumentException) { Console.WriteLine("Invalid method parameters."); } catch (EmptyListException e) { Console.WriteLine("Failed to execute command. " + e.Message); } }