main
 1using System;
 2using gorilla.utility;
 3using solidware.financials.infrastructure;
 4using solidware.financials.messages;
 5using solidware.financials.windows.ui.events;
 6using solidware.financials.windows.ui.presenters.specifications;
 7
 8namespace solidware.financials.windows.ui.presenters
 9{
10    public class AddNewIncomeViewModel : DialogPresenter
11    {
12        UICommandBuilder builder;
13
14        public AddNewIncomeViewModel(UICommandBuilder builder)
15        {
16            this.builder = builder;
17        }
18
19        public void present()
20        {
21            Add = builder.build<AddIncomeCommand, IfFamilyMemberIsSelected<AddNewIncomeViewModel>>(this);
22            Cancel = builder.build<CancelCommand>(this);
23            date = Clock.now();
24        }
25
26        public virtual decimal amount { get; set; }
27        public virtual DateTime date { get; set; }
28        public ObservableCommand Add { get; set; }
29        public ObservableCommand Cancel { get; set; }
30        public virtual Action close { get; set; }
31
32        public class AddIncomeCommand : UICommand<AddNewIncomeViewModel>
33        {
34            ServiceBus bus;
35            ApplicationState applicationState;
36
37            public AddIncomeCommand(ServiceBus bus, ApplicationState applicationState)
38            {
39                this.bus = bus;
40                this.applicationState = applicationState;
41            }
42
43            public override void run(AddNewIncomeViewModel presenter)
44            {
45                bus.publish(new AddIncomeCommandMessage
46                            {
47                                Amount = presenter.amount,
48                                PersonId = applicationState.PullOut<SelectedFamilyMember>().id,
49                                Date = presenter.date,
50                            });
51                presenter.close();
52            }
53        }
54
55    }
56}