Esempio n. 1
0
        public EditCommentViewModel GetCommentById(int commentId)
        {
            var query = from c in _repository.Comments
                        where c.CommentID == commentId
                        orderby c.UpdatedDate descending
                        select new
            {
                CommentID    = c.CommentID,
                Body         = c.Body,
                AddedBy      = c.AddedBy,
                AddedByEmail = c.AddedByEmail,
                AddedByWeb   = c.AddedByWeb,
                AddedByIP    = c.AddedByIP,
                AddedDate    = c.AddedDate,
                ArticleLID   = c.Article.LID
            };
            var comments = query.ToList();

            if (comments.Count > 0)
            {
                EditCommentViewModel model = new EditCommentViewModel();
                model.InjectFrom(comments[0]);
                return(model);
            }
            return(null);
        }
Esempio n. 2
0
        public EditCommentListViewModel RetrieveComments(int pageNum = 0, int pageSize = 10)
        {
            var count = _repository.Comments.Count();
            var query = from c in _repository.Comments
                        orderby c.UpdatedDate descending
                        select new
            {
                CommentID    = c.CommentID,
                Body         = c.Body,
                AddedBy      = c.AddedBy,
                AddedByEmail = c.AddedByEmail,
                AddedByWeb   = c.AddedByWeb,
                AddedByIP    = c.AddedByIP,
                AddedDate    = c.AddedDate,
                ArticleLID   = c.Article.LID
            };

            query.Skip(pageNum * pageSize).Take(pageSize);

            List <EditCommentViewModel> list = new List <EditCommentViewModel>();

            foreach (var item in query)
            {
                EditCommentViewModel commentModel = new EditCommentViewModel();
                commentModel.InjectFrom(item);
                list.Add(commentModel);
            }
            EditCommentListViewModel model = new EditCommentListViewModel();

            model.Comments   = list;
            model.PagingInfo = new Models.Shared.PagingInfo()
            {
                CurrentPage      = pageNum,
                PageSize         = pageSize,
                TotalRecordCount = count
            };
            return(model);
        }