Esempio n. 1
0
        public HttpResponseMessage GetRelatedComments([FromUri] CommentsQuery data)
        {
            int pn = data.Pn ?? 1;

            var good = db.GoodEntities.Find(data.GoodID);

            db.Entry(good).Collection(ge => ge.SaleEntities).Load();
            List <Comment> comments = new List <Comment>();

            foreach (var se in good.SaleEntities)
            {
                db.Entry(se).Collection(saleE => saleE.Comments).Load();
                foreach (var s_comment in se.Comments)
                {
                    comments.Add(s_comment);
                }
            }

            List <CommentU> dataList = new List <CommentU>();
            var             rs       = comments.Skip((pn - 1) * PageDataNumber).Take(PageDataNumber).ToList();
            int             res      = comments.Count() / PageDataNumber;

            if (comments.Count() % PageDataNumber != 0)
            {
                res = res + 1;
            }
            foreach (var VARIABLE in rs)
            {
                CommentU tmp = new CommentU();
                tmp.SaleEntityID    = VARIABLE.SaleEntityID;
                tmp.Detail          = VARIABLE.Detail;
                tmp.LevelRank       = VARIABLE.LevelRank;
                tmp.UserCommentTime = VARIABLE.UserCommentTime;
                IQueryable <User> users;
                users = db.Users;
                List <User> t = users.ToList();
                foreach (var va in t)
                {
                    if (va.UserID == VARIABLE.UserID)
                    {
                        tmp.UserName = va.NickName;
                    }
                }
                dataList.Add(tmp);
            }
            return(Request.CreateResponse(HttpStatusCode.OK,
                                          new
            {
                ResultNum = res,
                Comments = dataList,
                PageNum = pn
            }));
        }
Esempio n. 2
0
        public HttpResponseMessage GetRelatedComments([FromUri] CommentsQuery data)
        {
            int pn = data.Pn ?? 1;
            IQueryable <Comment> Comments;
            var cate = db.SaleEntities.Find(data.GoodID);

            if (cate == null)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, "GoodID not found"));
            }
            db.Entry(cate).Collection(c => c.Comments).Load();
            Comments = cate.Comments.AsQueryable();

            List <CommentU> dataList = new List <CommentU>();
            var             rs       = Comments.Skip((pn - 1) * PageDataNumber).Take(PageDataNumber).ToList();
            int             res      = Comments.Count() / PageDataNumber;

            if (Comments.Count() % PageDataNumber != 0)
            {
                res = res + 1;
            }
            foreach (var VARIABLE in rs)
            {
                CommentU tmp = new CommentU();
                tmp.SaleEntityID    = VARIABLE.SaleEntityID;
                tmp.Detail          = VARIABLE.Detail;
                tmp.LevelRank       = VARIABLE.LevelRank;
                tmp.UserCommentTime = VARIABLE.UserCommentTime;
                IQueryable <User> users;
                users = db.Users;
                List <User> t = users.ToList();
                foreach (var va in t)
                {
                    if (va.UserID == VARIABLE.UserID)
                    {
                        tmp.UserName = va.NickName;
                    }
                }
                dataList.Add(tmp);
            }
            return(Request.CreateResponse(HttpStatusCode.OK,
                                          new
            {
                ResultNum = res,
                Comments = dataList,
                PageNum = pn
            }));
        }