PageRenderTime 27ms CodeModel.GetById 18ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

/V4/StockTrader RI/Desktop/StockTraderRI.Modules.Position/PositionSummary/PositionSummaryItem.cs

#
C# | 132 lines | 101 code | 15 blank | 16 comment | 6 complexity | e2cc6b2aaed75e387676f2f22b0af346 MD5 | raw file
  1//===================================================================================
  2// Microsoft patterns & practices
  3// Composite Application Guidance for Windows Presentation Foundation and Silverlight
  4//===================================================================================
  5// Copyright (c) Microsoft Corporation.  All rights reserved.
  6// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
  7// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
  8// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  9// FITNESS FOR A PARTICULAR PURPOSE.
 10//===================================================================================
 11// The example companies, organizations, products, domain names,
 12// e-mail addresses, logos, people, places, and events depicted
 13// herein are fictitious.  No association with any real company,
 14// organization, product, domain name, email address, logo, person,
 15// places, or events is intended or should be inferred.
 16//===================================================================================
 17using Microsoft.Practices.Prism.ViewModel;
 18
 19namespace StockTraderRI.Modules.Position.PositionSummary
 20{
 21    public class PositionSummaryItem : NotificationObject
 22    {
 23        public PositionSummaryItem(string tickerSymbol, decimal costBasis, long shares, decimal currentPrice)
 24        {
 25            TickerSymbol = tickerSymbol;
 26            CostBasis = costBasis;
 27            Shares = shares;
 28            CurrentPrice = currentPrice;
 29        }
 30
 31        private string _tickerSymbol;
 32
 33        public string TickerSymbol
 34        {
 35            get
 36            {
 37                return _tickerSymbol;
 38            }
 39            set
 40            {
 41                if (value == null)
 42                {
 43                    value = string.Empty;
 44                }
 45
 46                if (!value.Equals(_tickerSymbol))
 47                {
 48                    _tickerSymbol = value;
 49                    this.RaisePropertyChanged(() => this.TickerSymbol);
 50                }
 51            }
 52        }
 53
 54
 55        private decimal _costBasis;
 56
 57        public decimal CostBasis
 58        {
 59            get
 60            {
 61                return _costBasis;
 62            }
 63            set
 64            {
 65                if (!value.Equals(_costBasis))
 66                {
 67                    _costBasis = value;
 68                    this.RaisePropertyChanged(() => this.CostBasis);
 69                    this.RaisePropertyChanged(() => this.GainLossPercent);
 70                }
 71            }
 72        }
 73
 74
 75        private long _shares;
 76
 77        public long Shares
 78        {
 79            get
 80            {
 81                return _shares;
 82            }
 83            set
 84            {
 85                if (!value.Equals(_shares))
 86                {
 87                    _shares = value;
 88                    this.RaisePropertyChanged(() => this.Shares);
 89                    this.RaisePropertyChanged(() => this.MarketValue);
 90                    this.RaisePropertyChanged(() => this.GainLossPercent);
 91                }
 92            }
 93        }
 94
 95
 96        private decimal _currentPrice;
 97
 98        public decimal CurrentPrice
 99        {
100            get
101            {
102                return _currentPrice;
103            }
104            set
105            {
106                if (!value.Equals(_currentPrice))
107                {
108                    _currentPrice = value;
109                    this.RaisePropertyChanged(() => this.CurrentPrice);
110                    this.RaisePropertyChanged(() => this.MarketValue);
111                    this.RaisePropertyChanged(() => this.GainLossPercent);
112                }
113            }
114        }
115
116        public decimal MarketValue
117        {
118            get
119            {
120                return (_shares * _currentPrice);
121            }
122        }
123
124        public decimal GainLossPercent
125        {
126            get
127            {
128                return ((CurrentPrice * Shares - CostBasis) * 100 / CostBasis);
129            }
130        }
131    }
132}