Пример #1
0
        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)
            });
        }
Пример #2
0
        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) };
                            

        }