Ejemplo n.º 1
0
        public ExecuteResult<CouponInfoCollectionResponse> GetList(CouponInfoGetListRequest request)
        {
            if (request == null)
            {
                return new ExecuteResult<CouponInfoCollectionResponse>(null) { StatusCode = StatusCode.ClientError, Message = "参数错误" };
            }

            int totalCount;
            var datas = this._couponRepository.GetPagedListByUserId(request.PagerRequest, out totalCount, request.AuthUid,
                                                        request.CouponSortOrder);
            var response = new CouponInfoCollectionResponse(request.PagerRequest, totalCount)
            {
                CouponInfoResponses = MappingManager.CouponInfoResponseMapping(datas).ToList()
            };

            var result = new ExecuteResult<CouponInfoCollectionResponse>(response);

            return result;
        }
Ejemplo n.º 2
0
 public ActionResult List(CouponInfoGetListRequest request, int? authuid, UserModel authUser)
 {
     request.AuthUid = authuid.Value;
     request.AuthUser = authUser;
     if (request == null)
         return new RestfulResult { Data = new ExecuteResult<CouponInfoResponse>(null)};
     var linq = _couponRepo.Get(c => c.User_Id == 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 < DateTime.Now);
                 break;
             case CouponRequestType.UnUsed:
                 linq = linq.Where(c => c.Status != (int)CouponStatus.Used && c.ValidEndDate >= DateTime.Now);
                 break;
         }
     }
     int totalCount = linq.Count();
     int skipCount = request.Page > 0 ? (request.Page - 1) * request.Pagesize : 0;
     linq = linq.OrderByDescending(c => c.CreatedDate).Skip(skipCount).Take(request.Pagesize);
     var productLinq = _productRepo.GetAll().Join(_storeRepo.GetAll(), o => o.Store_Id, i => i.Id, (o, i) => new { Pd = o, S = i });
     var promotionLinq = _promotionRepo.GetAll().Join(_storeRepo.GetAll(), o => o.Store_Id, i => i.Id, (o, i) => new { Pr = o, S = i });
     var linq2 = linq.GroupJoin(productLinq, o => o.FromProduct, i => i.Pd.Id, (o, i) => new { C=o,Pd = i.FirstOrDefault() })
                    .GroupJoin(promotionLinq, o => o.C.FromPromotion, i => i.Pr.Id, (o, i) => new { C = o.C, Pd = o.Pd, Pr = i.FirstOrDefault() });
     var responseData = from l in linq2.ToList()
                        select new CouponInfoResponse().FromEntity<CouponInfoResponse>(l.C,
                                     c => {
                                         var prod = l.Pd;
                                         if (prod != null)
                                         {
                                             c.ProductInfoResponse = new ProductInfoResponse().FromEntity<ProductInfoResponse>(prod.Pd, p => {
                                                 p.StoreInfoResponse = new StoreInfoResponse().FromEntity<StoreInfoResponse>(prod.S);
                                             });
                                             c.ProductId = c.ProductInfoResponse.Id;
                                             c.ProductName = c.ProductInfoResponse.Name;
                                             c.ProductDescription = c.ProductInfoResponse.Description;
                                             c.ProductType = (int)SourceType.Product;
                                            
                                         }
                                         var pro = l.Pr;
                                         if (pro != null)
                                         {
                                             c.PromotionInfoResponse = new PromotionInfoResponse().FromEntity<PromotionInfoResponse>(pro.Pr, p => {
                                                 p.StoreInfoResponse = new StoreInfoResponse().FromEntity<StoreInfoResponse>(pro.S);
                                             });
                                             c.ProductId = c.PromotionInfoResponse.Id;
                                             c.ProductName = c.PromotionInfoResponse.Name;
                                             c.ProductDescription = c.PromotionInfoResponse.Description;
                                             c.ProductType = (int)SourceType.Promotion;
                                         }
                                        
                                     });
     var response = new CouponInfoCollectionResponse(request.PagerRequest,totalCount){
                          CouponInfoResponses = responseData.ToList()
                  };
     return new RestfulResult { Data = new ExecuteResult<CouponInfoCollectionResponse>(response) };
 }