Esempio n. 1
0
 /// <summary>
 /// 获取优惠券种类
 /// </summary>
 /// <returns>list列表</returns>
 public ActionResult 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,
         BrandId = pp.BrandId,
         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 View(list);
 }
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <returns></returns>
        public HttpResponseMessage GetList()
        {
            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,
                p.Intro
            }).ToList().Select(pp => new CouponCategoryModel
            {
                Id = pp.Id,
                Name = pp.Name,
                Price = pp.Price,
                Count = pp.Count,
                ReMark = pp.ReMark,
                BrandId = pp.BrandId,
                Intro = pp.Intro,
                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);
        }
        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;
        }
 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();
 }
 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 });
 }