Skip to content

Commit

Permalink
WPF Client: create customer, show customer details, customer relocati…
Browse files Browse the repository at this point in the history
…ng, screen for choosing next task
  • Loading branch information
JoergEg committed Mar 11, 2011
1 parent 317d77c commit f1474b5
Show file tree
Hide file tree
Showing 28 changed files with 8,159 additions and 75 deletions.
Expand Up @@ -16,7 +16,7 @@ public CreateCustomerCommandHandler(IRepository repository)

public void Handle(CreateCustomerCommand command)
{
var client = Customer.CreateNew(command.Id, new CustomerName(command.ClientName),
var client = Customer.CreateNew(command.Id, new CustomerName(command.CustomerName),
new Address(command.Street, command.StreetNumber,
command.PostalCode, command.City),
new PhoneNumber(command.PhoneNumber));
Expand Down
18 changes: 10 additions & 8 deletions CQRSSample.Domain/Commands/CreateCustomerCommand.cs
Expand Up @@ -5,17 +5,19 @@ namespace CQRSSample.Domain.Commands
[Serializable]
public class CreateCustomerCommand : Command
{
public readonly string ClientName;
public readonly string Street;
public readonly string StreetNumber;
public readonly string PostalCode;
public readonly string City;
public readonly string PhoneNumber;
public string CustomerName { get; set; }
public string Street { get; set; }
public string StreetNumber { get; set; }
public string PostalCode { get; set; }
public string City { get; set; }
public string PhoneNumber { get; set; }

public CreateCustomerCommand(Guid id, string clientName, string street, string streetNumber, string postalCode, string city, string phoneNumber)
public CreateCustomerCommand(Guid id) : base(id){}

public CreateCustomerCommand(Guid id, string customerName, string street, string streetNumber, string postalCode, string city, string phoneNumber)
: base(id)
{
ClientName = clientName;
CustomerName = customerName;
Street = street;
StreetNumber = streetNumber;
PostalCode = postalCode;
Expand Down
10 changes: 6 additions & 4 deletions CQRSSample.Domain/Commands/RelocatingCustomerCommand.cs
Expand Up @@ -5,10 +5,12 @@ namespace CQRSSample.Domain.Commands
[Serializable]
public class RelocatingCustomerCommand : Command
{
public readonly string Street;
public readonly string Streetnumber;
public readonly string PostalCode;
public readonly string City;
public string Street { get; set; }
public string Streetnumber { get; set; }
public string PostalCode { get; set; }
public string City { get; set; }

public RelocatingCustomerCommand(Guid id) : base(id){}

public RelocatingCustomerCommand(Guid id, string street, string streetNumber, string postalCode, string city) : base(id)
{
Expand Down
7 changes: 4 additions & 3 deletions CQRSSample.ReadModel/IReadRepository.cs
@@ -1,3 +1,4 @@
using System;
using System.Linq;
using Raven.Client;

Expand All @@ -6,7 +7,7 @@ namespace CQRSSample.ReadModel
public interface IReadRepository
{
IQueryable<T> GetAll<T>() where T : class;
T GetById<T>(string id) where T : class;
T GetById<T>(Guid id) where T : class;
}

public class RavenReadRepository : IReadRepository
Expand All @@ -26,11 +27,11 @@ public RavenReadRepository(IDocumentStore documentStore)
}
}

public T GetById<T>(string id) where T : class
public T GetById<T>(Guid id) where T : class
{
using (var session = _documentStore.OpenSession())
{
return session.Load<T>(id);
return session.Load<T>(id.ToString());
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion CQRSSample.WpfClient/App.xaml
Expand Up @@ -6,9 +6,11 @@
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary>
<!-- don't forget to start RavenDB\Server\Raven.Server.exe -->
<local:WpfClientBootstrapper x:Key="bootstrapper" />
</ResourceDictionary>
<ResourceDictionary Source="Themes\ExpressionDark.xaml"/>
<ResourceDictionary Source="Themes\ExpressionDark.xaml" />
<ResourceDictionary Source="ApplicationFramework\Resources\ConverterResource.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Expand Down
@@ -0,0 +1,22 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace CQRSSample.WpfClient.ApplicationFramework.Converters
{
public class CollapsedWhenNullConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value == null
? Visibility.Collapsed
: Visibility.Visible;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
@@ -0,0 +1,7 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Converters="clr-namespace:CQRSSample.WpfClient.ApplicationFramework.Converters">

<Converters:CollapsedWhenNullConverter x:Key="collapsedWhenNullConverter" />

</ResourceDictionary>
51 changes: 50 additions & 1 deletion CQRSSample.WpfClient/CQRSSample.WpfClient.csproj
Expand Up @@ -49,6 +49,11 @@
<Reference Include="EventStore.Persistence.RavenPersistence">
<HintPath>..\External Libs\CommonDomain\bin\EventStore.Persistence.RavenPersistence.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Windows.Shell, Version=3.5.41019.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<Reference Include="RibbonControlsLibrary, Version=3.5.41019.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\External Libs\Microsoft Ribbon for WPF\V4.0\RibbonControlsLibrary.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Web" />
<Reference Include="System.Windows.Interactivity">
Expand All @@ -58,6 +63,9 @@
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="UIAutomationProvider" />
<Reference Include="UIAutomationTypes" />
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
Expand All @@ -71,8 +79,25 @@
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="ApplicationFramework\Converters\CollapsedWhenNullConverter.cs" />
<Compile Include="Infrastructure\Installers\ViewModelInstaller.cs" />
<Compile Include="Modules\CustomerList\CustomerListScreen.cs" />
<Compile Include="Modules\CustomerDetails\CreateCustomer\CreateCustomerView.xaml.cs">
<DependentUpon>CreateCustomerView.xaml</DependentUpon>
</Compile>
<Compile Include="Modules\CustomerDetails\CreateCustomer\CreateCustomerViewModel.cs" />
<Compile Include="Modules\CustomerDetails\CustomerDetailsOverview\CustomerDetailsOverviewView.xaml.cs">
<DependentUpon>CustomerDetailsOverviewView.xaml</DependentUpon>
</Compile>
<Compile Include="Modules\CustomerDetails\CustomerDetailsOverview\CustomerDetailsOverviewViewModel.cs" />
<Compile Include="Modules\CustomerDetails\CustomerRelocating\CustomerRelocatingView.xaml.cs">
<DependentUpon>CustomerRelocatingView.xaml</DependentUpon>
</Compile>
<Compile Include="Modules\CustomerDetails\CustomerRelocating\CustomerRelocatingViewModel.cs" />
<Compile Include="Modules\CustomerDetails\WhatsNext\WhatsNextView.xaml.cs">
<DependentUpon>WhatsNextView.xaml</DependentUpon>
</Compile>
<Compile Include="Modules\CustomerDetails\WhatsNext\WhatsNextViewModel.cs" />
<Compile Include="Modules\CustomerList\CustomerListViewModel.cs" />
<Compile Include="Modules\CustomerList\CustomerListView.xaml.cs">
<DependentUpon>CustomerListView.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -108,6 +133,26 @@
<AppDesigner Include="Properties\" />
</ItemGroup>
<ItemGroup>
<Page Include="ApplicationFramework\Resources\ConverterResource.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Modules\CustomerDetails\CreateCustomer\CreateCustomerView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Modules\CustomerDetails\CustomerDetailsOverview\CustomerDetailsOverviewView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Modules\CustomerDetails\CustomerRelocating\CustomerRelocatingView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Modules\CustomerDetails\WhatsNext\WhatsNextView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Modules\CustomerList\CustomerListView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -149,6 +194,10 @@
<Folder Include="ApplicationFramework\Controls\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CQRSSample.Domain\CQRSSample.Domain.csproj">
<Project>{A9EE33AB-B226-491C-8F14-A78069618F21}</Project>
<Name>CQRSSample.Domain</Name>
</ProjectReference>
<ProjectReference Include="..\CQRSSample.Infrastructure\CQRSSample.Infrastructure.csproj">
<Project>{F2DE41A9-C7A9-433C-9217-EEA6EE859159}</Project>
<Name>CQRSSample.Infrastructure</Name>
Expand Down
@@ -0,0 +1,14 @@
<UserControl x:Class="CQRSSample.WpfClient.Modules.CustomerDetails.CreateCustomer.CreateCustomerView"
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"
d:DesignHeight="800" d:DesignWidth="600">
<StackPanel HorizontalAlignment="Left">
<TextBlock>Customer name:</TextBlock>
<TextBox Text="{Binding Command.CustomerName, UpdateSourceTrigger=PropertyChanged}" Width="400" />

<Button x:Name="Save" Content="Save" Margin="0 20 0 0" Width="100" HorizontalAlignment="Right" IsDefault="True" />
</StackPanel>
</UserControl>
@@ -0,0 +1,27 @@
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 CQRSSample.WpfClient.Modules.CustomerDetails.CreateCustomer
{
/// <summary>
/// Interaction logic for CreateCustomerView.xaml
/// </summary>
public partial class CreateCustomerView : UserControl
{
public CreateCustomerView()
{
InitializeComponent();
}
}
}
@@ -0,0 +1,35 @@
using System;
using Caliburn.Micro;
using CQRSSample.Domain.Commands;
using CQRSSample.Infrastructure;

namespace CQRSSample.WpfClient.Modules.CustomerDetails.CreateCustomer
{
public class CreateCustomerViewModel : Screen
{
private readonly IBus _bus;
private readonly IEventAggregator _eventAggregator;

public CreateCustomerViewModel(IBus bus, IEventAggregator eventAggregator)
{
_bus = bus;
_eventAggregator = eventAggregator;
Command = new CreateCustomerCommand(Guid.NewGuid());
}

public CreateCustomerCommand Command{ get; private set; }

public void Save()
{
//important: send command over bus
_bus.Send(Command);

//signal for UI - change view
_eventAggregator.Publish(new CreateCustomerSavedEvent());
}
}

public class CreateCustomerSavedEvent
{
}
}
@@ -0,0 +1,19 @@
<UserControl x:Class="CQRSSample.WpfClient.Modules.CustomerDetails.CustomerDetailsOverview.CustomerDetailsOverviewView"
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"
d:DesignHeight="800" d:DesignWidth="600">
<StackPanel HorizontalAlignment="Center">
<StackPanel VerticalAlignment="Center" Margin="0 0 0 20">
<TextBlock FontSize="40" FontWeight="ExtraLight" Text="{Binding ViewModel.Name}" />
<TextBlock HorizontalAlignment="Right" FontWeight="ExtraLight">All you want to know about your cusomter</TextBlock>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Margin="0 0 2 0">Now living in</TextBlock>
<TextBlock Text="{Binding ViewModel.City}"></TextBlock>
</StackPanel>
<Button x:Name="RelocateCustomer" Width="200" Margin="0 20 0 0">Customer relocated</Button>
</StackPanel>
</UserControl>
@@ -0,0 +1,27 @@
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 CQRSSample.WpfClient.Modules.CustomerDetails.CustomerDetailsOverview
{
/// <summary>
/// Interaction logic for CustomerDetailsOverviewView.xaml
/// </summary>
public partial class CustomerDetailsOverviewView : UserControl
{
public CustomerDetailsOverviewView()
{
InitializeComponent();
}
}
}
@@ -0,0 +1,41 @@
using System;
using Caliburn.Micro;
using CQRSSample.ReadModel;

namespace CQRSSample.WpfClient.Modules.CustomerDetails.CustomerDetailsOverview
{
public class CustomerDetailsOverviewViewModel : Screen
{
private readonly IReadRepository _readRepository;
private readonly IEventAggregator _eventAggregator;

public CustomerDetailsOverviewViewModel(IReadRepository readRepository, IEventAggregator eventAggregator)
{
_readRepository = readRepository;
_eventAggregator = eventAggregator;
}

public void WithCustomer(Guid customerId)
{
ViewModel = _readRepository.GetById<CustomerListDto>(customerId);
}

//TODO: Change CustomerListDto to something specific for this screen
public CustomerListDto ViewModel { get; private set; }

public void RelocateCustomer()
{
_eventAggregator.Publish(new ShowCustomerRelocatingEvent(ViewModel.Id));
}
}

public class ShowCustomerRelocatingEvent
{
public readonly Guid CustomerId;

public ShowCustomerRelocatingEvent(Guid customerId)
{
CustomerId = customerId;
}
}
}

0 comments on commit f1474b5

Please sign in to comment.