示例#1
0
 public InterfaceLayerTask FindTask(int taskId)
 {
     if (kanban.FindTask(taskId))
     {
         foreach (InterfaceLayerColumn c in GetBoard())
         {
             foreach (InterfaceLayerTask t in c.tasks)
             {
                 if (t.taskId == taskId)
                 {
                     return(new InterfaceLayerTask(taskId, t.taskTitle, t.taskBody, t.creationDate, t.dueDate, t.userId, t.colName));
                 }
             }
         }
     }
     return(null);
 }
        public static void ChooseOption(string userChoise)// sort the user's choice
        {
            if (userChoise.Length == 1)
            {
                switch (userChoise)
                {
                case "1":    // in case the user wants to add task to his board
                    Console.ForegroundColor = ConsoleColor.Blue;
                    Console.WriteLine("In order to add a task please enter the following details according to the instructions.");
                    Console.WriteLine("The number of tasks in each column is limited, make sure you have space left before trying to add a task.");
                    Console.WriteLine("Your limit is: " + kanban.GetMaxLength() + "\n");
                    Console.ResetColor();
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Task's title - contains max 50 characters, not empty.\n");
                    Console.ResetColor();
                    Console.Write("Title :");
                    string title = Console.ReadLine();
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Task's description - contains 0-300 characters.");
                    Console.ResetColor();
                    Console.Write("Description :");
                    string body = Console.ReadLine();
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Task's due date - must be a date that has not passed yet.");
                    Console.ResetColor();
                    Console.Write("Enter due date (dd/mm/yyyy) : ");
                    string dueDate = Console.ReadLine();
                    while (!IsDateTime(dueDate))
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Log.Warn("Invalid date");
                        Console.WriteLine("Please enter a valid date as mentioned.");
                        Console.ResetColor();
                        Console.Write("Enter due date (dd/mm/yyyy) : ");
                        dueDate = Console.ReadLine();
                    }
                    AddTask(title, body, DateTime.Parse(dueDate));
                    break;

                case "2":    //in case the user wants to further a task
                    Console.ForegroundColor = ConsoleColor.Blue;
                    Console.WriteLine("If you start working on a task or you finish one");
                    Console.WriteLine("you can move your task one column forward:");
                    Console.WriteLine("from 'to do' to 'in progress' and from 'in progress' to 'done'.");
                    Console.ResetColor();
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Note: you can't move a task that is located in 'done' column!");
                    Console.ResetColor();
                    Console.ForegroundColor = ConsoleColor.Blue;
                    Console.WriteLine("Please enter the following task's details.");
                    Console.ResetColor();
                    Console.Write("Task number :");
                    string taskId = Console.ReadLine();
                    int    task   = ValidNumber(taskId);
                    if (task == -1)     //if the input is invalid
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Log.Warn("Invalid task number");
                        Console.WriteLine("Make sure you enter a valid task number.");
                        Console.ResetColor();
                        UserOption();
                    }
                    else
                    {
                        MoveTask(task);
                    }
                    break;

                case "3":    //in case the user wants to remove task
                    Console.ForegroundColor = ConsoleColor.Blue;
                    Console.WriteLine("Please enter the following task's details.");
                    Console.ResetColor();
                    Console.Write("Task number :");
                    taskId = Console.ReadLine();
                    task   = ValidNumber(taskId);
                    if (task == -1)     //if the inputs invalid
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Log.Warn("Invalid task number");
                        Console.WriteLine("Make sure you enter a valid task number.");
                        Console.ResetColor();
                        UserOption();
                    }
                    else
                    {
                        RemoveTask(task);
                    }
                    break;

                case "4":    //edit task
                    Console.ForegroundColor = ConsoleColor.Blue;
                    Console.WriteLine("Please enter the number of the task you would like to edit");
                    Console.ResetColor();
                    Console.Write("Task number :");
                    taskId = Console.ReadLine();
                    task   = ValidNumber(taskId);
                    if (task == -1)     //if the inputs invalid
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Log.Warn("Invalid task number");
                        Console.WriteLine("Make sure you enter a valid task number.");
                        Console.ResetColor();
                        UserOption();
                    }
                    else if (kanban.FindTask(task))
                    {
                        EditTaskChooseOption(task);
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Log.Warn("Invalid task number");
                        Console.WriteLine("Task number doesn't exist\n");
                        Console.ResetColor();
                        UserOption();
                    }

                    break;

                case "5":    //log out
                    LogOut();
                    break;

                case "6":     // exit the system
                    Exit();
                    break;

                default:     //the user enter incorrect option
                    Console.ForegroundColor = ConsoleColor.Red;
                    Log.Info("Invalid input, this input isn't one of the options");
                    Console.WriteLine("please type only one of the options.\n");
                    Console.ResetColor();
                    UserOption();
                    break;
                }
            }
            else //the user enter incorrect option
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Log.Info("Invalid input, this input isn't one of the options");
                Console.WriteLine("please type only one of the options.\n");
                Console.ResetColor();
                UserOption();
                //same as default
            }
        }