/// <summary>
        /// 获取优惠券
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult OtherCouponOwn(int id)
        {
            if (_workContext.CurrentUser == null)
            {
                return Redirect("http://www.iyookee.cn/#/user/login");
            }
            var couponCategory = _otherCouponCategoryService.GetCouponCategoryById(id);
            var condition = new OtherCouponSearchCondition
            {
                CouponCategoryId = id,
                Status = 0
            };
            var coupon = _otherCouponService.GetCouponByCondition(condition).FirstOrDefault();

            if (coupon != null)
            {
                _otherCouponOwnerService.CreateRecord(_workContext.CurrentUser.Id, coupon.Id);
                coupon.Status = EnumOtherCouponStatus.Owned;
                _otherCouponService.Update(coupon);
                couponCategory.Count = couponCategory.Count - 1;
                _otherCouponCategoryService.UpdateCouponCategory(couponCategory);
                var brand = _productBrandService.GetProductBrandById(couponCategory.BrandId);
                var couponOwn = new CouponCategoryModel
                {
                    Name = couponCategory.Name,
                    Number = coupon.Number,
                    BrandName = brand.Bname
                };
                return View(couponOwn);
            }
            return RedirectToAction("OtherCoupons", "OtherCoupons");
        }
        public IQueryable<Entity.Entity.OtherCoupon.OtherCoupon> GetCouponByCondition(OtherCouponSearchCondition condition)
        {
            var query = _couponRepository.Table;
            try
            {
                if (condition.Ids.HasValue)
                {
                    query = query.Where(q => condition.Ids == q.Id);
                }
                if (!string.IsNullOrEmpty(condition.Number))
                {
                    query = query.Where(q => q.Number == condition.Number);
                }
                if (condition.CouponCategoryId.HasValue)
                {
                    query = query.Where(q => condition.CouponCategoryId == q.CouponCategoryId);
                }
                if (condition.Status.HasValue)
                {
                    query = query.Where(q => (EnumOtherCouponStatus)condition.Status == q.Status);
                }
                if (condition.OrderBy.HasValue)
                {
                    switch (condition.OrderBy.Value)
                    {
                        case EnumOtherCouponSearchOrderBy.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.PageCount.HasValue)
                {
                    query = query.Skip((condition.Page.Value - 1) * condition.PageCount.Value).Take(condition.PageCount.Value);
                }
                return query;
            }

            catch (Exception e)
            {
                _log.Error(e, "数据库操作出错");
                return null;
            }
        }
 public HttpResponseMessage Index(int page, int pageSize, string number)
 {
     var condition = new OtherCouponSearchCondition
     {
         Number = number,
         Page = page,
         PageCount = pageSize,
         OrderBy = EnumOtherCouponSearchOrderBy.OrderById
     };
     var coupon = _otherCouponService.GetCouponByCondition(condition).Select(p => new
     {
         p.Id,
         p.Number,
         p.Price,
         p.Status
     }).ToList();
     var count = _otherCouponService.GetCouponCount(condition);
     return PageHelper.toJson(new { List = coupon, TotalCount = count, Condition = condition });
 }
        public int GetCouponCount(OtherCouponSearchCondition condition)
        {
            var query = _couponRepository.Table;
            try
            {
                if (condition.Ids.HasValue)
                {
                    query = query.Where(q => condition.Ids == q.Id);
                }
                if (!string.IsNullOrEmpty(condition.Number))
                {
                    query = query.Where(q => q.Number == condition.Number);
                }
                if (condition.CouponCategoryId.HasValue)
                {
                    query = query.Where(q => condition.CouponCategoryId == q.CouponCategoryId);
                }
                if (condition.Status.HasValue)
                {
                    query = query.Where(q => (EnumOtherCouponStatus)condition.Status == q.Status);
                }
                return query.Count();
            }

            catch (Exception e)
            {
                _log.Error(e, "数据库操作出错");
                return -1;
            }
        }