public async Task InsertAsync(T entity)
        {
            using var context = new BlogProjectContext();
            await context.Set <T>().AddAsync(entity);

            await context.SaveChangesAsync();
        }
Example #2
0
 public async Task <List <Category> > GetCategoriesWithBlogAsync(int blogId)
 {
     using var context = new BlogProjectContext();
     return(await context.Categories.Join(context.CategoryBlogs, c => c.Id, cb => cb.CategoryId, (category, categoryBlog) => new
     {
         category = category,
         categoryBlog = categoryBlog
     }).Where(x => x.categoryBlog.BlogId == blogId).Select(x => new Category
     {
         Id = x.category.Id,
         Name = x.category.Name
     }).ToListAsync());
 }
Example #3
0
        private async Task GetComments(int blogId, int?parentId, List <Comment> result)
        {
            using var context = new BlogProjectContext();
            var comments = await context.Comments.Where(x => x.BlogId == blogId && x.ParentCommentId == parentId).OrderByDescending(x => x.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);
                    }
                }
            }
        }
Example #4
0
        public async Task <List <Blog> > GetAllByCategoryIdAsync(int id)
        {
            using var context = new BlogProjectContext();

            return(await context.Blogs.Join(context.CategoryBlogs, b => b.Id, cb => cb.BlogId, (blog, categoryBlog) =>
                                            new
            {
                blog = blog,
                categoryBlog = categoryBlog
            }).Where(x => x.categoryBlog.CategoryId == id).Select(x => new Blog
            {
                Title = x.blog.Title,
                AppUser = x.blog.AppUser,
                AppUserId = x.blog.AppUserId,
                CategoryBlogs = x.blog.CategoryBlogs,
                Comments = x.blog.Comments,
                Description = x.blog.Description,
                Id = x.blog.Id,
                ImagePath = x.blog.ImagePath,
                PostedTime = x.blog.PostedTime,
                ShortDescription = x.blog.ShortDescription
            }).ToListAsync());
        }
 public async Task <T> GetByIdAsync(int id)
 {
     using var context = new BlogProjectContext();
     return(await context.Set <T>().FindAsync(id));
 }
Example #6
0
 public UnitOfWork(BlogProjectContext context)
 {
     _context = context;
 }
 public async Task <List <Category> > GetAllWithCategoryBlogsAsync()
 {
     using var context = new BlogProjectContext();
     return(await context.Categories.OrderByDescending(x => x.Id).Include(x => x.CategoryBlogs).ToListAsync());
 }
 public async Task DeleteAsync(T entity)
 {
     using var context = new BlogProjectContext();
     context.Set <T>().Remove(entity);
     await context.SaveChangesAsync();
 }
 public async Task <List <T> > GetAllAsync <TKey>(Expression <Func <T, TKey> > keySelector)
 {
     using var context = new BlogProjectContext();
     return(await context.Set <T>().OrderByDescending(keySelector).ToListAsync());
 }
 public async Task <T> GetAsync(Expression <Func <T, bool> > filter)
 {
     using var context = new BlogProjectContext();
     return(await context.Set <T>().FirstOrDefaultAsync(filter));
 }
 public async Task <List <T> > GetAllAsync()
 {
     using var context = new BlogProjectContext();
     return(await context.Set <T>().ToListAsync());
 }
 public async Task <List <T> > GetAllAsync(Expression <Func <T, bool> > filter)
 {
     using var context = new BlogProjectContext();
     return(await context.Set <T>().Where(filter).ToListAsync());
 }
Example #13
0
 public VideoRepository(BlogProjectContext db) : base(db)
 {
 }
Example #14
0
 public BaseRespository(BlogProjectContext db)
 {
     _db = db;
 }
Example #15
0
 public AuthRepository(IOptions <AppSettings> appSettings, BlogProjectContext context)
 {
     _appSettings = appSettings.Value;
     _context     = context;
 }
Example #16
0
 public PostRepository(BlogProjectContext context)
 {
     _context = context;
 }
Example #17
0
 public UserRepository(BlogProjectContext context)
 {
     _context = context;
 }