diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MetroWpf/FxRates.UI/Models/DisplayFxRate.cs	Tue Mar 20 20:18:35 2012 +0000
@@ -0,0 +1,138 @@
+using System;
+using FxRates.Common;
+using GalaSoft.MvvmLight;
+
+namespace FxRates.UI.Models
+{
+	public class DisplayFxRate : ObservableObject, IFxRate
+	{
+		private DisplayFxRate() { }
+
+		public static DisplayFxRate Create(FxRate rate)
+		{
+			var display = new DisplayFxRate()
+				{
+					Ccy = rate.Ccy,
+					Bid = rate.Bid,
+					Offer = rate.Offer,
+					PreviousOffer = rate.PreviousOffer,
+					Timestamp = rate.Timestamp,
+					Spread = getSpread(rate),
+          Delta = getDelta(rate)
+				};
+
+      return display;
+		}
+
+		public void Update(FxRate rate)
+		{
+			this.Bid = rate.Bid;
+			this.Offer = rate.Offer;
+			this.PreviousOffer = rate.PreviousOffer;
+			this.Timestamp = rate.Timestamp;
+			this.Spread = getSpread(rate);
+			this.Delta = getDelta(rate);
+		}
+
+		private static decimal getSpread(IFxRate rate)
+		{
+			return Math.Round(rate.Offer - rate.Bid, 4);
+		}
+
+		private static decimal getDelta(IFxRate rate)
+		{
+			return Math.Round(rate.Offer - rate.PreviousOffer, 4);
+		}
+
+		public const string CcyPropertyName = "Ccy";
+		private Ccy _ccy;
+		public Ccy Ccy
+		{
+			get { return _ccy; }
+      private set
+			{
+				if (_ccy == value) return;
+				_ccy = value;
+				RaisePropertyChanged(CcyPropertyName);
+			}
+		}
+
+		public const string BidPropertyName = "Bid";
+		private decimal _bid = 0;
+		public decimal Bid
+		{
+			get { return _bid; }
+      private set
+			{
+				if (_bid == value) return;
+				_bid = value;
+				RaisePropertyChanged(BidPropertyName);
+			}
+		}
+
+		public const string OfferPropertyName = "Offer";
+		private decimal _offer = 0;
+		public decimal Offer
+		{
+			get { return _offer; }
+      private set
+			{
+				if (_offer == value) return;
+				_offer = value;
+				RaisePropertyChanged(OfferPropertyName);
+			}
+		}
+
+		public const string PreviousOfferPropertyName = "PreviousOffer";
+		private decimal _previousOffer = 0;
+		public decimal PreviousOffer
+		{
+			get { return _previousOffer; }
+      private set
+			{
+				if (_previousOffer == value) return;
+				_previousOffer = value;
+				RaisePropertyChanged(PreviousOfferPropertyName);
+			}
+		}
+
+		public const string DeltaPropertyName = "Delta";
+		private decimal _delta = 0;
+		public decimal Delta
+		{
+			get { return _delta; }
+      private set
+			{
+				if (_delta == value) return;
+				_delta = value;
+				RaisePropertyChanged(DeltaPropertyName);
+			}
+		}
+
+		public const string SpreadPropertyName = "Spread";
+		private decimal _spread = 0;
+		public decimal Spread
+		{
+			get { return _spread; }
+      private set
+			{
+				if (_spread == value) return;
+				_spread = value;
+				RaisePropertyChanged(SpreadPropertyName);
+			}
+		}
+
+		public const string TimestampPropertyName = "Timestamp";
+		private DateTime _timestamp = DateTime.MinValue;
+		public DateTime Timestamp
+		{
+			get { return _timestamp;}
+      private set
+			{
+				if (_timestamp == value) return;
+				_timestamp = value;
+				RaisePropertyChanged(TimestampPropertyName);
+			}
+		}
+	}
+}
\ No newline at end of file