示例#1
0
        private void Create()
        {
            Console.Clear();
            TaskRepository taskRepository = new TaskRepository("TaskDataBase.txt");
            TaskEntity     taskEntity     = new TaskEntity();

            Console.WriteLine("Press [ENTER] to start a new task:");
            Console.WriteLine("OR Press X to return: ");
            string choice = Console.ReadLine();
            bool   result = Int32.TryParse(choice, out int id);

            if (choice.ToUpper() == "X")
            {
                return;
            }
            Console.Write("Enter a new name: ");
            taskEntity.Name = Console.ReadLine();
            Console.Write("Enter a new description: ");
            taskEntity.Description = Console.ReadLine();
            while (true)
            {
                Console.Write("Enter a new start time:");
                string   startTimeEntered = Console.ReadLine();
                DateTime startTime;
                result = DateTime.TryParse(startTimeEntered, out startTime);

                if (DateTime.TryParse(startTimeEntered, out startTime))
                {
                    String.Format(CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern, startTime);
                    taskEntity.StartTime = startTime;
                    break;
                }
                else
                {
                    Console.WriteLine("Invalid"); // <-- Control flow goes here
                }

                Console.WriteLine("Enter a valid start time!");
            }
            while (true)
            {
                Console.Write("Enter a new end time:");
                string   endTimeEntered = Console.ReadLine();
                DateTime endTime;
                result = DateTime.TryParse(endTimeEntered, out endTime);

                if (DateTime.TryParse(endTimeEntered, out endTime))
                {
                    String.Format(CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern, endTime);
                    taskEntity.EndTime = endTime;
                    break;
                }
                else
                {
                    Console.WriteLine("Invalid"); // <-- Control flow goes here
                }

                Console.WriteLine("Enter a valid end time!");
            }
            taskRepository.Save(taskEntity);
            Console.WriteLine("Task saved!");
            Console.WriteLine("Press enter to return:");
            Console.ReadKey(true);
        }
示例#2
0
        private void Edit()
        {
            Console.Clear();
            TaskRepository taskRepository = new TaskRepository("TaskDataBase.txt");

            Console.Write("Which task do you want to edit: " + "[Enter ID]");
            Console.WriteLine("OR Press X to return: ");
            string choice = Console.ReadLine();
            bool   result = Int32.TryParse(choice, out int id);

            if (choice.ToUpper() == "X")
            {
                return;
            }
            TaskEntity taskEntity = taskRepository.GetByID(id);

            if (taskEntity == null)
            {
                Console.WriteLine("Task not found!");
                Console.ReadKey(true);
                return;
            }

            taskEntity.Id = id;
            Console.Write("Enter a new name: ");
            taskEntity.Name = Console.ReadLine();
            Console.Write("Enter a new description:");
            taskEntity.Description = Console.ReadLine();

            while (true)
            {
                Console.Write("Enter a new start time:");
                string   startTimeEntered = Console.ReadLine();
                DateTime startTime;
                result = DateTime.TryParse(startTimeEntered, out startTime);

                if (DateTime.TryParse(startTimeEntered, out startTime))
                {
                    String.Format(CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern, startTime);
                    taskEntity.StartTime = startTime;
                    break;
                }
                else
                {
                    Console.WriteLine("Invalid");
                }

                Console.WriteLine("Enter a valid start time!");
            }
            while (true)
            {
                Console.Write("Enter a new end time:");
                string   endTimeEntered = Console.ReadLine();
                DateTime endTime;
                result = DateTime.TryParse(endTimeEntered, out endTime);

                if (DateTime.TryParse(endTimeEntered, out endTime))
                {
                    String.Format(CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern, endTime);
                    taskEntity.EndTime = endTime;
                    break;
                }
                else
                {
                    Console.WriteLine("Invalid");
                }

                Console.WriteLine("Enter a valid end time!");
            }
            taskRepository.Edit(taskEntity);
            Console.WriteLine("Task Edited!");
            Console.WriteLine("Press enter to return:");
            Console.ReadKey(true);
        }