Exemplo n.º 1
0
        /// <summary>
        /// Gets all the comments for the specified Content.
        /// </summary>
        /// <param name="filter">Filter which comments to be fetched</param>
        /// <param name="pageDetails">Details about the pagination</param>
        /// <returns>List of all comments of the Content</returns>
        public async Task<IEnumerable<CommentDetails>> GetContentComments(CommentFilter filter, PageDetails pageDetails)
        {
            this.CheckNotNull(() => new { filter, pageDetails });

            Func<ContentComments, object> orderBy = (contentComments) => contentComments.CommentDatetime;
            Expression<Func<ContentComments, bool>> condition = (contentComments) => contentComments.ContentID == filter.EntityId && contentComments.IsDeleted == false;

            IEnumerable<ContentComments> comments =  _contentCommentsRepository
                .GetItems(condition, orderBy, filter.OrderType == OrderType.NewestFirst, (pageDetails.CurrentPage - 1) * pageDetails.ItemsPerPage, pageDetails.ItemsPerPage);

            var commentDetails = new List<CommentDetails>();
            if (comments != null)
            {
                foreach (var item in comments)
                {
                    var comment = new CommentDetails();
                    Mapper.Map(item, comment);
                    commentDetails.Add(comment);
                }
            }

            return commentDetails;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets all the comments for the specified Community.
        /// </summary>
        /// <param name="filter">Filter which comments to be fetched</param>
        /// <param name="pageDetails">Details about the pagination</param>
        /// <returns>List of all comments of the Community</returns>
        public async Task<IEnumerable<CommentDetails>> GetCommunityComments(CommentFilter filter, PageDetails pageDetails)
        {
            this.CheckNotNull(() => new { filter, pageDetails });

            Func<CommunityComments, object> orderBy = (communityComments) => communityComments.CommentedDatetime;
            Expression<Func<CommunityComments, bool>> condition = (communityComments) => communityComments.CommunityID == filter.EntityId && communityComments.IsDeleted == false;

            // Gets the total items satisfying the
            var totalItemsForCondition = _communityCommentRepository.GetItemsCount(condition);
            pageDetails.TotalPages = (totalItemsForCondition / pageDetails.ItemsPerPage) + ((totalItemsForCondition % pageDetails.ItemsPerPage == 0) ? 0 : 1);

            IEnumerable<CommunityComments> comments =  _communityCommentRepository
                .GetItems(condition, orderBy, filter.OrderType == OrderType.NewestFirst, (pageDetails.CurrentPage - 1) * pageDetails.ItemsPerPage, pageDetails.ItemsPerPage);

            var commentDetails = new List<CommentDetails>();
            if (comments != null)
            {
                foreach (var item in comments)
                {
                    var comment = new CommentDetails();
                    Mapper.Map(item, comment);
                    commentDetails.Add(comment);
                }
            }

            return commentDetails;
        }
Exemplo n.º 3
0
        public bool CreateContentComment(CommentDetails comment)
        {
            // Make sure input is not null
            this.CheckNotNull(() => new { comment });

            try
            {
                var contentComment = new ContentComments();
                Mapper.Map(comment, contentComment);

                contentComment.IsDeleted = false;
                contentComment.CommentDatetime = DateTime.UtcNow;

                _contentCommentsRepository.Add(contentComment);
                _contentCommentsRepository.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                // TODO: Add exception handling logic here.
            }

            return false;
        }