Exemplo n.º 1
0
        /// <summary>
        /// returns all the comments of the story with the given author and title
        /// </summary>
        /// <param name="userName">author's userName</param>
        /// <param name="title">title of the story</param>
        /// <returns>all the story's comments</returns>
        public async Task <ICollection <Comment> > GetAllCommentsAsync(string userName, string title)
        {
            try
            {
                Story story = await _storiesRepository.GetStoryByTitleAsync(userName, title);

                return(story.Comments);
            }
            catch (Exception e)
            {
                _logger.LogError($"Error while getting all comments\n {e.Message}");
            }

            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// method to get story or comment depends on {postType}
        /// </summary>
        /// <param name="postType">story or comment</param>
        /// <param name="userName">author of the story</param>
        /// <param name="title">title of the story</param>
        /// <param name="id">id of the comment</param>
        /// <returns>story or comment if they exist</returns>
        private async Task <IPostable> GetPostWithGivenType(string postType,
                                                            string userName,
                                                            string title,
                                                            int id)
        {
            try
            {
                switch (postType)
                {
                case STORY:
                    return(await _storiesRepository.GetStoryByTitleAsync(userName, title));

                case COMMENT:
                    return(await _commentsRepository.GetCommentByIdAsync(userName, title, id));
                }
            }
            catch (Exception e)
            {
                _logger.LogError($"Error while getting post with given type\n {e.Message}");
            }

            return(null);
        }