Exemple #1
0
        private List <SelectListItem> GetStrategyOptions(int?callStrategyId = null, int?putStrategyId = null)
        {
            List <SelectListItem> strategyOptions = _strategyGroupService.GetNotGroupedStrategies(callStrategyId, putStrategyId).ConvertAll(m => new SelectListItem
            {
                Value = m.Id.ToString(CultureInfo.InvariantCulture),
                Text  = m.Name
            });

            return(strategyOptions);
        }
Exemple #2
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (value == null)
            {
                return(ValidationResult.Success);
            }

            int callOrPutStrategyId = int.Parse(value.ToString());
            int strategyId          = int.Parse(validationContext.ObjectType.GetProperty("Id").GetValue(validationContext.ObjectInstance, null).ToString());
            int?originalCallStrategyId;
            int?originalPutStrategyId;

            IStrategyGroupService strategyGroupService = ObjectFactory.GetInstance <IStrategyGroupService>();

            if (strategyId == 0)
            {
                originalCallStrategyId = null;
                originalPutStrategyId  = null;
            }
            else
            {
                StrategyGroup strategyGroup = strategyGroupService.GetById(strategyId);
                originalCallStrategyId = strategyGroup.CallStrategyId;
                originalPutStrategyId  = strategyGroup.PutStrategyId;
            }

            List <Strategy> notGroupedStrategies  = strategyGroupService.GetNotGroupedStrategies(originalCallStrategyId, originalPutStrategyId);
            List <int>      notGroupedStrategyIds = notGroupedStrategies.Select(m => m.Id).ToList();

            if (notGroupedStrategyIds.Contains(callOrPutStrategyId))
            {
                return(ValidationResult.Success);
            }

            string displayName = DisplayNameHelper.GetDisplayName(validationContext.DisplayName, validationContext);

            return(new ValidationResult(FormatErrorMessage(displayName)));
        }