private static async Task <int> HandleSalesOrdersOperationAsync(SessionContext sessionContext, AuthenticationProvider authenticationProvider, SalesOrdersMenuOptions option) { Console.WriteLine(""); Console.WriteLine("selected option " + string.Format("{0:D} - {1}", option, option.ToName())); Console.WriteLine(""); // Get the authorization access token SalesOrdersController.AccountKey = sessionContext.AccountKey; SalesOrdersController.SubscriptionKey = sessionContext.SubscriptionKey; SalesOrdersController.CompanyKey = sessionContext.CompanyKey; SalesOrdersController.CultureKey = sessionContext.CultureKey; SalesOrdersController.AuthenticationProvider = authenticationProvider; switch (option) { case SalesOrdersMenuOptions.Sales_Orders_GetAll: await SalesOrdersController.GetOrdersAsync(); break; case SalesOrdersMenuOptions.Sales_Orders_GetOdata: await SalesOrdersController.GetTop5OrdersAsync(); break; case SalesOrdersMenuOptions.Sales_Orders_GetLastOrder: sessionContext.OrderResource = await SalesOrdersController.GetLastOrderAsync(false); break; case SalesOrdersMenuOptions.Sales_Orders_Create: await SalesOrdersController.CreateOrderAsync(); /// Just to update sessionContext.OrderResource = await SalesOrdersController.GetLastOrderAsync(true); break; case SalesOrdersMenuOptions.Sales_Orders_InsertLine: if (sessionContext.OrderResource == null) { sessionContext.OrderResource = await SalesOrdersController.GetLastOrderAsync(true); } if (sessionContext.OrderResource != null) { await SalesOrdersController.InsertLineOnOrderAsync(sessionContext.OrderResource); sessionContext.OrderResource = await SalesOrdersController.GetLastOrderAsync(true); } else { ConsoleHelper.WriteErrorLine("You must create an order first."); } break; case SalesOrdersMenuOptions.Sales_Orders_UpdateQtd: if (sessionContext.OrderResource == null) { sessionContext.OrderResource = await SalesOrdersController.GetLastOrderAsync(true); } if (sessionContext.OrderResource != null) { await SalesOrdersController.SetQuantityOnOrderLastLineAsync(sessionContext.OrderResource); sessionContext.OrderResource = await SalesOrdersController.GetLastOrderAsync(true); } else { ConsoleHelper.WriteErrorLine("You must create an order first."); } break; case SalesOrdersMenuOptions.Sales_Orders_DelLastLine: if (sessionContext.OrderResource == null) { sessionContext.OrderResource = await SalesOrdersController.GetLastOrderAsync(true); } if (sessionContext.OrderResource != null) { await SalesOrdersController.DeleteLastLineOnOrderAsync(sessionContext.OrderResource); sessionContext.OrderResource = await SalesOrdersController.GetLastOrderAsync(true); } else { ConsoleHelper.WriteErrorLine("You must create an order first."); } break; case SalesOrdersMenuOptions.Sales_Orders_Del: if (sessionContext.OrderResource == null) { sessionContext.OrderResource = await SalesOrdersController.GetLastOrderAsync(true); } if (sessionContext.OrderResource != null) { await SalesOrdersController.DeleteOrderAsync(sessionContext.OrderResource); sessionContext.OrderResource = null; } else { ConsoleHelper.WriteErrorLine("You must create an order first."); } break; } return(0); }
internal static SalesOrdersMenuOptions GetSalesOrdersMenuOption() { Console.WriteLine(""); Console.WriteLine("*******************************************"); Console.WriteLine("This is your Sales Orders menu."); Console.WriteLine("What do you want to do?"); Console.WriteLine("*******************************************"); Console.WriteLine(""); Console.WriteLine(string.Format("{0:D} - {1}", SalesOrdersMenuOptions.Sales_Orders_GetAll, SalesOrdersMenuOptions.Sales_Orders_GetAll.ToName())); Console.WriteLine(string.Format("{0:D} - {1}", SalesOrdersMenuOptions.Sales_Orders_GetOdata, SalesOrdersMenuOptions.Sales_Orders_GetOdata.ToName())); Console.WriteLine(string.Format("{0:D} - {1}", SalesOrdersMenuOptions.Sales_Orders_Create, SalesOrdersMenuOptions.Sales_Orders_Create.ToName())); Console.WriteLine(string.Format("{0:D} - {1}", SalesOrdersMenuOptions.Sales_Orders_GetLastOrder, SalesOrdersMenuOptions.Sales_Orders_GetLastOrder.ToName())); Console.WriteLine(string.Format("{0:D} - {1}", SalesOrdersMenuOptions.Sales_Orders_InsertLine, SalesOrdersMenuOptions.Sales_Orders_InsertLine.ToName())); Console.WriteLine(string.Format("{0:D} - {1}", SalesOrdersMenuOptions.Sales_Orders_UpdateQtd, SalesOrdersMenuOptions.Sales_Orders_UpdateQtd.ToName())); Console.WriteLine(string.Format("{0:D} - {1}", SalesOrdersMenuOptions.Sales_Orders_DelLastLine, SalesOrdersMenuOptions.Sales_Orders_DelLastLine.ToName())); Console.WriteLine(string.Format("{0:D} - {1}", SalesOrdersMenuOptions.Sales_Orders_Del, SalesOrdersMenuOptions.Sales_Orders_Del.ToName())); Console.WriteLine(""); Console.WriteLine(string.Format("{0:D} - {1}", SalesOrdersMenuOptions.Exit, SalesOrdersMenuOptions.Exit.ToName())); Console.WriteLine(""); Console.WriteLine("*******************************************"); Console.WriteLine(""); Console.WriteLine("Type you option: "); ConsoleKeyInfo userOption = Console.ReadKey(true); SalesOrdersMenuOptions option = SalesOrdersMenuOptions.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 = (SalesOrdersMenuOptions)intOption; } } return(option); }