Commit 42304e1

mo <email@solidware.ca>
2011-03-31 03:58:11
extract Family view model.
1 parent a994056
product/desktop.ui/model/TaxesForIndividual.cs
@@ -8,19 +8,19 @@ namespace solidware.financials.windows.ui.model
     {
         public TaxesForIndividual(Guid id, FederalTaxesViewModel federalTaxes)
         {
-            FederalTaxes = federalTaxes;
             Id = id;
-            TotalIncome = Money.Null;
+            Income = Money.Null;
+            FederalTaxes = federalTaxes;
         }
 
         public Guid Id { get; private set; }
-        public Observable<Money> TotalIncome { get; private set; }
+        public Observable<Money> Income { get; private set; }
         public FederalTaxesViewModel FederalTaxes { get; set; }
 
         public void AddIncome(decimal amount)
         {
-            TotalIncome.Value += amount;
-            FederalTaxes.ApplyTaxesTo(TotalIncome.Value);
+            Income.Value += amount;
+            FederalTaxes.ApplyTaxesTo(Income.Value);
         }
     }
 }
\ No newline at end of file
product/desktop.ui/presenters/TaxesForFamily.cs
@@ -0,0 +1,36 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using solidware.financials.windows.ui.model;
+using solidware.financials.windows.ui.views.controls;
+
+namespace solidware.financials.windows.ui.presenters
+{
+    public class TaxesForFamily
+    {
+        public TaxesForFamily()
+        {
+            Income = Money.Null;
+            FederalTaxes = Money.Null;
+        }
+
+        public Observable<Money> Income { get; set; }
+        public Observable<Money> FederalTaxes { get; set; }
+
+        public TaxesForIndividual TaxesFor(Guid id)
+        {
+            if (!family.ContainsKey(id))
+                family[id] = new TaxesForIndividual(id, new FederalTaxesViewModel(id));
+            return family[id];
+        }
+
+        public void AddIncomeFor(Guid personId, decimal amount)
+        {
+            TaxesFor(personId).AddIncome(amount);
+            Income.Value = family.Values.Sum(x => x.Income.Value);
+            FederalTaxes.Value = family.Values.Sum(x => x.FederalTaxes.Taxes.Value);
+        }
+
+        IDictionary<Guid, TaxesForIndividual> family = new Dictionary<Guid, TaxesForIndividual>();
+    }
+}
\ No newline at end of file
product/desktop.ui/presenters/TaxSummaryPresenter.cs
@@ -1,12 +1,8 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using solidware.financials.infrastructure;
+using solidware.financials.infrastructure;
 using solidware.financials.infrastructure.eventing;
 using solidware.financials.messages;
 using solidware.financials.windows.ui.events;
 using solidware.financials.windows.ui.model;
-using solidware.financials.windows.ui.views.controls;
 
 namespace solidware.financials.windows.ui.presenters
 {
@@ -19,8 +15,7 @@ namespace solidware.financials.windows.ui.presenters
         {
             this.builder = builder;
             this.bus = bus;
-            FamilyIncome = Money.Null;
-            TotalFamilyFederalTaxes = Money.Null;
+            Family = new TaxesForFamily();
         }
 
         public string Header
@@ -28,9 +23,8 @@ namespace solidware.financials.windows.ui.presenters
             get { return "Taxes"; }
         }
 
-        public TaxesForIndividual Selected { get; set; }
-        public Observable<Money> FamilyIncome { get; set; }
-        public Observable<Money> TotalFamilyFederalTaxes { get; set; }
+        public TaxesForIndividual Individual { get; set; }
+        public TaxesForFamily Family { get; set; }
 
         public void present()
         {
@@ -39,24 +33,14 @@ namespace solidware.financials.windows.ui.presenters
 
         public void notify(IncomeMessage message)
         {
-            FamilyIncome.Value += message.Amount;
-            TaxesFor(message.PersonId).AddIncome(message.Amount);
-            TotalFamilyFederalTaxes.Value = family.Values.Sum(x => x.FederalTaxes.Taxes.Value);
+            Family.AddIncomeFor(message.PersonId, message.Amount);
+            update(x => x.Family);
         }
 
         public void notify(SelectedFamilyMember message)
         {
-            Selected = TaxesFor(message.id);
-            update(x => x.Selected);
+            Individual = Family.TaxesFor(message.id);
+            update(x => x.Individual);
         }
-
-        TaxesForIndividual TaxesFor(Guid id)
-        {
-            if (!family.ContainsKey(id))
-                family[id] = new TaxesForIndividual(id, new FederalTaxesViewModel(id));
-            return family[id];
-        }
-
-        IDictionary<Guid, TaxesForIndividual> family = new Dictionary<Guid, TaxesForIndividual>();
     }
 }
\ No newline at end of file
product/desktop.ui/views/TaxSummaryTab.xaml
@@ -2,18 +2,18 @@
              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" xmlns:controls="clr-namespace:solidware.financials.windows.ui.views.controls" mc:Ignorable="d" >
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" >
     <DockPanel MinWidth="1024">
         <StackPanel>
             <StackPanel Margin="5,5,5,5">
             <Label FontWeight="Bold">Income</Label>
             <DockPanel>
                 <Label Width="100">Individual:</Label>
-                <Label Content="{Binding Path=Selected.TotalIncome.Value}" FontWeight="Bold"></Label>
+                <Label Content="{Binding Path=Individual.Income.Value}" FontWeight="Bold"></Label>
             </DockPanel>
             <DockPanel>
                 <Label Width="100">Family:</Label>
-                <Label Content="{Binding Path=FamilyIncome.Value}" FontWeight="Bold"></Label>
+                <Label Content="{Binding Path=Family.Income.Value}" FontWeight="Bold" Foreground="Green"></Label>
             </DockPanel>
             </StackPanel>
             <DockPanel LastChildFill="False" HorizontalAlignment="Stretch">
@@ -21,11 +21,11 @@
             <StackPanel Width="500">
                 <DockPanel>
                     <Label Width="100">Individual:</Label>
-                    <Label Content="{Binding Path=Selected.FederalTaxes.Taxes.Value}" ContentStringFormat="{}{0:C}" FontWeight="Bold"/>
+                    <Label Content="{Binding Path=Individual.FederalTaxes.Taxes.Value}" ContentStringFormat="{}{0:C}" FontWeight="Bold"/>
                 </DockPanel>
                 <DockPanel>
                     <Label Width="100">Family:</Label>
-                    <Label Content="{Binding Path=TotalFamilyFederalTaxes}" FontWeight="Bold"/>
+                    <Label Content="{Binding Path=Family.FederalTaxes.Value}" FontWeight="Bold" Foreground="Red" />
                 </DockPanel>
                 <Expander Header="Tax Rates">
                 <StackPanel>
@@ -52,7 +52,7 @@
                 </Expander>
                 <DockPanel>
                     <Label Width="100">Individual:</Label>
-                    <Label Content="{Binding Path=Selected.ProvincialTaxes}" FontWeight="Bold"/>
+                    <Label Content="{Binding Path=Individual.ProvincialTaxes}" FontWeight="Bold"/>
                 </DockPanel>
             </StackPanel>
             </DockPanel>
product/desktop.ui/solidware.financials.csproj
@@ -138,6 +138,7 @@
     <Compile Include="presenters\Money.cs" />
     <Compile Include="presenters\specifications\IfFamilyMemberIsSelected.cs" />
     <Compile Include="presenters\ButtonBarPresenter.cs" />
+    <Compile Include="presenters\TaxesForFamily.cs" />
     <Compile Include="presenters\TaxSummaryPresenter.cs" />
     <Compile Include="presenters\StatusBarPresenter.cs" />
     <Compile Include="presenters\ToastViewModel.cs" />