Пример #1
0
        private void updateOrder()
        {
            Console.WriteLine("\t~*~ ~*~ ~*~ \tUpdating Order\t ~*~ ~*~ ~*~\n");
            Console.WriteLine("Input OrderID: ");
            long id = Convert.ToInt64(Console.ReadLine());

            OrderDTO myOrder = dalorder.GetOrderByID(id);

            if (myOrder is null) //check if such order exists
            {
                Console.WriteLine("Invalid input! No such order in database.\n");
                return;
            }

            bool flag = true;

            while (flag)
            {
                Console.WriteLine("~ Updating Order:\n\tID: {0}\tCustomer: {1} {2} \tStatus: {3} \n\tComments: {4}\n",
                                  myOrder.MainOrderID, myOrder.CustomerID, getFullNameById(myOrder.CustomerID), getStatusById(myOrder.StatusID), myOrder.Comments);
                Console.WriteLine("Items in order: ");
                printItemsInOrder(myOrder.MainOrderID);

                Console.WriteLine("\nChoose an option:" +
                                  "\n\t1. Change customer" +
                                  "\n\t2. Chnage status" +
                                  "\n\t3. Change comments" +
                                  "\n\t0. Exit");
                try
                {
                    int opt = Convert.ToInt32(Console.ReadLine());
                    if (opt == 0)
                    {
                        flag = false;
                    }
                    switch (opt)
                    {
                    case 1:
                        Console.WriteLine("Input new CustomerID: ");
                        myOrder.CustomerID = Convert.ToInt64(Console.ReadLine());
                        break;

                    case 2:
                        Console.WriteLine("Input new StatusID: ");
                        myOrder.StatusID = Convert.ToInt16(Console.ReadLine());
                        break;

                    case 3:
                        Console.WriteLine("Input comment: ");
                        myOrder.Comments = Console.ReadLine();
                        break;

                    case 0:
                        flag = false;
                        break;

                    default:
                        throw new Exception("Invalid input.");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    Console.WriteLine("Try again, or input 0 to exit.");
                }
                myOrder.LastUpdate       = DateTime.UtcNow;
                myOrder.LastStaffUpdated = 1; //id of admin
                try
                {
                    myOrder = dalorder.UpdateOrder(myOrder);
                    Console.WriteLine($"Updated Item ID: {myOrder.MainOrderID}");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    Console.WriteLine("Data inputted incorrectly. Order update failed.");
                }
            }
        }