private IEnumerable <string> Validate(Portfolio portfolioToSave)
        {
            var validator = new FormValidator();

            validator.AddRequired(() => portfolioToSave.Name, "Please enter a portfolio name");
            validator.AddValidation(() => IsDuplicateName(portfolioToSave));

            return(validator.Apply().ToList());
        }
Exemple #2
0
        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());
            }
        }