Пример #1
0
        public static SchemeContextViewModel GetSchemeContext(int schemeID)
        {
            SchemeContextViewModel vm = new SchemeContextViewModel();

            try
            {
                using (_certonaService = new CertonaServiceClient())
                {
                    try
                    {
                        UserDTO user       = FormsAuthenticationWrapper.User;
                        var     getRequest = new GetSchemeContextRequest()
                        {
                            SchemeID = schemeID, User = user
                        };
                        var getResponse = _certonaService.GetSchemeContext(getRequest);

                        if (getResponse.Success && getResponse.SchemeEventsContexts != null)
                        {
                            foreach (var dto in getResponse.SchemeEventsContexts)
                            {
                                if (dto.Name == "Current Product")
                                {
                                    vm.InclusionCriteria.IncludeCurrentAssets = dto.SourceObject;
                                    vm.InclusionCriteria.IncludeMaxCount      = dto.SourceObjectMaxCount;
                                    vm.InclusionCriteria.IncludeDaysPast      = dto.SourceObjectDaysPast;
                                    vm.InclusionCriteria.IncludeLastPages     = dto.SourceObjectLastPages;
                                    // this data comes across on both, so last one wins
                                    vm.RulesCriteria.RulesDaysPast  = dto.RulesDaysPast;
                                    vm.RulesCriteria.RulesLastPages = dto.RulesLastPages;
                                    vm.RulesCriteria.RulesMaxCount  = dto.RulesMaxCount;
                                }
                                if (dto.Name == "Last Product")
                                {
                                    vm.ExclusionCriteria.ExcludeCurrentAssets = dto.ExcludeItem;
                                    vm.ExclusionCriteria.ExcludeMaxCount      = dto.ExcludeItemMaxCount;
                                    vm.ExclusionCriteria.ExcludeDaysPast      = dto.ExcludeItemDaysPast;
                                    vm.ExclusionCriteria.ExcludeLastPages     = dto.ExcludeItemLastPages;
                                    // this data comes across on both, so last one wins
                                    vm.RulesCriteria.RulesDaysPast  = dto.RulesDaysPast;
                                    vm.RulesCriteria.RulesLastPages = dto.RulesLastPages;
                                    vm.RulesCriteria.RulesMaxCount  = dto.RulesMaxCount;
                                }
                            }
                        }

                        //
                        var request = new GetSchemeEventContextRequest()
                        {
                            SchemeID = schemeID, User = user
                        };
                        var response = _certonaService.GetSchemeEventContext(request);
                        if (response.Success && response.SchemeEventsContexts != null)
                        {
                            int counter = 0;
                            foreach (var dto in response.SchemeEventsContexts)
                            {
                                counter++;
                                AddSchemeEventContext(vm, counter, dto);
                            }
                            // The lists should be rendered in order
                            vm.ExclusionCriteria.EventContexts = vm.ExclusionCriteria.EventContexts.OrderBy(r => r.DisplayOrder).ThenBy(r => r.EventName).ToList();
                            vm.InclusionCriteria.EventContexts = vm.InclusionCriteria.EventContexts.OrderBy(r => r.DisplayOrder).ThenBy(r => r.EventName).ToList();
                            vm.RulesCriteria.EventContexts     = vm.RulesCriteria.EventContexts.OrderBy(r => r.DisplayOrder).ThenBy(r => r.EventName).ToList();
                        }
                    }
                    catch (TimeoutException exception)
                    {
                        _certonaService.Abort();
                        throw;
                    }
                    catch (CommunicationException exception)
                    {
                        _certonaService.Abort();
                        throw;
                    }
                }
            }
            catch (Exception ex)
            {
            }

            return(vm);
        }