Esempio n. 1
0
        public void Start()
        {
            DisplayAll();
            string Command      = ConsoleUtil.GetCommands();
            bool   quit         = false;
            bool   update       = false;
            string updateSelect = "";
            bool   verifyID     = true;
            bool   verifyStat   = true;

            while (!quit)
            {
                CommandValidate(command);
                if (CommandValidate(command) == false)
                {
                    ConsoleUtil.BadAction();
                }


                switch (command)
                {
                case "Add":
                    update = true;
                    string newDesc = ConsoleUtil.GetDescription(update);
                    ItemRepository.AddItem(newDesc);
                    DisplayAll();
                    break;

                case "Delete":
                    do
                    {
                        int delItemID = ConsoleUtil.GetItemID(command);
                        verifyID = Itemrepo.ItemIDVerify(delItemID);
                        if (verifyID == false)
                        {
                            DisplayAll();
                            ConsoleUtil.BadID();
                        }
                        else
                        {
                            Itemrepo.DeleteItem(delItemID);
                            DisplayAll();
                        }
                    } while (!verifyID);
                    DisplayAll();
                    break;

                case "Update":
                    do
                    {
                        update = true;

                        int itemID = ConsoleUtil.GetItemID(command);

                        verifyID = Itemrepo.ItemIDVerify(itemID);
                        if (verifyID == false)
                        {
                            ConsoleUtil.BadID();
                        }
                        else
                        {
                            updateSelect = ConsoleUtil.UpdateSelect(itemID);

                            if (updateSelect == "description")
                            {
                                bool statUpdate = false;

                                newDesc = ConsoleUtil.GetDescription(update);

                                string newStat = ConsoleUtil.GetStatus(statUpdate);

                                Itemrepo.UpdateItem(itemID, newDesc, newStat);
                            }
                            else if (updateSelect == "status")
                            {
                                do
                                {
                                    bool descUpdate = false;

                                    string newStat = ConsoleUtil.GetStatus(update);

                                    verifyStat = StatusValidate(newStat);
                                    if (verifyStat == false)
                                    {
                                        ConsoleUtil.BadStatus();
                                    }
                                    else
                                    {
                                        newDesc = ConsoleUtil.GetDescription(descUpdate);
                                        Itemrepo.UpdateItem(itemID, newDesc, newStat);
                                    }
                                } while (verifyStat == false);
                            }
                            else
                            {
                                ConsoleUtil.BadAction();
                                verifyID = false;
                            }
                        }
                    } while (!verifyID);

                    DisplayAll();
                    break;

                case "Filter":
                    DisplayFilter();
                    break;

                case "Quit":
                    Itemrepo.QuitProtocol();
                    quit = true;
                    break;
                }
                if (quit == true)
                {
                    ConsoleUtil.QuitMessage();
                }
                else
                {
                    command = ConsoleUtil.GetCommands();
                }
            }
        }