private void addClick(object sender, RoutedEventArgs e)
        {
            if (TaskField.Text == string.Empty)
            {
                MessageBox.Show("Please enter a new task.");
                return;
            }
            if (App.ViewModel.ActiveToDoCateg == null)
            {
                MessageBox.Show("The current category is null");
                return;
            }
            using (ToDoDataContext ToDoDB = new ToDoDataContext("Data Source=isostore:/ToDo.sdf"))
            {

                ToDoItem newItem = new ToDoItem
                {
                    ItemName = TaskField.Text,
                    _categoryId = App.ViewModel.ActiveToDoCateg.Id,
                    IsComplete = false
                };
                ToDoDB.Items.InsertOnSubmit(newItem);
                ToDoDB.SubmitChanges();
                MessageBox.Show("Your task was added successfully!");
                this.NavigationService.Navigate(new Uri("/TodoItems.xaml", UriKind.Relative));
            }
        }
Exemple #2
0
        // Add a to-do item to the database and collections.
        public void AddToDoItem(ToDoItem newToDoItem)
        {
            // Add a to-do item to the data context.
            toDoDB.Items.InsertOnSubmit(newToDoItem);

            // Save changes to the database.
            toDoDB.SubmitChanges();

            // Add a to-do item to the "all" observable collection.
            AllToDoItems.Add(newToDoItem);

            /*
            using (ToDoDataContext ToDoDB = new ToDoDataContext("Data Source=isostore:/ToDo.sdf"))
            {
                ToDoCategory newCategory = new ToDoCategory
                {
                    Name = CategoryField.Text
                };

                //check if it already exists by iterating through all
                IList<ToDoCategory> categories = this.GetCategories();
                foreach (ToDoCategory todoCateg in categories)
                {
                    if (todoCateg.Name.Equals(newCategory.Name))
                    {
                        MessageBox.Show("The category already exists");
                        return;
                    }
                }

                ToDoDB.Categories.InsertOnSubmit(newCategory);
                ToDoDB.SubmitChanges();
                MessageBox.Show("Your new category has been added successfully!");
                this.NavigationService.Navigate(new Uri("/Todo.xaml", UriKind.Relative));
            }
             * */
        }
Exemple #3
0
 // Called during a remove operation
 private void detach_ToDo(ToDoItem toDo)
 {
     NotifyPropertyChanging("ToDoItem");
     toDo.Category = null;
 }
Exemple #4
0
 // Called during an add operation
 private void attach_ToDo(ToDoItem toDo)
 {
     NotifyPropertyChanging("ToDoItem");
     toDo.Category = this;
 }
Exemple #5
0
        // Remove a to-do task item from the database and collections.
        public void DeleteToDoItem(ToDoItem toDoForDelete)
        {
            // Remove the to-do item from the "all" observable collection.
            AllToDoItems.Remove(toDoForDelete);

            // Remove the to-do item from the data context.
            toDoDB.Items.DeleteOnSubmit(toDoForDelete);

            // Save changes to the database.
            toDoDB.SubmitChanges();
        }