internal static CustomersMenuOptions GetCustomersMenuOption() { Console.WriteLine(""); Console.WriteLine("*******************************************"); Console.WriteLine("This is your Customers menu."); Console.WriteLine("What do you want to do?"); Console.WriteLine("*******************************************"); Console.WriteLine(""); Console.WriteLine(string.Format("{0:D} - {1}", CustomersMenuOptions.Sales_Customers_CustomerAllInOne, CustomersMenuOptions.Sales_Customers_CustomerAllInOne.ToName())); Console.WriteLine(string.Format("{0:D} - {1}", CustomersMenuOptions.Sales_Customers_PartyAndCustomer, CustomersMenuOptions.Sales_Customers_PartyAndCustomer.ToName())); Console.WriteLine(string.Format("{0:D} - {1}", CustomersMenuOptions.Sales_Customers_GetLastCustomer, CustomersMenuOptions.Sales_Customers_GetLastCustomer.ToName())); Console.WriteLine(string.Format("{0:D} - {1}", CustomersMenuOptions.Sales_Customers_UpdateCityAddress, CustomersMenuOptions.Sales_Customers_UpdateCityAddress.ToName())); Console.WriteLine(string.Format("{0:D} - {1}", CustomersMenuOptions.Sales_Customers_UpdatePaymentTerm, CustomersMenuOptions.Sales_Customers_UpdatePaymentTerm.ToName())); Console.WriteLine(string.Format("{0:D} - {1}", CustomersMenuOptions.Sales_Customers_DeleteCustomer, CustomersMenuOptions.Sales_Customers_DeleteCustomer.ToName())); Console.WriteLine(string.Format("{0:D} - {1}", CustomersMenuOptions.Sales_Customers_AddCustomer, CustomersMenuOptions.Sales_Customers_AddCustomer.ToName())); Console.WriteLine(string.Format("{0:D} - {1}", CustomersMenuOptions.Sales_Customers_DeleteAllParties, CustomersMenuOptions.Sales_Customers_DeleteAllParties.ToName())); Console.WriteLine(""); Console.WriteLine(string.Format("{0:D} - {1}", CustomersMenuOptions.Exit, CustomersMenuOptions.Exit.ToName())); Console.WriteLine(""); Console.WriteLine("*******************************************"); Console.WriteLine(""); Console.WriteLine("Type you option: "); ConsoleKeyInfo userOption = Console.ReadKey(true); CustomersMenuOptions option = CustomersMenuOptions.Exit; int maxOption = option.Max(); int intOption = 0; if (!int.TryParse(userOption.KeyChar.ToString(), out intOption)) { Console.WriteLine(""); Console.WriteLine("Not a valid Input. Back to Main Menu."); intOption = 0; } else { if (intOption == 0) { Console.WriteLine(""); Console.WriteLine("selected option " + string.Format("{0:D} - {1}", option, option.ToName())); } else if (intOption < 0 || intOption > maxOption) { Console.WriteLine(""); Console.WriteLine("Not a valid Input. Back to Main Menu."); intOption = 0; } else { option = (CustomersMenuOptions)intOption; } } return(option); }
private static async Task <int> HandleMainMenuOptionAsync(SessionContext sessionContext, AuthenticationProvider authenticationProvider, MenuOptions option) { Console.WriteLine(""); Console.WriteLine("selected option " + string.Format("{0:D} - {1}", option, option.ToName())); Console.WriteLine(""); // Display Sub Menu according to Menu Selection. switch (option) { case MenuOptions.Sales_Customers: CustomersMenuOptions customersOption = CustomersMenuOptions.Exit; do { customersOption = ConsoleHelper.GetCustomersMenuOption(); if (customersOption != CustomersMenuOptions.Exit) { await HandleCustomersOperationAsync(sessionContext, authenticationProvider, customersOption); } } while (customersOption != CustomersMenuOptions.Exit); break; case MenuOptions.Sales_SalesItems: SalesItemsMenuOptions salesItemsOption = SalesItemsMenuOptions.Exit; do { salesItemsOption = ConsoleHelper.GetSalesItemsMenuOption(); if (salesItemsOption != SalesItemsMenuOptions.Exit) { await HandleSalesItemsOperationAsync(sessionContext, authenticationProvider, salesItemsOption); } } while (salesItemsOption != SalesItemsMenuOptions.Exit); break; case MenuOptions.Sales_SalesOrders: SalesOrdersMenuOptions salesOrdersOption = SalesOrdersMenuOptions.Exit; do { salesOrdersOption = ConsoleHelper.GetSalesOrdersMenuOption(); if (salesOrdersOption != SalesOrdersMenuOptions.Exit) { await HandleSalesOrdersOperationAsync(sessionContext, authenticationProvider, salesOrdersOption); } } while (salesOrdersOption != SalesOrdersMenuOptions.Exit); break; case MenuOptions.Sales_SalesInvoices: SalesInvoicesMenuOptions salesInvoicesOption = SalesInvoicesMenuOptions.Exit; do { salesInvoicesOption = ConsoleHelper.GetSalesInvoicesMenuOption(); if (salesInvoicesOption != SalesInvoicesMenuOptions.Exit) { await HandleSalesInvoicesOperationAsync(sessionContext, authenticationProvider, salesInvoicesOption); } } while (salesInvoicesOption != SalesInvoicesMenuOptions.Exit); break; } return(0); }
private static async Task <int> HandleCustomersOperationAsync(SessionContext sessionContext, AuthenticationProvider authenticationProvider, CustomersMenuOptions option) { Console.WriteLine(""); Console.WriteLine("selected option " + string.Format("{0:D} - {1}", option, option.ToName())); Console.WriteLine(""); // Get the authorization access token CustomersController.AccountKey = sessionContext.AccountKey; CustomersController.SubscriptionKey = sessionContext.SubscriptionKey; CustomersController.CultureKey = sessionContext.CultureKey; CustomersController.AuthenticationProvider = authenticationProvider; switch (option) { case CustomersMenuOptions.Sales_Customers_CustomerAllInOne: sessionContext.PartyKey = await CustomersController.CreateCustomerAndPartyAsync(); break; case CustomersMenuOptions.Sales_Customers_PartyAndCustomer: sessionContext.PartyKey = await CustomersController.CreatePartyAndCustomerExtensionAsync(); break; case CustomersMenuOptions.Sales_Customers_GetLastCustomer: sessionContext.PartyKey = await CustomersController.GetLastCustomerAsync(false); break; case CustomersMenuOptions.Sales_Customers_UpdateCityAddress: if (sessionContext.PartyKey == null) { sessionContext.PartyKey = await CustomersController.GetLastCustomerAsync(true); } if (sessionContext.PartyKey != null) { await CustomersController.UpdateCustomerCityAddressAsync(sessionContext.PartyKey); } else { ConsoleHelper.WriteErrorLine("You must create a customer first."); } break; case CustomersMenuOptions.Sales_Customers_UpdatePaymentTerm: if (sessionContext.PartyKey == null) { sessionContext.PartyKey = await CustomersController.GetLastCustomerAsync(true); } if (sessionContext.PartyKey != null) { await CustomersController.UpdateCustomerPaymentTermAsync(sessionContext.PartyKey); } else { ConsoleHelper.WriteErrorLine("You must create a customer first."); } break; case CustomersMenuOptions.Sales_Customers_DeleteCustomer: if (sessionContext.PartyKey == null) { sessionContext.PartyKey = await CustomersController.GetLastCustomerAsync(true); } if (sessionContext.PartyKey != null) { await CustomersController.DeleteCustomerExtensionAsync(sessionContext.PartyKey); sessionContext.DeletedCustomerKey = sessionContext.PartyKey; sessionContext.PartyKey = null; } else { ConsoleHelper.WriteErrorLine("You must create a customer first."); } break; case CustomersMenuOptions.Sales_Customers_AddCustomer: if (sessionContext.DeletedCustomerKey != null) { await CustomersController.CreateCustomerExtensionAsync(sessionContext.DeletedCustomerKey); sessionContext.PartyKey = sessionContext.DeletedCustomerKey; sessionContext.DeletedCustomerKey = null; } else { ConsoleHelper.WriteErrorLine("You must delete a customer first."); } break; case CustomersMenuOptions.Sales_Customers_DeleteAllParties: await CustomersController.DeleteAllPartiesCreatedOnSample(); break; } return(0); }