private PositionInputModel GetPositionInputModel() { var model = new PositionInputModel(); model.TickerText = this.TickerTextBox.Text; model.PriceText = this.PriceTextBox.Text; model.SharesText = this.SharesTextBox.Text; return(model); }
private Position GetPosition(PositionInputModel positionInputModel) { Position positionToSave; if (_positionId != null) { positionToSave = new Position(_positionId ?? -1); } else { positionToSave = new Position(); } positionToSave.Shares = decimal.Parse(positionInputModel.SharesText); positionToSave.PricePerShare = decimal.Parse(positionInputModel.PriceText); positionToSave.Ticker = positionInputModel.TickerText.ToUpper(); positionToSave.ContainingPortfolioID = _portfolioId; return positionToSave; }
public void Save(PositionInputModel positionInputModel) { var validator = new FormValidator(); validator.AddRequired(() => positionInputModel.TickerText, "Please enter a ticker"); validator.AddValidPositiveDecimal(() => positionInputModel.SharesText, "Please enter a valid, positive number of shares"); validator.AddValidPositiveDecimal(() => positionInputModel.PriceText, "Please enter a valid, positive price per share"); validator.AddValidation(() => ValidateTicker(positionInputModel.TickerText)); var errorMessages = validator.Apply(); if (!errorMessages.Any()) { _portfolioRepository.SavePosition(GetPosition(positionInputModel)); _currentView.GoBackToPortfolioActivity(); } else { _currentView.ShowErrorMessages(errorMessages.ToList()); } }
private Position GetPosition(PositionInputModel positionInputModel) { Position positionToSave; if (_positionId != null) { positionToSave = new Position(_positionId ?? -1); } else { positionToSave = new Position(); } positionToSave.Shares = decimal.Parse(positionInputModel.SharesText); positionToSave.PricePerShare = decimal.Parse(positionInputModel.PriceText); positionToSave.Ticker = positionInputModel.TickerText.ToUpper(); positionToSave.ContainingPortfolioID = _portfolioId; return(positionToSave); }
public void Save(PositionInputModel positionInputModel) { var validator = new FormValidator(); validator.AddRequired(() => positionInputModel.TickerText, "Please enter a ticker"); validator.AddValidPositiveDecimal(() => positionInputModel.SharesText, "Please enter a valid, positive number of shares"); validator.AddValidPositiveDecimal(() => positionInputModel.PriceText, "Please enter a valid, positive price per share"); validator.AddValidation(() => ValidateTicker(positionInputModel.TickerText)); var errorMessages = validator.Apply(); if (!errorMessages.Any()) { _portfolioRepository.SavePosition(GetPosition(positionInputModel)); _currentView.GoBackToPortfolioActivity(); } else { _currentView.ShowErrorMessages(errorMessages.ToList()); } }
private PositionInputModel GetPositionInputModel() { var model = new PositionInputModel(); model.TickerText = this.TickerTextBox.Text; model.PriceText = this.PriceTextBox.Text; model.SharesText = this.SharesTextBox.Text; return model; }