summaryrefslogtreecommitdiff
path: root/product/desktop.ui/presenters/StockViewModel.cs
blob: 00139cd62549a400c78d86c72ceb90e4ae4f13a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using solidware.financials.windows.ui.views;
using solidware.financials.windows.ui.views.controls;

namespace solidware.financials.windows.ui.presenters
{
    public class StockViewModel : Presenter
    {
        UICommandBuilder builder;

        public StockViewModel(string symbol, UICommandBuilder builder)
        {
            this.builder = builder;
            Symbol = symbol;
            Price = Money.Null;
            AdditionalInformation = new SimpleCommand(() => {});
        }

        public virtual string Symbol { get; set; }
        public Observable<Money> Price { get; set; }
        public ObservableCommand AdditionalInformation { get; set; }

        public void present()
        {
            AdditionalInformation = builder.build<MoreCommand>(this);
        }

        public bool is_for(string symbol)
        {
            return Symbol.Equals(symbol);
        }

        public void change_price_to(decimal price)
        {
            Price.Value = price;
        }

        public class MoreCommand : UICommand<StockViewModel>
        {
            readonly ApplicationController controller;
            readonly SingleStockPresenter.Factory factory;

            public MoreCommand(ApplicationController controller, SingleStockPresenter.Factory factory)
            {
                this.controller = controller;
                this.factory = factory;
            }

            public override void run(StockViewModel presenter)
            {
                controller
                    .load_tab<SingleStockPresenter, SingleStockTab>(factory.create_for(presenter.Symbol));
            }
        }
    }
}