Exemplo n.º 1
0
        public async Task AddAsync(TEntity entity)
        {
            using var context = new UdemyBlogWebSiteContext();
            await context.AddAsync(entity);

            await context.SaveChangesAsync();
        }
 public async Task <List <Blog> > GetAllByCategoryIdAsync(int categoryId)
 {
     using var context = new UdemyBlogWebSiteContext();
     return(await context.Blogs.Join(context.CategoryBlogs, b => b.Id, cb => cb.BlogId, (blog, CategoryBlog) => new
     {
         blog = blog,
         categoryBlog = 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());
 }
 public async Task <List <Category> > GetAllWithCategoryBlogsAsync()
 {
     using var context = new UdemyBlogWebSiteContext();
     return(await context.Categories.OrderByDescending(I => I.Id).Include(I => I.CategoryBlogs).ToListAsync());
 }
Exemplo n.º 4
0
 public async Task <TEntity> GetAsync(Expression <Func <TEntity, bool> > filter)
 {
     using var context = new UdemyBlogWebSiteContext();
     return(await context.Set <TEntity>().FirstOrDefaultAsync(filter));
 }
Exemplo n.º 5
0
 public async Task <List <TEntity> > GetAllAsync <TKey>(Expression <Func <TEntity, TKey> > keySelector)//Sort edilmiş hali
 {
     using var context = new UdemyBlogWebSiteContext();
     return(await context.Set <TEntity>().OrderByDescending(keySelector).ToListAsync());
 }
Exemplo n.º 6
0
 public async Task <List <TEntity> > GetAllAsync(Expression <Func <TEntity, bool> > filter)
 {
     using var context = new UdemyBlogWebSiteContext();
     return(await context.Set <TEntity>().Where(filter).ToListAsync());
 }
Exemplo n.º 7
0
 public async Task <List <TEntity> > GetAllAsync()
 {
     using var context = new UdemyBlogWebSiteContext();
     return(await context.Set <TEntity>().ToListAsync());
 }
Exemplo n.º 8
0
 public async Task <TEntity> FindByIdAsync(int Id)
 {
     using var context = new UdemyBlogWebSiteContext();
     return(await context.FindAsync <TEntity>(Id));
 }
Exemplo n.º 9
0
 public async Task DeleteAsync(TEntity entity)
 {
     using var context = new UdemyBlogWebSiteContext();
     context.Remove(entity);
     await context.SaveChangesAsync();
 }