public AddDialog(ref ToDoItem item)
        {
            InitializeComponent();

            this.DataContext = item;
        }
        private void addButton_Click(object sender, RoutedEventArgs e)
        {
            ToDoItem item = new ToDoItem();
            AddDialog addDialog = new AddDialog(ref item);
            Nullable<bool> dialogResult = addDialog.ShowDialog();
            if (dialogResult == true)
            {
                //Get new Index
                if (ToDoList.Count == 0)
                    item.Index = 0;
                else
                {
                    var maxIndex = ToDoList.Max(m => m.Index);
                    item.Index = ++maxIndex;
                }

                //Get new GUID
                item.Id = Guid.NewGuid();

                //Save the item to db
                int rowsAffected = 0;
                using (ToDoEntities da = new ToDoEntities())
                {
                    da.ToDoItems.AddObject(item);
                    rowsAffected = da.SaveChanges();
                }

                // Save the item to the list
                if (rowsAffected != 0)
                    ToDoList.Add(item);
                else
                    MessageBox.Show("Error while accessing the database", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the ToDoItems EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToToDoItems(ToDoItem toDoItem)
 {
     base.AddObject("ToDoItems", toDoItem);
 }
        private bool IsContainingText(ToDoItem item, string searchString)
        {
            if (searchString == "")
                return true;

            if (item.Title != null)
                if (item.Title.IndexOf(searchString, StringComparison.OrdinalIgnoreCase) >= 0)
                    return true;
            if (item.Description != null)
                if (item.Description.IndexOf(searchString, StringComparison.OrdinalIgnoreCase) >= 0)
                    return true;

            return false;
        }
 /// <summary>
 /// Create a new ToDoItem object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="index">Initial value of the Index property.</param>
 /// <param name="done">Initial value of the Done property.</param>
 public static ToDoItem CreateToDoItem(global::System.Guid id, global::System.Int64 index, global::System.Boolean done)
 {
     ToDoItem toDoItem = new ToDoItem();
     toDoItem.Id = id;
     toDoItem.Index = index;
     toDoItem.Done = done;
     return toDoItem;
 }