Пример #1
0
 public async Task <List <TEntity> > GetAll(int offset, int limit)
 {
     using (var dbContext = new raw2Context())
     {
         return(await dbContext.Set <TEntity>().Skip(offset).Take(limit).ToListAsync());
     }
 }
Пример #2
0
 public async Task <TEntity> Get(int id)
 {
     using (var dbContext = new raw2Context())
     {
         return(await dbContext.Set <TEntity>().FindAsync(id));
     }
 }
Пример #3
0
        public async Task <TEntity> Update(TEntity entity)
        {
            using (var dbContext = new raw2Context())
            {
                dbContext.Entry(entity).State = EntityState.Modified;
                await dbContext.SaveChangesAsync();

                return(entity);
            }
        }
Пример #4
0
        public async Task <TEntity> Create(TEntity entity)
        {
            using (var dbContext = new raw2Context())
            {
                dbContext.Set <TEntity>().Add(entity);
                await dbContext.SaveChangesAsync();

                return(entity);
            }
        }
Пример #5
0
 public void AddSearchHistory(string query, int userId)
 {
     Task.Run(() =>
     {
         using (var context = new raw2Context())
         {
             var searchEntry = new SearchEntry(query, userId);
             context.SearchEntry.Add(searchEntry);
             var res = context.SaveChanges();
             return(res != 1 ? null : searchEntry);
         }
     });
 }
Пример #6
0
 public async Task <List <Models.Post> > GetPostAnswers(int id)
 {
     using (var context = new raw2Context())
     {
         return(await context.Post
                .Where(p => p.ParentId == id)
                .Include(p => p.Author)
                .Include(p => p.Comment)
                .ThenInclude(c => c.Author)
                .OrderByDescending(p => p.Score)
                .ToListAsync());
     }
 }
Пример #7
0
        public async Task <List <TEntity> > GetAll(int offset, int limit, TOptions options)
        {
            using (var dbContext = new raw2Context())
            {
                var x = dbContext.Set <TEntity>().Skip(offset).Take(limit);

                foreach (var model in options.IncludedModels)
                {
                    x = x.Include(model);
                }

                return(await x.ToListAsync());
            }
        }
Пример #8
0
 public async Task <Models.Post> GetComplete(int id)
 {
     using (var context = new raw2Context())
     {
         return(await context.Post
                .Include(p => p.PostTag)
                .ThenInclude(pt => pt.Tag)
                .Include(p => p.PostLinkFromPost)
                .ThenInclude(pl => pl.ToPost)
                .Include(p => p.Author)
                .Include(p => p.Comment)
                .ThenInclude(c => c.Author)
                .FirstOrDefaultAsync(p => p.PostId == id));
     }
 }
Пример #9
0
        public async Task <bool> Delete(int id)
        {
            using (var dbContext = new raw2Context())
            {
                var entity = await dbContext.Set <TEntity>().FindAsync(id);

                if (entity == null)
                {
                    return(false);
                }

                dbContext.Set <TEntity>().Remove(entity);
                await dbContext.SaveChangesAsync();

                return(true);
            }
        }
Пример #10
0
 public CommentRepository(raw2Context dbContext) : base(dbContext)
 {
     DbContext = dbContext;
 }
Пример #11
0
 public Repository(raw2Context dbContext)
 {
     DbContext = dbContext;
 }
Пример #12
0
 public SearchRepositoryTests()
 {
     context = new raw2Context();
 }
Пример #13
0
 public SearchRepository(raw2Context dbContext) : base(dbContext)
 {
     DbContext = dbContext;
 }
Пример #14
0
 public UserRepository(raw2Context dbContext) : base(dbContext)
 {
     DbContext = dbContext;
 }
Пример #15
0
 public PostRepository(raw2Context dbContext) : base(dbContext)
 {
     DbContext = dbContext;
 }