Ejemplo n.º 1
0
        // -------------------------------------------------------------------- private methods

        /// <summary>
        /// Returns a <see cref="Post"/> from data source, throws <see cref="FanException"/> if not found.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        /// <remarks>
        /// This returns Post not a BlogPost, which would maintain tracking for <see cref="PrepPostAsync(BlogPost, string)"/>.
        /// </remarks>
        private async Task <Post> QueryPostAsync(int id, EPostType type)
        {
            var post = await _postRepo.GetAsync(id, type);

            if (post == null)
            {
                throw new FanException($"{type} with id {id} is not found.");
            }

            return(post);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Returns a <see cref="Post"/> by slug. If it is a BlogPost it'll return together with its
 /// <see cref="Category"/> and <see cref="Tag"/>. Returns null if it's not found.
 /// </summary>
 /// <param name="slug"></param>
 /// <param name="type">If it's BlogPost it'll return category and tags with it.</param>
 /// <returns></returns>
 public async Task <Post> GetAsync(string slug, EPostType type)
 {
     return((type == EPostType.BlogPost) ?
            await _entities.Include(p => p.User).Include(p => p.Category).Include(p => p.PostTags).ThenInclude(p => p.Tag)
            .SingleOrDefaultAsync(p =>
                                  p.Type == EPostType.BlogPost &&
                                  p.Status == EPostStatus.Published &&
                                  p.Slug.Equals(slug, StringComparison.CurrentCultureIgnoreCase)) :
            await _entities.Include(p => p.User)
            .SingleOrDefaultAsync(p =>
                                  p.Type == type &&
                                  p.Status == EPostStatus.Published &&
                                  p.Slug.Equals(slug, StringComparison.CurrentCultureIgnoreCase)));
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Returns a <see cref="Post"/> by id. If it is a BlogPost it'll return together with its
 /// <see cref="Category"/> and <see cref="Tag"/>. Returns null if it's not found.
 /// </summary>
 /// <param name="id"></param>
 /// <param name="type">If it's BlogPost it'll return category and tags with it.</param>
 public async Task <Post> GetAsync(int id, EPostType type)
 {
     return((type == EPostType.BlogPost) ?
            await _entities.Include(p => p.User).Include(p => p.Category).Include(p => p.PostTags).ThenInclude(p => p.Tag).SingleOrDefaultAsync(p => p.Id == id) :
            await _entities.Include(p => p.User).SingleOrDefaultAsync(p => p.Id == id));
 }
Ejemplo n.º 4
0
        public static string GetDescription(this EPostType type)
        {
            var types = Enum.GetName(type.GetType(), type);

            return(types.Replace("_", " "));
        }