comparison MetroWpf/FxRates.UI/Models/DisplayFxRate.cs @ 24:a8b50a087544

Stocks and FxRates working, new menu introduced. Working nicely so far
author adminsh@apollo
date Tue, 20 Mar 2012 20:18:35 +0000
parents
children
comparison
equal deleted inserted replaced
23:399398841fd0 24:a8b50a087544
1 using System;
2 using FxRates.Common;
3 using GalaSoft.MvvmLight;
4
5 namespace FxRates.UI.Models
6 {
7 public class DisplayFxRate : ObservableObject, IFxRate
8 {
9 private DisplayFxRate() { }
10
11 public static DisplayFxRate Create(FxRate rate)
12 {
13 var display = new DisplayFxRate()
14 {
15 Ccy = rate.Ccy,
16 Bid = rate.Bid,
17 Offer = rate.Offer,
18 PreviousOffer = rate.PreviousOffer,
19 Timestamp = rate.Timestamp,
20 Spread = getSpread(rate),
21 Delta = getDelta(rate)
22 };
23
24 return display;
25 }
26
27 public void Update(FxRate rate)
28 {
29 this.Bid = rate.Bid;
30 this.Offer = rate.Offer;
31 this.PreviousOffer = rate.PreviousOffer;
32 this.Timestamp = rate.Timestamp;
33 this.Spread = getSpread(rate);
34 this.Delta = getDelta(rate);
35 }
36
37 private static decimal getSpread(IFxRate rate)
38 {
39 return Math.Round(rate.Offer - rate.Bid, 4);
40 }
41
42 private static decimal getDelta(IFxRate rate)
43 {
44 return Math.Round(rate.Offer - rate.PreviousOffer, 4);
45 }
46
47 public const string CcyPropertyName = "Ccy";
48 private Ccy _ccy;
49 public Ccy Ccy
50 {
51 get { return _ccy; }
52 private set
53 {
54 if (_ccy == value) return;
55 _ccy = value;
56 RaisePropertyChanged(CcyPropertyName);
57 }
58 }
59
60 public const string BidPropertyName = "Bid";
61 private decimal _bid = 0;
62 public decimal Bid
63 {
64 get { return _bid; }
65 private set
66 {
67 if (_bid == value) return;
68 _bid = value;
69 RaisePropertyChanged(BidPropertyName);
70 }
71 }
72
73 public const string OfferPropertyName = "Offer";
74 private decimal _offer = 0;
75 public decimal Offer
76 {
77 get { return _offer; }
78 private set
79 {
80 if (_offer == value) return;
81 _offer = value;
82 RaisePropertyChanged(OfferPropertyName);
83 }
84 }
85
86 public const string PreviousOfferPropertyName = "PreviousOffer";
87 private decimal _previousOffer = 0;
88 public decimal PreviousOffer
89 {
90 get { return _previousOffer; }
91 private set
92 {
93 if (_previousOffer == value) return;
94 _previousOffer = value;
95 RaisePropertyChanged(PreviousOfferPropertyName);
96 }
97 }
98
99 public const string DeltaPropertyName = "Delta";
100 private decimal _delta = 0;
101 public decimal Delta
102 {
103 get { return _delta; }
104 private set
105 {
106 if (_delta == value) return;
107 _delta = value;
108 RaisePropertyChanged(DeltaPropertyName);
109 }
110 }
111
112 public const string SpreadPropertyName = "Spread";
113 private decimal _spread = 0;
114 public decimal Spread
115 {
116 get { return _spread; }
117 private set
118 {
119 if (_spread == value) return;
120 _spread = value;
121 RaisePropertyChanged(SpreadPropertyName);
122 }
123 }
124
125 public const string TimestampPropertyName = "Timestamp";
126 private DateTime _timestamp = DateTime.MinValue;
127 public DateTime Timestamp
128 {
129 get { return _timestamp;}
130 private set
131 {
132 if (_timestamp == value) return;
133 _timestamp = value;
134 RaisePropertyChanged(TimestampPropertyName);
135 }
136 }
137 }
138 }