Beispiel #1
0
        public ActionResult List(StoreCouponListRequest request, int?authuid, UserModel authUser)
        {
            request.AuthUid  = authuid.Value;
            request.AuthUser = authUser;
            if (request == null)
            {
                return new RestfulResult {
                           Data = new ExecuteResult <StoreCouponListRequest>(null)
                }
            }
            ;
            var linq = _storecouponRepo.Get(c => c.UserId == authUser.Id && c.Status != (int)CouponStatus.Deleted);

            if (request.Type.HasValue)
            {
                switch (request.Type.Value)
                {
                case CouponRequestType.Used:
                    linq = linq.Where(c => c.Status == (int)CouponStatus.Used);
                    break;

                case CouponRequestType.Expired:
                    linq = linq.Where(c => c.Status != (int)CouponStatus.Used && c.ValidEndDate.HasValue && c.ValidEndDate.Value < DateTime.Now);
                    break;

                case CouponRequestType.UnUsed:
                    linq = linq.Where(c => c.Status != (int)CouponStatus.Used && c.ValidEndDate.HasValue && c.ValidEndDate.Value >= DateTime.Now);
                    break;
                }
            }
            int totalCount = linq.Count();
            int skipCount  = request.Page > 0 ? (request.Page - 1) * request.Pagesize : 0;

            linq = linq.OrderByDescending(c => c.CreateDate).Skip(skipCount).Take(request.Pagesize);
            var linq2 = linq.Join(_storeproRepo.GetAll(), o => o.StorePromotionId, i => i.Id, (o, i) => new { SC = o, SP = i });

            var responseData = from l in linq2.ToList()
                               select new StoreCouponDetailResponse().FromEntity <StoreCouponDetailResponse>(l.SC,
                                                                                                             c =>
            {
                c.Promotion = new StorePromotionDetailResponse().FromEntity <StorePromotionDetailResponse>(l.SP);
            });
            var response = new PagerInfoResponse <StoreCouponDetailResponse>(request.PagerRequest, totalCount)
            {
                Items = responseData.ToList()
            };

            return(new RestfulResult {
                Data = new ExecuteResult <PagerInfoResponse <StoreCouponDetailResponse> >(response)
            });
        }