예제 #1
0
        public async Task AddAsync(TEntity entity)
        {
            using var context = new MerigurumiblogContext();
            await context.AddAsync(entity);

            await context.SaveChangesAsync();
        }
예제 #2
0
 public async Task <List <Category> > GetCategoriesAsync(int blogId)
 {
     using var context = new MerigurumiblogContext();
     return(await context.Categories.Join(context.CategoryBlogs, c => c.Id, cb => cb.CategoryId, (category, categoryBlog) => new
     {
         category,
         categoryBlog
     }).Where(I => I.categoryBlog.BlogId == blogId).Select(I => new Category
     {
         Id = I.category.Id,
         Name = I.category.Name
     }).ToListAsync());
 }
예제 #3
0
 public async Task <List <Blog> > GetAllByCategoryIdAsync(int categoryId)
 {
     using var context = new MerigurumiblogContext();
     return(await context.Blogs.Join(context.CategoryBlogs, b => b.Id, cb => cb.BlogId, (blog, categoryBlog) => new
     {
         blog,
         categoryBlog
     }).Where(I => I.categoryBlog.CategoryId == categoryId).Select(I => new Blog
     {
         AppUser = I.blog.AppUser,
         AppUserId = I.blog.AppUserId,
         CategoryBlogs = I.blog.CategoryBlogs,
         Comments = I.blog.Comments,
         Description = I.blog.Description,
         Id = I.blog.Id,
         ImagePath = I.blog.ImagePath,
         PostedTime = I.blog.PostedTime,
         ShortDescription = I.blog.ShortDescription,
         Title = I.blog.Title
     }).ToListAsync());
 }
        private async Task GetComments(int blogId, int?parentId, List <Comment> result)
        {
            using var context = new MerigurumiblogContext();
            var comments = await context.Comments.Where(I => I.BlogId == blogId && I.ParentCommentId == parentId).OrderByDescending(I => I.PostedTime).ToListAsync();

            if (comments.Count > 0)
            {
                foreach (var comment in comments)
                {
                    if (comment.SubComments == null)
                    {
                        comment.SubComments = new List <Comment>();
                    }

                    await GetComments(comment.BlogId, comment.Id, comment.SubComments);

                    if (!result.Contains(comment))
                    {
                        result.Add(comment);
                    }
                }
            }
        }
예제 #5
0
 public async Task <TEntity> GetAsync(Expression <Func <TEntity, bool> > filter)
 {
     using var context = new MerigurumiblogContext();
     return(await context.Set <TEntity>().FirstOrDefaultAsync(filter));
 }
예제 #6
0
 public async Task <List <TEntity> > GetAllAsync <TKey>(Expression <Func <TEntity, TKey> > keySelector)
 {
     using var context = new MerigurumiblogContext();
     return(await context.Set <TEntity>().OrderByDescending(keySelector).ToListAsync());
 }
예제 #7
0
 public async Task <List <TEntity> > GetAllAsync(Expression <Func <TEntity, bool> > filter)
 {
     using var context = new MerigurumiblogContext();
     return(await context.Set <TEntity>().Where(filter).ToListAsync());
 }
예제 #8
0
        public async Task <List <TEntity> > GetAllAsync()
        {
            using var context = new MerigurumiblogContext();

            return(await context.Set <TEntity>().ToListAsync());
        }
예제 #9
0
 public async Task <TEntity> FindByIdAsync(int id)
 {
     using var context = new MerigurumiblogContext();
     return(await context.FindAsync <TEntity>(id));
 }
 public async Task <List <Category> > GetAllWithCategoryBlogsAsync()
 {
     using var context = new MerigurumiblogContext();
     return(await context.Categories.OrderByDescending(I => I.Id).Include(I => I.CategoryBlogs).ToListAsync());
 }
예제 #11
0
 public async Task <List <Blog> > GetLastFiveAsync()
 {
     using var context = new MerigurumiblogContext();
     return(await context.Blogs.OrderByDescending(I => I.PostedTime).Take(5).ToListAsync());
 }