Beispiel #1
0
        public StrategyGroup ToEntity()
        {
            StrategyGroup strategyGroup = Mapper.Map <StrategyGroupViewModel, StrategyGroup>(this);

            if (ImageFile != null)
            {
                // original image
                MemoryStream memoryStream = new MemoryStream();
                ImageFile.InputStream.CopyTo(memoryStream);
                byte[] originalImageContent = memoryStream.ToArray();
                strategyGroup.OriginalImage = new Image
                {
                    Content = originalImageContent,
                    Type    = ImageFile.ContentType
                };

                // thumbnail image
                byte[] thumbnailImageContent = ThumbnailHelper.CreateThumbnail(originalImageContent);
                strategyGroup.ThumbnailImage = new Image
                {
                    Content = thumbnailImageContent,
                    Type    = ImageFile.ContentType
                };
            }

            return(strategyGroup);
        }
Beispiel #2
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);
        }
Beispiel #3
0
        public StrategyGroupForDisplay GetById(int id)
        {
            StrategyGroup           strategyGroup           = _strategyGroupService.GetById(id);
            StrategyGroupForDisplay strategyGroupForDisplay = Mapper.Map <StrategyGroup, StrategyGroupForDisplay>(strategyGroup);

            if (strategyGroupForDisplay == null)
            {
                ThrowNotFoundException();
            }
            return(strategyGroupForDisplay);
        }
        /// <summary>
        /// Delete strategyGroup
        /// </summary>
        /// <param name="strategyGroup">StrategyGroup</param>
        public virtual void DeleteStrategyGroup(StrategyGroup strategyGroup)
        {
            if (strategyGroup == null)
            {
                throw new ArgumentNullException(nameof(strategyGroup));
            }

            _strategyGroupRepository.Delete(strategyGroup);

            //event notification
            _eventPublisher.EntityDeleted(strategyGroup);
        }
        public JsonResult Update(StrategyGroupViewModel editStrategyGroup)
        {
            if (!ModelState.IsValid)
            {
                List <string> errorMessages = GetErrorMessages();
                return(Json(new { success = false, errorMessages }));
            }
            StrategyGroup strategyGroup = editStrategyGroup.ToEntity();

            _strategyGroupService.Update(strategyGroup);
            return(Json(new { success = true }));
        }
        /// <summary>
        /// Inserts strategyGroup
        /// </summary>
        /// <param name="strategyGroup">StrategyGroup</param>
        public virtual void InsertStrategyGroup(StrategyGroup strategyGroup)
        {
            if (strategyGroup == null)
            {
                throw new ArgumentNullException(nameof(strategyGroup));
            }

            if (strategyGroup is IEntityForCaching)
            {
                throw new ArgumentException("Cacheable entities are not supported by Entity Framework");
            }

            _strategyGroupRepository.Insert(strategyGroup);

            //cache
            _cacheManager.RemoveByPattern(ResearchStrategyGroupDefaults.StrategyGroupsPatternCacheKey);
            // _staticCacheManager.RemoveByPattern(ResearchStrategyGroupDefaults.StrategyGroupsPatternCacheKey);

            //event notification
            _eventPublisher.EntityInserted(strategyGroup);
        }
Beispiel #7
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)));
        }
 public void Update(StrategyGroup strategyGroup)
 {
     Uow.StrategyGroups.Update(strategyGroup);
     Uow.Commit();
 }
 public StrategyGroup Create(StrategyGroup strategyGroup)
 {
     Uow.StrategyGroups.Add(strategyGroup);
     Uow.Commit();
     return(strategyGroup);
 }
        public StrategyGroup GetById(int id)
        {
            StrategyGroup strategyGroup = Uow.StrategyGroups.GetById(id);

            return(strategyGroup);
        }