Commit eca7f7d

Jason Lepp <jlepp@arcresources.com>
2010-10-15 17:09:49
Begin adding presenter for TodoItems
1 parent 364848a
src/MVPtoMVVM/mappers/ITodoItemPresenterMapper.cs
@@ -0,0 +1,12 @@
+using System.Collections.Generic;
+using MVPtoMVVM.domain;
+using MVPtoMVVM.presenters;
+using MVPtoMVVM.views;
+
+namespace MVPtoMVVM.mappers
+{
+    public interface ITodoItemPresenterMapper
+    {
+        IEnumerable<ITodoItemPresenter> MapAll(IEnumerable<TodoItem> items);
+    }
+}
\ No newline at end of file
src/MVPtoMVVM/mappers/TodoItemPresenterMapper.cs
@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using MVPtoMVVM.domain;
+using MVPtoMVVM.presenters;
+using MVPtoMVVM.views;
+using StructureMap;
+
+namespace MVPtoMVVM.mappers
+{
+    public class TodoItemPresenterMapper : ITodoItemPresenterMapper
+    {
+        private ITodoItemPresenter MapFrom(TodoItem item)
+        {
+            var presenter = ObjectFactory.GetInstance<ITodoItemPresenter>();
+            presenter.SetItem(item);
+            return presenter;
+        }
+
+        public IEnumerable<ITodoItemPresenter> MapAll(IEnumerable<TodoItem> items)
+        {
+            return items.Select(todoItem => MapFrom(todoItem));
+        }
+    }
+}
\ No newline at end of file
src/MVPtoMVVM/presenters/IMvpPresenter.cs
@@ -1,8 +1,9 @@
+using MVPtoMVVM.views;
+
 namespace MVPtoMVVM.presenters
 {
     public interface IMvpPresenter
     {
         void SetView(IMvpView view);
-
     }
 }
\ No newline at end of file
src/MVPtoMVVM/presenters/ITodoItemPresenter.cs
@@ -0,0 +1,11 @@
+using MVPtoMVVM.domain;
+using MVPtoMVVM.views;
+
+namespace MVPtoMVVM.presenters
+{
+    public interface ITodoItemPresenter
+    {
+        void SetView(ITodoItemView view);
+        void SetItem(TodoItem item);
+    }
+}
\ No newline at end of file
src/MVPtoMVVM/presenters/MvpPresenter.cs
@@ -1,5 +1,8 @@
 using System;
+using System.Linq;
+using MVPtoMVVM.mappers;
 using MVPtoMVVM.repositories;
+using MVPtoMVVM.views;
 
 namespace MVPtoMVVM.presenters
 {
@@ -7,10 +10,12 @@ namespace MVPtoMVVM.presenters
     {
         private IMvpView view;
         private ITodoItemRepository itemRepository;
+        private ITodoItemPresenterMapper presenterMapper;
 
-        public MvpPresenter(ITodoItemRepository itemRepository)
+        public MvpPresenter(ITodoItemRepository itemRepository, ITodoItemPresenterMapper presenterMapper)
         {
             this.itemRepository = itemRepository;
+            this.presenterMapper = presenterMapper;
         }
 
         public void SetView(IMvpView view)
@@ -21,7 +26,7 @@ namespace MVPtoMVVM.presenters
 
         private void InitializeView()
         {
-            view.SetTodoItems(itemRepository.GetAll());
+            view.SetTodoItems(presenterMapper.MapAll(itemRepository.GetAll()));
         }
     }
 }
\ No newline at end of file
src/MVPtoMVVM/presenters/TodoItemPresenter.cs
@@ -0,0 +1,30 @@
+using System;
+using MVPtoMVVM.domain;
+using MVPtoMVVM.views;
+
+namespace MVPtoMVVM.presenters
+{
+    public class TodoItemPresenter : ITodoItemPresenter
+    {
+        private ITodoItemView view;
+        private TodoItem item;
+
+        public void SetView(ITodoItemView view)
+        {
+            this.view = view;
+            InitializeView();
+        }
+
+        public void SetItem(TodoItem item)
+        {
+            this.item = item;
+        }
+
+        private void InitializeView()
+        {
+            view.Description = item.Description;
+            view.DueDate = item.DueDate;
+        }
+
+    }
+}
\ No newline at end of file
src/MVPtoMVVM/repositories/IRepository.cs
@@ -1,12 +0,0 @@
-using System.Collections.Generic;
-using MVPtoMVVM.domain;
-
-namespace MVPtoMVVM.repositories
-{
-    public interface ITodoItemRepository
-    {
-        void Add(TodoItem item);
-        TodoItem Get(string description);
-        IEnumerable<TodoItem> GetAll();
-    }
-}
\ No newline at end of file
src/MVPtoMVVM/repositories/TodoItemRepository.cs
@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
 using MVPtoMVVM.domain;
 using System.Linq;
 
@@ -6,7 +7,13 @@ namespace MVPtoMVVM.repositories
 {
     public class TodoItemRepository : ITodoItemRepository
     {
-        private List<TodoItem> items = new List<TodoItem>();
+        private List<TodoItem> items;
+
+        public TodoItemRepository()
+        {
+            items = new List<TodoItem>();
+            items.Add(new TodoItem {Description = "First One", DueDate = DateTime.Today});
+        }
 
         public void Add(TodoItem item)
         {
src/MVPtoMVVM/views/IMvpView.cs
@@ -0,0 +1,10 @@
+using System.Collections.Generic;
+using MVPtoMVVM.presenters;
+
+namespace MVPtoMVVM.views
+{
+    public interface IMvpView
+    {
+        void SetTodoItems(IEnumerable<ITodoItemPresenter> presenters);
+    }
+}
\ No newline at end of file
src/MVPtoMVVM/views/ITodoItemView.cs
@@ -0,0 +1,10 @@
+using System;
+
+namespace MVPtoMVVM.views
+{
+    public interface ITodoItemView
+    {
+        string Description { get; set; }
+        DateTime DueDate { get; set; }
+    }
+}
\ No newline at end of file
src/MVPtoMVVM/IMvpView.cs
@@ -1,10 +0,0 @@
-using System.Collections.Generic;
-using MVPtoMVVM.domain;
-
-namespace MVPtoMVVM
-{
-    public interface IMvpView
-    {
-        void SetTodoItems(IEnumerable<TodoItem> items);
-    }
-}
\ No newline at end of file
src/MVPtoMVVM/MVPtoMVVM.csproj
@@ -33,6 +33,9 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
+    <Reference Include="StructureMap">
+      <HintPath>..\..\lib\StructureMap\StructureMap.dll</HintPath>
+    </Reference>
     <Reference Include="System" />
     <Reference Include="System.Core" />
     <Reference Include="System.Xml.Linq" />
@@ -43,12 +46,17 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="domain\TodoItem.cs" />
-    <Compile Include="IMvpView.cs" />
+    <Compile Include="mappers\ITodoItemPresenterMapper.cs" />
+    <Compile Include="mappers\TodoItemPresenterMapper.cs" />
+    <Compile Include="presenters\ITodoItemPresenter.cs" />
+    <Compile Include="presenters\TodoItemPresenter.cs" />
+    <Compile Include="views\IMvpView.cs" />
     <Compile Include="presenters\IMvpPresenter.cs" />
     <Compile Include="presenters\MvpPresenter.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="repositories\ITodoItemRepository.cs" />
     <Compile Include="repositories\TodoItemRepository.cs" />
+    <Compile Include="views\ITodoItemView.cs" />
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
src/MVPtoMVVM.mvp/MainWindow.xaml
@@ -1,8 +0,0 @@
-<Window x:Class="MVPtoMVVM.mvp.MainWindow"
-        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
-        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-        Title="MainWindow" Height="350" Width="525">
-    <Grid>
-        
-    </Grid>
-</Window>
src/MVPtoMVVM.mvp/MainWindow.xaml.cs
@@ -1,27 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Navigation;
-using System.Windows.Shapes;
-
-namespace MVPtoMVVM.mvp
-{
-    /// <summary>
-    /// Interaction logic for MainWindow.xaml
-    /// </summary>
-    public partial class MainWindow : Window
-    {
-        public MainWindow()
-        {
-            InitializeComponent();
-        }
-    }
-}
src/MVPtoMVVM.mvp/MVPtoMVVM.mvp.csproj
@@ -59,6 +59,9 @@
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </ApplicationDefinition>
+    <Compile Include="TodoItemView.xaml.cs">
+      <DependentUpon>TodoItemView.xaml</DependentUpon>
+    </Compile>
     <Page Include="MvpWindow.xaml">
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
@@ -72,6 +75,10 @@
       <DependentUpon>MvpWindow.xaml</DependentUpon>
       <SubType>Code</SubType>
     </Compile>
+    <Page Include="TodoItemView.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
   </ItemGroup>
   <ItemGroup>
     <Compile Include="Properties\AssemblyInfo.cs">
src/MVPtoMVVM.mvp/MvpWindow.xaml
@@ -3,7 +3,6 @@
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         Title="MainWindow" Height="350" Width="525">
     <StackPanel>
-        <DataGrid AutoGenerateColumns="True" Name="todoItemsGrid">
-        </DataGrid>
+        <ListView Name="todoItemsList"></ListView>
     </StackPanel>
 </Window>
src/MVPtoMVVM.mvp/MvpWindow.xaml.cs
@@ -1,7 +1,7 @@
 using System.Collections.Generic;
-using System.Diagnostics;
-using MVPtoMVVM.domain;
+using System.Linq;
 using MVPtoMVVM.presenters;
+using MVPtoMVVM.views;
 using StructureMap;
 
 namespace MVPtoMVVM.mvp
@@ -13,14 +13,14 @@ namespace MVPtoMVVM.mvp
         public MvpWindow()
         {
             InitializeComponent();
-            Debug.Write(ObjectFactory.WhatDoIHave());
             presenter = ObjectFactory.GetInstance<IMvpPresenter>();
             presenter.SetView(this);
         }
 
-        public void SetTodoItems(IEnumerable<TodoItem> items)
+        public void SetTodoItems(IEnumerable<ITodoItemPresenter> presenters)
         {
-            todoItemsGrid.ItemsSource = items;
+            todoItemsList.ItemsSource = presenters.Select(x => new TodoItemView(x));
         }
+
     }
 }
src/MVPtoMVVM.mvp/TodoItemView.xaml
@@ -0,0 +1,11 @@
+<UserControl x:Class="MVPtoMVVM.mvp.TodoItemView"
+             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
+             mc:Ignorable="d">
+    <StackPanel Orientation="Horizontal">
+        <TextBox Name="description" Width="200"/>
+        <DatePicker Name="dueDate" />
+    </StackPanel>
+</UserControl>
src/MVPtoMVVM.mvp/TodoItemView.xaml.cs
@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+using MVPtoMVVM.domain;
+using MVPtoMVVM.presenters;
+using MVPtoMVVM.views;
+
+namespace MVPtoMVVM.mvp
+{
+    /// <summary>
+    /// Interaction logic for TodoItemView.xaml
+    /// </summary>
+    public partial class TodoItemView : ITodoItemView
+    {
+        public TodoItemView(ITodoItemPresenter presenter)
+        {
+            InitializeComponent();
+            presenter.SetView(this);
+        }
+
+        public string Description
+        {
+            get { return description.Text; }
+            set { description.Text = value; }
+        }
+
+        public DateTime DueDate
+        {
+            get { return dueDate.SelectedDate.Value; }
+            set { dueDate.SelectedDate = value; }
+        }
+    }
+}
README
@@ -1,1 +0,0 @@
-Test commit