Exemple #1
0
        public List <Marking> GetMarkings(int userid, PagingAttributes pagingAttributes)
        {
            using var db = new SOContext();

            var markings = db.Markings
                           .Where(m => m.UserId == userid)
                           .Include(m => m.Annotation)
                           .Skip(pagingAttributes.Page * pagingAttributes.PageSize)
                           .Take(pagingAttributes.PageSize)
                           .ToList();

            return(markings);
        }
Exemple #2
0
        public List <Question> GetQuestions(PagingAttributes pagingAttributes)
        {
            using var db = new SOContext();
            var questions = db.Questions
                            .Include(q => q.Post)

                            .Skip(pagingAttributes.Page * pagingAttributes.PageSize)
                            .Take(pagingAttributes.PageSize)
                            .ToList();


            return(questions);
        }
Exemple #3
0
        public IList <Questions> GetQuestions(PagingAttributes pagingAttributes)
        {
            //// for browsing the full list of questions
            using var db = new DatabaseContext();

            //convert back from 1-based pages + check/fix page
            int page = _sharedService.GetPagination(_sharedService.NumberOfQuestions(), pagingAttributes);

            return(db.Questions
                   .OrderBy(u => u.Id)
                   .Skip(page * pagingAttributes.PageSize)
                   .Take(pagingAttributes.PageSize)
                   .ToList());
        }
/*
 *      public int GetPagination(int matchcount, PagingAttributes pagingAttributes)
 *      {
 *          //calc max pages and set requested page to last page if out of bounds
 *          var maxPages = (int)Math.Ceiling((double)matchcount / pagingAttributes.PageSize);
 *          var minPages = 1;
 *
 *          System.Console.WriteLine($"{maxPages} calculated pages.");
 *
 *          if (pagingAttributes.Page > maxPages)
 *          {
 *              pagingAttributes.Page = maxPages;
 *          }
 *          else if (pagingAttributes.Page < minPages)
 *          {
 *              pagingAttributes.Page = minPages;
 *          }
 *          return pagingAttributes.Page - 1;    // return 0 indexed
 *
 *
 *          Console.WriteLine($"{page} page");
 *          Console.WriteLine($"{pagingAttributes.Page} paginattr.page");
 *
 *          return page;
 *
 *      }
 */

        public int GetPagination(int matchcount, PagingAttributes pagingAttributes)
        {
            //calc max pages and set requested page to last page if out of bounds
            var maxPages = (int)Math.Ceiling((double)matchcount / pagingAttributes.PageSize);
            var minPages = 1;

            System.Console.WriteLine($"{maxPages} calculated pages.");

            if (pagingAttributes.Page > maxPages)
            {
                pagingAttributes.Page = maxPages;
            }
            else if (pagingAttributes.Page < minPages)
            {
                pagingAttributes.Page = minPages;
            }
            return(pagingAttributes.Page - 1);    // return 0 indexed
        }
Exemple #5
0
        public (List <Searches>, int) GetSearchesList(int userId, PagingAttributes pagingAttributes)
        {
            using var db = new DatabaseContext();

            var count = db.Searches
                        .Where(x => x.UserId == userId)
                        .OrderByDescending(x => x.Date)
                        .Count();

            //try to convert back from 1-based pages
            int page = _sharedService.GetPagination(count, pagingAttributes);

            var list = db.Searches
                       .Where(x => x.UserId == userId)
                       .OrderByDescending(x => x.Date)
                       .Skip(page * pagingAttributes.PageSize)
                       .Take(pagingAttributes.PageSize)
                       .ToList();

            return(list, count);
        }
Exemple #6
0
        public IList <Posts> Search(int userid, string searchstring, int?searchtypecode, PagingAttributes pagingAttributes)
        {
            ////// for performing searches with appsearch on the db
            ///
            // do actual search using appsearch in db and build results

            //need db context and searchtype lookuptable
            using var db = new DatabaseContext();
            Modules.SearchTypeLookupTable st = new Modules.SearchTypeLookupTable();

            ////get params for db.func
            ///
            //build searchstring
            var search = new NpgsqlParameter("search", NpgsqlTypes.NpgsqlDbType.Text)
            {
                Value = BuildSearchString(searchstring, false)
            };

            //lookup searchtype string
            var searchtype = new NpgsqlParameter("searchtype", NpgsqlTypes.NpgsqlDbType.Text);

            if (searchtypecode >= 0 && searchtypecode <= 3)
            {
                searchtype.Value = st.searchType[searchtypecode.Value];
            }
            else
            {
                searchtype.Value = st.searchType[3];
            }

            //userid
            var appuserid = new NpgsqlParameter("appuserid", NpgsqlTypes.NpgsqlDbType.Integer)
            {
                Value = userid
            };

            //if internal call is specified, stored function appsearch won't add to searches/searchhistory
            var internalcall = new NpgsqlParameter("internalcall", NpgsqlTypes.NpgsqlDbType.Boolean)
            {
                Value = true
            };

            //count all matches
            var matchcount = db.Search
                             .FromSqlRaw("select appsearch(@appuserid, @searchtype, @search, @internalcall)", appuserid, searchtype, search, internalcall)
                             .Count();

            System.Console.WriteLine($"{matchcount} results.");

            int page = _sharedService.GetPagination(matchcount, pagingAttributes);

            System.Console.WriteLine($"{page} page trying to get.");

            //get subset of results according to pagesize etc
            var resultlist = db.Search
                             .FromSqlRaw("SELECT * from appsearch(@appuserid, @searchtype, @search)", appuserid, searchtype, search)
                             .Skip(page * pagingAttributes.PageSize)
                             .Take(pagingAttributes.PageSize)
                             .ToList();

            //build and map results to posts
            var resultposts = new List <Posts>();

            foreach (Search s in resultlist)
            {
                Posts      p  = new Posts();
                SinglePost sp = new SinglePost();
                sp = _sharedService.GetPost(s.postid);

                p.Parentid = sp.QuestionId;
                p.Id       = sp.Id;
                var endpos = 100;
                if (sp.Body.Length < 100)
                {
                    endpos = sp.Body.Length;
                }
                p.Body = sp.Body.Substring(0, endpos);

                p.Title        = _sharedService.GetQuestion(p.Parentid).Title;
                p.Totalresults = matchcount;
                p.Rank         = s.rank;
                resultposts.Add(p);
            }
            return(resultposts);
        }