示例#1
0
        public List <ProductCarCateItem> Get([FromUri] ProductCarCatePageOption option = null)
        {
            var result           = new List <ProductCarCateItem>();
            var parentCategories = CarCateService.GetAll().Where(x => !x.Deleted && x.ParentId == option.CarCateId).ToList();

            foreach (var category in parentCategories)
            {
                var categories        = CarCateService.GetAll().Where(x => !x.Deleted && x.ParentId == category.Id).ToList();
                var ids               = categories.Select(x => x.Id).ToList();
                var productCarCateIds = ProductCarCateService.GetAll().Where(x => x.ProductId == option.ProductId && ids.Contains(x.CarCateId)).Select(x => x.CarCateId).ToList();
                result.AddRange(categories.Select(x => new ProductCarCateItem()
                {
                    CarCateId = x.Id,
                    ProductId = option.ProductId,
                    Id        = productCarCateIds.Contains(x.Id) ? x.Id : 0,
                    Selected  = productCarCateIds.Contains(x.Id),
                    CarName   = category.Name + " | " + x.Name
                }).ToList());
            }
            return(result);
        }
示例#2
0
        public ApiListResult <CarCateDTO> Get([FromUri] AntPageOption option = null)
        {
            var query = CarCateService.GetAll().Where(x => !x.Deleted).ProjectTo <CarCateDTO>();

            if (option != null)
            {
                if (!string.IsNullOrEmpty(option.SortField))
                {
                    //for example
                    if (option.SortField == "id")
                    {
                        if (option.SortOrder == PageSortTyoe.DESC)
                        {
                            query = query.OrderByDescending(x => x.Id);
                        }
                        else
                        {
                            query = query.OrderBy(x => x.Id);
                        }
                    }
                }

                if (option.Page > 0 && option.Results > 0)
                {
                    if (string.IsNullOrEmpty(option.SortField))
                    {
                        query = query.OrderBy(x => x.Level).ThenBy(x => x.Id);
                    }
                }
            }
            else
            {
                query = query.OrderBy(x => x.Id);
            }
            var count  = query.Count();
            var result = query.Paging <CarCateDTO>(option.Page - 1, option.Results, count);

            return(new ApiListResult <CarCateDTO>(result, result.PageIndex, result.PageSize, count));
        }