Permalink
Browse files

deleting todo items

  • Loading branch information...
1 parent 20e2a8b commit 0a111a4f0dfba6aba62a7569430b65f33ef5a401 Christian Lang committed Feb 25, 2012
@@ -15,7 +15,7 @@ public TodoItemsRepository(IDataContext dataContext)
public override IQueryable<TodoItem> FindAll()
{
- return this.DataContext.TodoItems;
+ return this.DataContext.TodoItems.Where(t => !t.Deleted);
}
public override TodoItem Find(int id)
@@ -15,6 +15,8 @@ public class TodoItem
public DateTime? DueDate { get; set; }
+ public bool Deleted { get; set; }
+
public virtual ICollection<Tag> Tags { get; set; }
}
}
@@ -31,7 +31,7 @@ public string Text
}
}
- public void Remove()
+ public void RemoveTag()
{
if (OnRemove != null) OnRemove(this, EventArgs.Empty);
}
@@ -44,6 +44,12 @@ public string Text
set { this.item.DueDate = value; }
}
+ public bool Deleted
+ {
+ get { return this.item.Deleted; }
+ set { this.item.Deleted = value; }
+ }
+
public IObservableCollection<TagViewModel> Tags
{
get { return this.tags; }
@@ -48,18 +48,25 @@ public void SaveTodoList()
this.repository.Save();
}
- public void AddNew(NewTodoItemViewModel dataContext, KeyEventArgs e)
+ public void AddNewTodo(NewTodoItemViewModel model, KeyEventArgs e)
{
- if (e.Key == Key.Return && !string.IsNullOrWhiteSpace(dataContext.Text))
+ if (e.Key == Key.Return && !string.IsNullOrWhiteSpace(model.Text))
{
- var item = new TodoItem { Text = dataContext.Text, DueDate = dataContext.DueDate, Tags = new BindableCollection<Tag>() };
+ var item = new TodoItem { Text = model.Text, DueDate = model.DueDate, Tags = new BindableCollection<Tag>() };
this.TodoItems.Add(new TodoItemViewModel(item));
this.repository.Add(item);
this.repository.Save();
- dataContext.Clear();
+ model.Clear();
}
}
+ public void DeleteTodo(TodoItemViewModel model)
+ {
+ model.Deleted = true;
+ this.repository.Save();
+ this.todoItems.Remove(model);
+ }
+
private void OnFilterChanged(object sender, EventArgs eventArgs)
{
var items = this.repository.FindAll()
@@ -18,7 +18,7 @@
</Border.Background>
<i:Interaction.Triggers>
<i:EventTrigger EventName="KeyUp">
- <cal:ActionMessage MethodName="AddNew">
+ <cal:ActionMessage MethodName="AddNewTodo">
<cal:Parameter Value="$dataContext" />
<cal:Parameter Value="$eventArgs" />
</cal:ActionMessage>
@@ -4,7 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
- d:DesignHeight="300" d:DesignWidth="300">
+ d:DesignHeight="20" d:DesignWidth="100">
<Border CornerRadius="7" BorderBrush="#9ACAE4" BorderThickness="1" Padding="5,0">
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
@@ -14,7 +14,7 @@
</Border.Background>
<StackPanel Orientation="Horizontal">
<TextBlock Name="Text" />
- <Button Name="Remove">
+ <Button Name="RemoveTag">
<Button.Template>
<ControlTemplate>
<TextBlock FontSize="10" Padding="5,0,0,0">x</TextBlock>
@@ -20,6 +20,20 @@
</i:Interaction.Triggers>
<DockPanel>
<CheckBox Name="Done" VerticalAlignment="Center" Margin="0,0,5,0" />
+ <Button Name="DeleteTodo" DockPanel.Dock="Right">
+ <Button.Template>
+ <ControlTemplate>
+ <TextBlock FontSize="14" FontWeight="Bold" Foreground="#333333" Padding="5,0,0,0">x</TextBlock>
+ </ControlTemplate>
+ </Button.Template>
+ <i:Interaction.Triggers>
+ <i:EventTrigger EventName="Click">
+ <cal:ActionMessage MethodName="DeleteTodo">
+ <cal:Parameter Value="$dataContext" />
+ </cal:ActionMessage>
+ </i:EventTrigger>
+ </i:Interaction.Triggers>
+ </Button>
<DatePicker Name="DueDate" FontSize="12" VerticalAlignment="Center" DockPanel.Dock="Right" Width="130" Margin="5,0,0,0" />
<ItemsControl Name="Tags" VerticalAlignment="Center" DockPanel.Dock="Right">
<ItemsControl.ItemsPanel>

0 comments on commit 0a111a4

Please sign in to comment.