Exemple #1
0
        //implementation of the button that adds tasks
        public void AddTaskButton_Click(object sender, RoutedEventArgs e)
        {
            //binding gui fields to values
            string title, description;

            title       = AddTitle.Text;
            description = AddDescription.Text;
            DateTime dueDate;

            // Check if correct dueDate was passed:
            try {
                dueDate = (DateTime)DueDateCalendar.SelectedDate;
            } catch (InvalidOperationException err) {
                MessageBox.Show("Check the due date!");
                return;
            }


            //creating a task if fields are filled
            bool isTaskValid = ValidateTask(title, description, dueDate);

            if (isTaskValid)
            {
                //Buid a new Task
                TaskBuilder builder = new TaskBuilder();

                builder.SetTaskTitle(title)
                .SetTaskDesc(description)
                .SetCreationDate()
                .SetDueDate(dueDate)
                .SetUserId(currentUser.Id)
                .SetStatus(TaskStatus.New.ToString());

                Task newTask = builder.Build();

                // Add it to the repo:
                taskRepo.Add(newTask);
                taskRepo.Save();

                MessageBox.Show("Task created successfully!");
                ReloadTaskList();
            }
        }