コード例 #1
0
        public IQueryable <CouponCategory> GetCouponCategoriesByCondition(CouponCategorySearchCondition condition)
        {
            var query = _repository.Table;

            if (condition.BrandId.HasValue)
            {
                query = query.Where(c => c.BrandId == condition.BrandId);
            }
            if (!string.IsNullOrEmpty(condition.Name))
            {
                query = query.Where(c => condition.Name == c.Name);
            }
            if (condition.OrderBy.HasValue)
            {
                switch (condition.OrderBy.Value)
                {
                case EnumCouponCategorySearchOrderBy.OrderById:
                    query = condition.IsDescending ? query.OrderByDescending(q => q.Id) : query.OrderBy(q => q.Id);
                    break;
                }
            }
            else
            {
                query = query.OrderBy(q => q.Id);
            }
            if (condition.Page.HasValue && condition.PageSize.HasValue)
            {
                query = query.Skip((condition.Page.Value - 1) * condition.PageSize.Value).Take(condition.PageSize.Value);
            }
            return(query);
        }
コード例 #2
0
        /// <summary>
        /// 获取优惠券种类
        /// </summary>
        /// <returns>list列表</returns>
        public HttpResponseMessage Coupons()
        {
            var Con = new CouponCategorySearchCondition
            {
                OrderBy = EnumCouponCategorySearchOrderBy.OrderById
            };
            var list = _couponCategoryService.GetCouponCategoriesByCondition(Con).Select(p => new
            {
                p.Id,
                p.BrandId,
                p.Name,
                p.ReMark,
                p.Price,
                p.Count
            }).ToList().Select(pp => new CouponCategoryModel
            {
                Id               = pp.Id,
                Name             = pp.Name,
                Price            = pp.Price,
                Count            = pp.Count,
                ReMark           = pp.ReMark,
                BrandImg         = _productBrandService.GetProductBrandById(pp.BrandId).Bimg,
                SubTitle         = _productBrandService.GetProductBrandById(pp.BrandId).SubTitle,
                ProductParamater = _productBrandService.GetProductBrandById(pp.BrandId).ParameterEntities.ToDictionary(k => k.Parametername, v => v.Parametervaule)
            });

            return(PageHelper.toJson(list));
        }
コード例 #3
0
        public int GetCouponCategoriesCountByCondition(CouponCategorySearchCondition condition)
        {
            var query = _repository.Table;

            if (condition.BrandId.HasValue)
            {
                query = query.Where(c => c.BrandId == condition.BrandId);
            }
            if (!string.IsNullOrEmpty(condition.Name))
            {
                query = query.Where(c => condition.Name == c.Name);
            }
            return(query.Count());
        }
コード例 #4
0
        public HttpResponseMessage Index(int page, int pageSize, string name = null)
        {
            var condition = new CouponCategorySearchCondition
            {
                Name     = name,
                Page     = page,
                PageSize = pageSize,
                OrderBy  = EnumCouponCategorySearchOrderBy.OrderById
            };
            var couponCategory = _couponCategoryService.GetCouponCategoriesByCondition(condition).Select(p => new
            {
                p.Id,
                p.Name,
                p.Count,
                p.Price,
                p.ReMark
            }).ToList();
            var count = _couponCategoryService.GetCouponCategoriesCountByCondition(condition);

            return(PageHelper.toJson(new { List = couponCategory, TotalCount = count, Condition = condition }));
        }