示例#1
0
        private List <History> GetListFromQuery(int userId, bool isBookmark, PagingAttributes pageAtt)
        {
            // This enforces the page upper and lower limits
            var sharedService = new SharedService();

            sharedService.GetPagination(GetCount(userId, isBookmark), pageAtt);

            return(_database.History
                   .Where(x =>
                          x.Userid == userId &&
                          x.isBookmark == isBookmark)
                   .OrderBy(x => x.Date)
                   .Skip((pageAtt.Page - 1) * pageAtt.PageSize)
                   .Take(pageAtt.PageSize)
                   .ToList());
        }
        //public List<AnnotationsDto> GetAllAnnotationsOfUser(int userId, PagingAttributes pagingAttributes)
        //{
        //    using var DB = new AppContext();
        //    var listAnnotationsOfUser = (from annot in DB.Annotations
        //                                 join hist in DB.History on annot.HistoryId equals hist.Id
        //                                 where annot.UserId == userId
        //                                 select new AnnotationsDto
        //                                 {
        //                                     AnnotationId = annot.Id,
        //                                     PostId = hist.Postid,
        //                                     Body = annot.Body,
        //                                     Date = annot.Date
        //                                 }).ToList();


        //    return listAnnotationsOfUser;
        //}

        /// <summary>
        /// Gets all the annotations of a userId and a postId
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="postId"></param>
        /// <param name="pagingAttributes"></param>
        /// <returns>List Type SimpleAnnotationsDto</returns>
        public List <SimpleAnnotationDto> GetUserAnnotationsMadeOnAPost(int userId, int postId, PagingAttributes pagingAttributes)
        {
            using var DB = new DatabaseContext();
            var sharedService         = new SharedService();
            var page                  = sharedService.GetPagination(UserAnnotOnPostListCount(userId, postId), pagingAttributes);
            var annotationsOfPostList = (from annot in DB.Annotations
                                         join hist in DB.History on annot.HistoryId equals hist.Id
                                         where hist.Postid == postId && annot.UserId == userId
                                         select new SimpleAnnotationDto
            {
                AnnotationId = annot.Id,
                Body = annot.Body,
                Date = annot.Date
            }).Skip(page * pagingAttributes.PageSize)
                                        .Take(pagingAttributes.PageSize)
                                        .ToList();

            return(annotationsOfPostList);
        }
        /// <summary>
        /// Returns a list of annotations and their postId recorded in history table
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="postId"></param>
        /// <returns></returns>
        public List <PostAnnotationsDto> GetAllAnnotationsOfUser(int userId, PagingAttributes pagingAttributes, out int count)
        {
            using var DB = new DatabaseContext();
            var sharedService = new SharedService();

            count = GetAllAnnotationsOfUserCount(userId);
            var page = sharedService.GetPagination(count, pagingAttributes);

            var result = (from annot in DB.Annotations
                          join hist in DB.History on annot.HistoryId equals hist.Id
                          where annot.UserId == userId
                          select new PostAnnotationsDto
            {
                AnnotationId = annot.Id,
                PostId = hist.Postid,
                Body = annot.Body,
                Date = annot.Date
            }).Skip(page * pagingAttributes.PageSize)
                         .Take(pagingAttributes.PageSize)
                         .ToList();

            return(result);
        }