Exemple #1
0
        public static GetAssetsModelResponse GetCatalogItems(DataSourceRequest request, string catalogId)
        {
            var ret = new GetAssetsModelResponse();

            try
            {
                using (_certonaService = new CertonaServiceClient())
                {
                    try
                    {
                        UserDTO user            = FormsAuthenticationWrapper.User;
                        var     getItemsRequest = new GetCatalogItemsRequest
                        {
                            CatalogID = catalogId,
                            User      = user
                        };

                        foreach (FilterDescriptor filter in request.Filters)
                        {
                            switch (filter.Member.ToLower())
                            {
                            case "description":
                                getItemsRequest.NameValueFilter   = filter.Value.ToString();
                                getItemsRequest.NameValueOperator = "Contains";
                                break;

                            case "account_item_id":
                                getItemsRequest.IDValueFilter   = filter.Value.ToString();
                                getItemsRequest.IDValueOperator = "Starts With";
                                break;

                            case "disabled":
                                getItemsRequest.StatusValueFilter = filter.Value.ToString() == "1";
                                break;
                            }
                        }

                        var sbSort = new StringBuilder();

                        foreach (var sort in request.Sorts)
                        {
                            var member = "";
                            switch (sort.Member.ToLower())
                            {
                            case "account_item_id":
                                member = "Account_Item_ID";
                                break;

                            case "description":
                                member = "Description";
                                break;

                            default:
                                member = "Disabled";
                                break;
                            }
                            sbSort.AppendFormat(
                                sort.SortDirection == ListSortDirection.Ascending ? "{0} asc, " : "{0} desc, ",
                                member);
                        }

                        var trimChars = new char[2];
                        trimChars[0] = ',';
                        trimChars[1] = ' ';

                        getItemsRequest.SortColumns = sbSort.ToString().TrimEnd(trimChars);
                        getItemsRequest.Page        = request.Page;
                        getItemsRequest.PageSize    = request.PageSize;

                        var response = _certonaService.GetCatalogItems(getItemsRequest);

                        if (response.Success)
                        {
                            ret.Items = response.Items;
                            ret.Total = response.Total;
                        }
                        else
                        {
                            ret.Total = 0;
                        }
                    }
                    catch (TimeoutException exception)
                    {
                        _certonaService.Abort();
                        throw;
                    }
                    catch (CommunicationException exception)
                    {
                        _certonaService.Abort();
                        throw;
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return(ret);
        }