Beispiel #1
0
 public async Task DeleteByIdsAsync <T>(IEnumerable <Int32> ids) where T : class, IEntity
 {
     using (var context = new AppsEntities())
     {
         var items = context.Set <T>().Where(e => ids.Contains(e.ID));
         context.Set <T>().RemoveRange(items);
         await context.SaveChangesAsync();
     }
 }
Beispiel #2
0
 public IEnumerable <T> Get <T>() where T : class
 {
     using (var context = new AppsEntities())
     {
         return(context.Set <T>().AsNoTracking().ToList());
     }
 }
Beispiel #3
0
 public async Task <T> GetSingleAsync <T>(Expression <Func <T, bool> > filter) where T : class, IEntity
 {
     using (var context = new AppsEntities())
     {
         return(await context.Set <T>().FirstOrDefaultAsync(filter));
     }
 }
Beispiel #4
0
 public async Task <T> GetSingleAsync <T>(int id) where T : class, IEntity
 {
     using (var context = new AppsEntities())
     {
         return(await context.Set <T>().FirstOrDefaultAsync(e => e.ID == id));
     }
 }
Beispiel #5
0
 public T GetSingle <T>(int id) where T : class, IEntity
 {
     using (var context = new AppsEntities())
     {
         return(context.Set <T>().FirstOrDefault(e => e.ID == id));
     }
 }
Beispiel #6
0
 public IEnumerable <T> GetFiltered <T>(Expression <Func <T, bool> > filter) where T : class
 {
     using (var context = new AppsEntities())
     {
         return(context.Set <T>().AsNoTracking().Where(filter).ToList());
     }
 }
Beispiel #7
0
 public async Task SaveNewEntityRangeAsync <T>(IEnumerable <T> items) where T : class
 {
     using (var context = new AppsEntities())
     {
         context.Set <T>().AddRange(items);
         await context.SaveChangesAsync();
     }
 }
Beispiel #8
0
 public void SaveNewEntityRange <T>(IEnumerable <T> items) where T : class
 {
     using (var context = new AppsEntities())
     {
         context.Set <T>().AddRange(items);
         context.SaveChanges();
     }
 }
Beispiel #9
0
 public async Task SaveNewEntityAsync <T>(T item) where T : class
 {
     using (var context = new AppsEntities())
     {
         context.Set <T>().Add(item);
         await context.SaveChangesAsync();
     }
 }
Beispiel #10
0
 public void SaveNewEntity <T>(T item) where T : class
 {
     using (var context = new AppsEntities())
     {
         context.Set <T>().Add(item);
         context.SaveChanges();
     }
 }
Beispiel #11
0
 public Task <List <T> > GetFilteredAsync <T>(Expression <Func <T, bool> > filter) where T : class
 {
     using (var context = new AppsEntities())
     {
         var set = context.Set <T>().AsQueryable();
         return(set.AsNoTracking().Where(filter).ToListAsync());
     }
 }
Beispiel #12
0
        public async Task DeleteScreenshotsById(IEnumerable <Int32> ids)
        {
            using (var context = new AppsEntities())
            {
                var screenshots = await context.Set <Screenshot>().Where(s => ids.Contains(s.ID)).ToListAsync();

                context.Screenshots.RemoveRange(screenshots);
                await context.SaveChangesAsync();
            }
        }
Beispiel #13
0
 public Task <List <T> > GetAsync <T>(params Expression <Func <T, object> >[] navigations) where T : class
 {
     using (var context = new AppsEntities())
     {
         IQueryable <T> query = context.Set <T>().AsQueryable();
         foreach (var nav in navigations)
         {
             query = query.Include(nav);
         }
         return(query.AsNoTracking().ToListAsync <T>());
     }
 }
Beispiel #14
0
 public IEnumerable <T> GetFiltered <T>(Expression <Func <T, bool> > filter, params Expression <Func <T, object> >[] navigations) where T : class
 {
     using (var context = new AppsEntities())
     {
         var query = context.Set <T>().AsQueryable();
         foreach (var nav in navigations)
         {
             query = query.Include(nav);
         }
         return(query.AsNoTracking().Where(filter).ToList());
     }
 }
Beispiel #15
0
 public IEnumerable <T> GetOrderedDesc <T, TKey>(Expression <Func <T, bool> > filter,
                                                 Expression <Func <T, TKey> > selector,
                                                 int count) where T : class
 {
     using (var context = new AppsEntities())
     {
         return(context.Set <T>()
                .AsNoTracking()
                .Where(filter)
                .OrderByDescending(selector)
                .Take(count)
                .ToList());
     }
 }