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()); }
public async Task <TEntity> GetAsync(Expression <Func <TEntity, bool> > filter) { using var context = new UdemyBlogWebSiteContext(); return(await context.Set <TEntity>().FirstOrDefaultAsync(filter)); }
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()); }
public async Task <List <TEntity> > GetAllAsync(Expression <Func <TEntity, bool> > filter) { using var context = new UdemyBlogWebSiteContext(); return(await context.Set <TEntity>().Where(filter).ToListAsync()); }
public async Task <List <TEntity> > GetAllAsync() { using var context = new UdemyBlogWebSiteContext(); return(await context.Set <TEntity>().ToListAsync()); }
public async Task <TEntity> FindByIdAsync(int Id) { using var context = new UdemyBlogWebSiteContext(); return(await context.FindAsync <TEntity>(Id)); }
public async Task DeleteAsync(TEntity entity) { using var context = new UdemyBlogWebSiteContext(); context.Remove(entity); await context.SaveChangesAsync(); }