Esempio n. 1
0
        /// <summary>
        /// Gets view model for 'edit strategy group' form
        /// </summary>
        public StrategyGroupViewModel GetEditStrategyGroup(int strategyGroupId)
        {
            StrategyGroup          strategyGroup     = _strategyGroupService.GetById(strategyGroupId);
            List <SelectListItem>  strategyOptions   = GetStrategyOptions(strategyGroup.CallStrategyId, strategyGroup.PutStrategyId);
            StrategyGroupViewModel editStrategyGroup = Mapper.Map <StrategyGroup, StrategyGroupViewModel>(strategyGroup);

            editStrategyGroup.StrategyOptions = strategyOptions;
            return(editStrategyGroup);
        }
Esempio n. 2
0
        public StrategyGroupForDisplay GetById(int id)
        {
            StrategyGroup           strategyGroup           = _strategyGroupService.GetById(id);
            StrategyGroupForDisplay strategyGroupForDisplay = Mapper.Map <StrategyGroup, StrategyGroupForDisplay>(strategyGroup);

            if (strategyGroupForDisplay == null)
            {
                ThrowNotFoundException();
            }
            return(strategyGroupForDisplay);
        }
Esempio n. 3
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)));
        }