Ejemplo n.º 1
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);
        }
        public async Task <List <Comment> > GetComments(string username)
        {
            List <Repository.Models.Comment> repoComments = await _repo.GetUserComments(username);

            if (repoComments == null)
            {
                Console.WriteLine("UserLogic.GetComments() was called for a username that doesn't exist.");
                return(null);
            }

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

            foreach (var repoComment in repoComments)
            {
                comments.Add(Mapper.RepoCommentToComment(repoComment));
            }
            return(comments);
        }
Ejemplo n.º 3
0
        public async Task <List <Comment> > GetComments(int discussionid)
        {
            List <Repository.Models.Comment> repoComments = await _repo.GetMovieComments(discussionid);

            if (repoComments == null)
            {
                Console.WriteLine("ForumLogic.GetComments() was called with a discussionid that doesn't exist.");
                return(null);
            }

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

            foreach (var repoComment in repoComments)
            {
                comments.Add(Mapper.RepoCommentToComment(repoComment));
            }
            return(comments);
        }