Пример #1
0
        internal static SalesItemsMenuOptions GetSalesItemsMenuOption()
        {
            Console.WriteLine("");
            Console.WriteLine("*******************************************");
            Console.WriteLine("This is your Sales Items menu.");
            Console.WriteLine("What do you want to do?");
            Console.WriteLine("*******************************************");
            Console.WriteLine("");
            Console.WriteLine(string.Format("{0:D} - {1}", SalesItemsMenuOptions.Sales_SalesItems_SalesItemAllInOne, SalesItemsMenuOptions.Sales_SalesItems_SalesItemAllInOne.ToName()));
            Console.WriteLine(string.Format("{0:D} - {1}", SalesItemsMenuOptions.Sales_SalesItems_ItemAndSalesItem, SalesItemsMenuOptions.Sales_SalesItems_ItemAndSalesItem.ToName()));
            Console.WriteLine(string.Format("{0:D} - {1}", SalesItemsMenuOptions.Sales_SalesItems_GetLastSalesItem, SalesItemsMenuOptions.Sales_SalesItems_GetLastSalesItem.ToName()));
            Console.WriteLine(string.Format("{0:D} - {1}", SalesItemsMenuOptions.Sales_SalesItems_SetPrices, SalesItemsMenuOptions.Sales_SalesItems_SetPrices.ToName()));
            Console.WriteLine(string.Format("{0:D} - {1}", SalesItemsMenuOptions.Sales_SalesItems_UpdatePrice, SalesItemsMenuOptions.Sales_SalesItems_UpdatePrice.ToName()));
            Console.WriteLine(string.Format("{0:D} - {1}", SalesItemsMenuOptions.Sales_SalesItems_DeleteSalesItem, SalesItemsMenuOptions.Sales_SalesItems_DeleteSalesItem.ToName()));
            Console.WriteLine(string.Format("{0:D} - {1}", SalesItemsMenuOptions.Sales_SalesItems_AddSalesItem, SalesItemsMenuOptions.Sales_SalesItems_AddSalesItem.ToName()));
            Console.WriteLine(string.Format("{0:D} - {1}", SalesItemsMenuOptions.Sales_SalesItems_DeleteAllItems, SalesItemsMenuOptions.Sales_SalesItems_DeleteAllItems.ToName()));
            Console.WriteLine("");
            Console.WriteLine(string.Format("{0:D} - {1}", SalesItemsMenuOptions.Exit, SalesItemsMenuOptions.Exit.ToName()));
            Console.WriteLine("");
            Console.WriteLine("*******************************************");
            Console.WriteLine("");
            Console.WriteLine("Type you option: ");

            ConsoleKeyInfo userOption = Console.ReadKey(true);

            SalesItemsMenuOptions option = SalesItemsMenuOptions.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 = (SalesItemsMenuOptions)intOption;
                }
            }

            return(option);
        }
Пример #2
0
        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);
        }
Пример #3
0
        private static async Task <int> HandleSalesItemsOperationAsync(SessionContext sessionContext, AuthenticationProvider authenticationProvider, SalesItemsMenuOptions option)
        {
            Console.WriteLine("");
            Console.WriteLine("selected option " + string.Format("{0:D} - {1}", option, option.ToName()));
            Console.WriteLine("");

            // Get the authorization access token

            SalesItemsController.AccountKey             = sessionContext.AccountKey;
            SalesItemsController.SubscriptionKey        = sessionContext.SubscriptionKey;
            SalesItemsController.CultureKey             = sessionContext.CultureKey;
            SalesItemsController.AuthenticationProvider = authenticationProvider;

            switch (option)
            {
            case SalesItemsMenuOptions.Sales_SalesItems_SalesItemAllInOne:
                sessionContext.ItemKey = await SalesItemsController.CreateSalesItemAndItemAsync();

                break;

            case SalesItemsMenuOptions.Sales_SalesItems_ItemAndSalesItem:
                sessionContext.ItemKey = await SalesItemsController.CreateItemAndSalesItemExtensionAsync();

                break;

            case SalesItemsMenuOptions.Sales_SalesItems_GetLastSalesItem:
                sessionContext.ItemKey = await SalesItemsController.GetLastCreatedSalesItemAsync(false);

                break;

            case SalesItemsMenuOptions.Sales_SalesItems_SetPrices:
                if (sessionContext.ItemKey == null)
                {
                    sessionContext.ItemKey = await SalesItemsController.GetLastCreatedSalesItemAsync(true);
                }

                if (sessionContext.ItemKey != null)
                {
                    await SalesItemsController.InsertPriceOnSalesItemAsync(sessionContext.ItemKey);
                }
                else
                {
                    ConsoleHelper.WriteErrorLine("You must create a salesItem first.");
                }

                break;

            case SalesItemsMenuOptions.Sales_SalesItems_UpdatePrice:
                if (sessionContext.ItemKey == null)
                {
                    sessionContext.ItemKey = await SalesItemsController.GetLastCreatedSalesItemAsync(true);
                }

                if (sessionContext.ItemKey != null)
                {
                    await SalesItemsController.SetNewPriceAsync(sessionContext.ItemKey);
                }
                else
                {
                    ConsoleHelper.WriteErrorLine("You must create a salesItem first.");
                }
                break;

            case SalesItemsMenuOptions.Sales_SalesItems_DeleteSalesItem:
                if (sessionContext.ItemKey == null)
                {
                    sessionContext.ItemKey = await SalesItemsController.GetLastCreatedSalesItemAsync(true);
                }

                if (sessionContext.ItemKey != null)
                {
                    await SalesItemsController.DeleteSalesItemExtensionAsync(sessionContext.ItemKey);

                    sessionContext.DeletedItemKey = sessionContext.ItemKey;
                    sessionContext.ItemKey        = null;
                }
                else
                {
                    ConsoleHelper.WriteErrorLine("You must create a SalesItem first.");
                }

                break;

            case SalesItemsMenuOptions.Sales_SalesItems_AddSalesItem:
                if (sessionContext.DeletedItemKey != null)
                {
                    await SalesItemsController.CreateSalesItemExtensionAsync(sessionContext.DeletedItemKey);

                    sessionContext.ItemKey        = sessionContext.DeletedItemKey;
                    sessionContext.DeletedItemKey = null;
                }
                else
                {
                    ConsoleHelper.WriteErrorLine("You must delete a sales item first.");
                }

                break;

            case SalesItemsMenuOptions.Sales_SalesItems_DeleteAllItems:
                await SalesItemsController.DeleteAllItemsCreatedOnSample();

                break;
            }

            return(0);
        }