Esempio n. 1
0
        public static SegmentItemsGridViewModel GetSegmentItems(int modelID, int segmentID)
        {
            var viewModel = new SegmentItemsGridViewModel
            {
                SegmentID = segmentID
            };

            try
            {
                using (_certonaService = new CertonaServiceClient())
                {
                    try
                    {
                        var request = new GetSegmentItemsRequest
                        {
                            ModelID   = modelID,
                            SegmentID = segmentID,
                            User      = (UserDTO)HttpContext.Current.Session["user"]
                        };
                        GetSegmentItemsResponse response = _certonaService.GetSegmentItems(request);

                        if (response.SegmentItems.Count > 0)
                        {
                            viewModel.AccountItemIDDisplay = response.SegmentItems[0].AccountItemIdFieldValue;
                            viewModel.DescriptionDisplay   = response.SegmentItems[0].AccountDescriptionFieldValue;
                        }

                        if (response.Errors != null && response.Errors.Count != 0)
                        {
                            viewModel.Errors = response.Errors.ToList();
                        }

                        foreach (SegmentItemDTO segment in response.SegmentItems)
                        {
                            viewModel.SegmentItems.Add(new SegmentItemsViewModel
                            {
                                ItemID    = segment.ItemID,
                                Name      = segment.AccountDescriptionValue,
                                Score     = segment.Score,
                                SegmentID = segment.SegmentID,
                                SKU       = segment.AccountItemIDValue
                            });
                        }
                    }
                    catch (TimeoutException exception)
                    {
                        _certonaService.Abort();
                        throw;
                    }
                    catch (CommunicationException exception)
                    {
                        _certonaService.Abort();
                        throw;
                    }
                }
            }
            catch (Exception ex)
            {
                viewModel.Errors.Add(new ErrorResult
                {
                    Description = ex.Message
                });
            }

            return(viewModel);
        }