Esempio n. 1
0
        private MenuOptionResult AddTask()
        {
            Task task = GetTaskinfo();

            if (task != null)
            {
                taskDAO.AddTask(task);
            }
            return(MenuOptionResult.DoNotWaitAfterMenuSelection);
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Task List!\r\n");
            System.Threading.Thread.Sleep(500);

            // Read the config file
            Config config = new Config("appsettings.json");

            if (config.UseSql)
            {
                taskDAO = new TaskSqlDAO(config.ConnectionString);
            }
            else
            {
                taskDAO = new TaskFileDAO(config.FilePath);
            }

            while (true)
            {
                Console.Clear();

                // List all the tasks
                IList <Task> list = taskDAO.GetOpenTasks();
                ListTasks(list);

                Console.WriteLine();
                Console.WriteLine("What would you like to do?");
                Console.WriteLine("(A)dd a task");
                Console.WriteLine("(C)omplete a task");
                Console.WriteLine("(Q)uit");

                string input = Console.ReadLine().Trim().ToUpper();

                if (input.Length == 0)
                {
                    continue;
                }
                if (input.Substring(0, 1) == "Q")
                {
                    break;
                }
                int taskId;
                switch (input.Substring(0, 1))
                {
                case "A":
                    // Prompt the user to add a task
                    Task task = GetTaskinfo();
                    taskDAO.AddTask(task);
                    break;

                case "C":
                    taskId = GetTaskId(list);
                    if (taskId > 0)
                    {
                        task           = taskDAO.GetById(taskId);
                        task.Completed = true;
                        taskDAO.Update(task);
                    }
                    break;
                }
            }
        }