Esempio n. 1
0
        /// <summary>
        /// 查询数据
        /// </summary>
        /// <returns></returns>
        public ActionResult List(string BrandName, int?CategoryId, int?storeId, int?storageId, int?seasonId)
        {
            GridRequest request    = new GridRequest(Request);
            var         storeIds   = _storeContract.FilterStoreId(AuthorityHelper.OperatorId, _administratorContract, storeId);
            var         storageIds = _storageContract.FilterStorageId(AuthorityHelper.OperatorId, _administratorContract, storageId);

            Expression <Func <Inventory, bool> > predicate;

            CacheAccess.SaveHttpContextState();

            try
            {
                predicate = FilterHelper.GetExpression <Inventory>(request.FilterGroup);

                var inventoryQuery = CacheAccess.GetAccessibleInventorys(_inventoryContract, _storeContract)
                                     .Where(i => !i.IsLock && i.Status == InventoryStatus.Default)
                                     .Where(i => storeIds.Contains(i.StoreId))
                                     .Where(i => storageIds.Contains(i.StorageId))
                                     .Where(predicate)
                                     .Include(i => i.Product)
                                     .Include(i => i.Product.Size)
                                     .Include(i => i.Product.Color)
                                     .Include(i => i.Product.ProductOriginNumber)
                                     .Include(i => i.Product.ProductOriginNumber.Season)
                                     .Include(i => i.Product.ProductOriginNumber.Category)
                                     .Include(i => i.Product.ProductOriginNumber.Brand);

                if (!string.IsNullOrEmpty(BrandName))
                {
                    inventoryQuery = inventoryQuery.Where(i => i.Product.ProductOriginNumber.Brand.BrandName == BrandName);
                }

                if (CategoryId.HasValue)
                {
                    inventoryQuery = inventoryQuery.Where(i => i.Product.ProductOriginNumber.Category.ParentId == CategoryId.Value);
                }
                if (seasonId.HasValue)
                {
                    inventoryQuery = inventoryQuery.Where(i => i.Product.ProductOriginNumber.SeasonId == seasonId.Value);
                }


                //获取分页信息
                var groupQuery          = inventoryQuery.GroupBy(i => i.Product.ProductOriginNumber.BigProdNum);
                var inventoryTotalCount = groupQuery.Count();
                var groupedDataList     = groupQuery.OrderBy(g => g.Key)
                                          .Skip(request.PageCondition.PageIndex)
                                          .Take(request.PageCondition.PageSize)
                                          .ToList();

                var li    = new List <object>();
                var index = 0;
                foreach (var groupItem in groupedDataList)
                {
                    //构造父节点
                    li.Add(new
                    {
                        ParentId       = "",
                        Id             = "par" + index,
                        BigProdNum     = groupItem.Key,
                        BrandName      = groupItem.First().Product.ProductOriginNumber.Brand.BrandName,
                        CategoryName   = groupItem.First().Product.ProductOriginNumber.Category.CategoryName,
                        ColorName      = string.Empty,
                        IconPath       = string.Empty,
                        ThumbnailPath  = groupItem.First().Product.ProductOriginNumber.ThumbnailPath,
                        SizeName       = string.Empty,
                        Quantity       = groupItem.Count(),
                        StoreName      = "",
                        StorageName    = "",
                        ProductName    = "",
                        TagPrice       = "",
                        RetailPrice    = "",
                        WholesalePrice = "",
                        PurchasePrice  = "",
                        IsDeleted      = "",
                        IsEnabled      = "",
                        UpdatedTime    = "",
                        CreatedTime    = "",
                        SeasonName     = groupItem.First().Product.ProductOriginNumber.Season.SeasonName
                    });

                    // 构造子节点
                    li.AddRange(
                        groupItem.GroupBy(h => h.ProductNumber).Select(c => new
                    {
                        ParentId      = "par" + index,
                        Id            = c.First().Id,
                        BigProdNum    = "",
                        ProductNumber = c.Key,
                        StoreName     = c.First().Store.StoreName,
                        StorageName   = c.First().Storage.StorageName,
                        ProductName   = c.First().Product.ProductName,
                        BrandName     = c.First().Product.ProductOriginNumber.Brand.BrandName,
                        CategoryName  = c.First().Product.ProductOriginNumber.Category.CategoryName,
                        SeasonName    = string.Empty,
                        ColorName     = c.First().Product.Color.ColorName,
                        SizeName      = c.First().Product.Size.SizeName,
                        IconPath      = c.First().Product.Color.IconPath,
                        Quantity      = c.Count(),
                        TagPrice      = c.First().Product.ProductOriginNumber.TagPrice,
                        ThumbnailPath = c.First().Product.ThumbnailPath ?? c.First().Product.ProductOriginNumber.ThumbnailPath,
                        IsDeleted     = c.First().IsDeleted,
                        IsEnabled     = c.First().IsEnabled,
                        UpdatedTime   = c.First().UpdatedTime,
                        CreatedTime   = c.First().CreatedTime
                    }));
                    index++;
                }
                var data = new GridDataResul <object>(li, inventoryTotalCount, request.RequestInfo)
                {
                    Other = inventoryQuery.Count().ToString() + "|" + groupedDataList.Sum(g => g.Count())
                };
                return(Json(data, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                return(Json(new GridData <object>(new List <string>(), 0, request.RequestInfo)));
            }
        }