public ActionResult My(MyCommentListRequest request, int?authuid, UserModel authUser) { request.AuthUser = authUser; var comments = _commentRepo.Get(c => c.Status != (int)DataStatus.Deleted).OrderByDescending(c => c.CreatedDate) .GroupJoin(_resourceRepo.Get(r => r.Status != (int)DataStatus.Deleted && r.SourceType == (int)SourceType.CommentAudio), o => o.Id, i => i.SourceId, (o, i) => new { C = o, Aud = i.FirstOrDefault() }) .GroupJoin(_customerRepo.Get(cu => cu.Status != (int)DataStatus.Deleted), o => o.C.User_Id, i => i.Id, (o, i) => new { C = o.C, Aud = o.Aud, U = i.FirstOrDefault() }) .GroupJoin(_customerRepo.Get(cu => cu.Status != (int)DataStatus.Deleted), o => o.C.ReplyUser, i => i.Id, (o, i) => new { C = o.C, Aud = o.Aud, U = o.U, RU = i.FirstOrDefault() }); var dbContext = _commentRepo.Context; var linq = (from c2 in dbContext.Set <CommentEntity>() let products = dbContext.Set <ProductEntity>().Where(p => p.Status != (int)DataStatus.Deleted && p.RecommendUser == authUser.Id) let promotions = dbContext.Set <PromotionEntity>().Where(p => p.Status != (int)DataStatus.Deleted && p.RecommendUser == authUser.Id) where (c2.User_Id == authUser.Id && c2.Status != (int)DataStatus.Deleted) || products.Any(p => c2.SourceId == p.Id && c2.SourceType == (int)SourceType.Product) || promotions.Any(p => c2.SourceId == p.Id && c2.SourceType == (int)SourceType.Promotion) select new { SourceId = c2.SourceId, SourceType = c2.SourceType }).Distinct() .GroupJoin(comments, o => new { SourceType = o.SourceType, SourceId = o.SourceId }, i => new { SourceType = i.C.SourceType, SourceId = i.C.SourceId }, (o, i) => new { SourceType = o.SourceType, SourceId = o.SourceId, Comment = i.OrderByDescending(c => c.C.CreatedDate).FirstOrDefault() }); int totalCount = linq.Count(); int skipCount = request.Page > 0 ? (request.Page - 1) * request.Pagesize : 0; linq = linq.OrderByDescending(c => c.Comment.C.CreatedDate).Skip(skipCount).Take(request.Pagesize); var responseData = from l in linq.ToList() select new MyCommentInfoResponse().FromEntity <MyCommentInfoResponse>(l.Comment.C, c => { //c.SourceId = l.SourceId; // c.SourceType = l.SourceType; c.CommentUser = new UserInfoResponse().FromEntity <UserInfoResponse>(l.Comment.U); c.ReplyUserName = l.Comment.RU == null ? string.Empty : l.Comment.RU.Nickname; c.Resource = new ResourceInfoResponse().FromEntity <ResourceInfoResponse>(l.Comment.Aud); }); var response = new PagerInfoResponse <MyCommentInfoResponse>(request.PagerRequest, totalCount) { Items = responseData.ToList() }; return(new RestfulResult { Data = new ExecuteResult <PagerInfoResponse <MyCommentInfoResponse> >(response) }); }
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) }); }