Example #1
0
        private void Button_Click_AddTask(object sender, RoutedEventArgs e)
        {
            //Check for length
            var taskToAdd = AddTask.Text;

            if (taskToAdd.Length < 5)
            {
                MessageBox.Show("The task should be at least 5 letters long!");
                return;
            }

            //adding the task to DB
            using (var context = new EverydayJournalContext())
            {
                var person = context.People.Find(LoggerUtility.UserId);
                var task   = new Task()
                {
                    Name = taskToAdd,
                    Date = new Date()
                    {
                        ExactDate = DateTime.Now
                    },
                    Person = person
                };

                context.Tasks.AddOrUpdate(task);
                context.SaveChanges();
                MessageBox.Show("Successfully added task");
                //Refresh the page
                TasksPage tasksPage = new TasksPage();
                this.NavigationService?.Navigate(tasksPage);
            }
        }
Example #2
0
        private void Button_Click_Delete(object sender, RoutedEventArgs e)
        {
            try
            {
                var selectedTaskId = 0;
                selectedTaskId = int.Parse(Tasks.SelectedItem.ToString().Substring(3, 5));
                //Deleting the selected task
                using (var context = new EverydayJournalContext())
                {
                    var taskToDelete = context.Tasks.FirstOrDefault(x => x.Id == selectedTaskId);
                    if (taskToDelete != null)
                    {
                        context.Tasks.Remove(taskToDelete);
                        context.SaveChanges();

                        MessageBox.Show("Successfully deleted task!");

                        //Refresh the page
                        TasksPage tasksPage = new TasksPage();
                        this.NavigationService?.Navigate(tasksPage);
                    }
                    else
                    {
                        MessageBox.Show("There is nothing to delete!");
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Please, select task first");
            }
        }
Example #3
0
        private void Button_Click_UpdateTask(object sender, RoutedEventArgs e)
        {
            try
            {
                var taskToUpdate = 0;
                //getting selected food Id
                taskToUpdate = int.Parse(Tasks.SelectedItem.ToString().Substring(3, 5));

                using (var context = new EverydayJournalContext())
                {
                    var updatedTaskName = UpdatedTaskName.Text;

                    var task = context.Tasks.FirstOrDefault(x => x.Id == taskToUpdate);

                    if (updatedTaskName.Length > 4 && updatedTaskName != task.Name && taskToUpdate > 0)
                    {
                        task.Name = updatedTaskName;
                        context.SaveChanges();
                        MessageBox.Show("Successfully updated task");

                        //Reloading the page
                        TasksPage tasksPage = new TasksPage();
                        this.NavigationService?.Navigate(tasksPage);
                    }
                    else
                    {
                        MessageBox.Show("The length should be greater than 4 symbols!");
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Please, select Task first!");
            }
        }
Example #4
0
        private void Button_Click_Tasks(object sender, RoutedEventArgs e)
        {
            //Navigate to Tasks page
            TasksPage taskPage = new TasksPage();

            this.NavigationService?.Navigate(taskPage);
        }