Esempio n. 1
0
        public async Task <bool> SetReviewsPageSize(int pagesize)
        {
            if (pagesize < 1 || pagesize > 100)
            {
                return(false);
            }

            Repository.Models.Setting setting = new Repository.Models.Setting();
            setting.Setting1 = "reviewspagesize";
            setting.IntValue = pagesize;
            return(await _repo.SetSetting(setting));
        }
Esempio n. 2
0
        public async Task <bool> SetCommentsPageSize(int pagesize)
        {
            if (pagesize < 1 || pagesize > 100)
            {
                Console.WriteLine("ForumLogic.SetCommentsPageSize() was called with an invalid pagesize.");
                return(false);
            }

            Repository.Models.Setting setting = new Repository.Models.Setting();
            setting.Setting1 = "commentspagesize";
            setting.IntValue = pagesize;
            return(await _repo.SetSetting(setting));
        }
Esempio n. 3
0
        public async Task <List <Comment> > GetCommentsPage(int discussionid, int page)
        {
            if (page < 1)
            {
                Console.WriteLine("ForumLogic.GetCommentsPage() was called with a negative or zero page number.");
                return(null);
            }

            Repository.Models.Setting pageSizeSetting = _repo.GetSetting("commentspagesize");
            int pageSize = pageSizeSetting.IntValue ?? default(int);

            if (pageSize < 1)
            {
                Console.WriteLine("ForumLogic.GetCommentsPage() was called but the commentspagesize is invalid");
                return(null);
            }

            List <Repository.Models.Comment> repoComments = await _repo.GetMovieComments(discussionid);

            if (repoComments == null)
            {
                Console.WriteLine("ForumLogic.GetCommentsPage() was called with a discussionid that doesn't exist.");
                return(null);
            }
            repoComments = repoComments.OrderByDescending(c => c.CreationTime).ToList <Repository.Models.Comment>();

            int numberOfComments = repoComments.Count;
            int startIndex       = pageSize * (page - 1);

            if (startIndex > numberOfComments - 1)
            {
                Console.WriteLine("ForumLogic.GetCommentsPage() was called for a page number without comments.");
                return(null);
            }

            int endIndex = startIndex + pageSize - 1;

            if (endIndex > numberOfComments - 1)
            {
                endIndex = numberOfComments - 1;
            }

            List <Comment> comments = new List <Comment>();

            for (int i = startIndex; i <= endIndex; i++)
            {
                comments.Add(Mapper.RepoCommentToComment(repoComments[i]));
            }
            return(comments);
        }
Esempio n. 4
0
        public async Task <List <Review> > GetReviewsPage(string movieid, int page, string sortorder)
        {
            if (page < 1)
            {
                Console.WriteLine("MovieLogic.GetReviewsPage() was called with a negative or zero page number.");
                return(null);
            }

            Repository.Models.Setting pageSizeSetting = _repo.GetSetting("reviewspagesize");
            int pageSize = pageSizeSetting.IntValue ?? default(int);

            if (pageSize < 1)
            {
                Console.WriteLine("MovieLogic.GetReviewsPage() was called but the reviewspagesize is invalid");
                return(null);
            }

            List <Repository.Models.Review> repoReviews = await _repo.GetMovieReviews(movieid);

            if (repoReviews == null)
            {
                Console.WriteLine("MovieLogic.GetReviewsPage() was called for a movie that doesn't exist.");
                return(null);
            }

            // Sort the list of Reviews
            switch (sortorder)
            {
            case "ratingasc":
                repoReviews = repoReviews.OrderBy(r => r.Rating).ToList <Repository.Models.Review>();
                break;

            case "ratingdsc":
                repoReviews = repoReviews.OrderByDescending(r => r.Rating).ToList <Repository.Models.Review>();
                break;

            case "timeasc":
                repoReviews = repoReviews.OrderBy(r => r.CreationTime).ToList <Repository.Models.Review>();
                break;

            case "timedsc":
                repoReviews = repoReviews.OrderByDescending(r => r.CreationTime).ToList <Repository.Models.Review>();
                break;

            default:
                return(null);
            }

            int numberOfReviews = repoReviews.Count;
            int startIndex      = pageSize * (page - 1);

            if (startIndex > numberOfReviews - 1)
            {
                Console.WriteLine("MovieLogic.GetReviewsPage() was called for a page number without reviews.");
                return(null);
            }

            int endIndex = startIndex + pageSize - 1;

            if (endIndex > numberOfReviews - 1)
            {
                endIndex = numberOfReviews - 1;
            }

            List <Review> reviews = new List <Review>();

            for (int i = startIndex; i <= endIndex; i++)
            {
                reviews.Add(Mapper.RepoReviewToReview(repoReviews[i]));
            }
            return(reviews);
        }