コード例 #1
0
        public ApiResult <PagedList <ProductBrief> > GetProductList([FromQuery] ProductListInput input)
        {
            var query = new ExpressionQuery <Product>();

            query.And(e => e.StoreId == input.StoreId.ToString());
            query.PageIndex    = (int)input.PageIndex;
            query.PageSize     = (int)input.PageSize;
            query.EnablePaging = true;
            query.OrderByDescending(e => e.Id);
            var list = Resolve <IProductService>().GetPagedList(query);

            if (list.Count < 0)
            {
                return(ApiResult.Success(new PagedList <ProductBrief>()));
            }

            var catDict = Resolve <ICategoryService>().GetList().ToDictionary(c => c.Id);

            var ret = list.Select(prd =>
            {
                var brief = new ProductBrief();

                AutoMapping.SetValue(prd, brief);

                brief.CategoryName = catDict.ContainsKey(prd.CategoryId) ? catDict[prd.CategoryId].Name : "未定义";

                return(brief);
            });

            return(ApiResult.Success(PagedList <ProductBrief> .Create(ret, list.RecordCount, list.PageSize, list.PageIndex)));
        }
コード例 #2
0
        protected override Control AddEditor(Control container)
        {
            IEnumerable <ProductBrief> productBriefs;

            try
            {
                ShopperApiClientHelperForN2Admin.AssureLimitedAuthentication(false);
                productBriefs = Context.Current.Container.Resolve <ICatalogApi>().GetProductBriefsAsync().Result;
            }
            catch
            {               // TODO - better error handling, e.g. show an input box
                productBriefs = new ProductBrief[0];
            }

            // here we create the editor control and add it to the page
            var list = new DropDownList
            {
                ID             = Name,
                DataTextField  = "IdAndName",
                DataValueField = "Id",
                DataSource     = productBriefs
            };

            list.DataBind();
            container.Controls.Add(list);
            return(list);
        }