예제 #1
0
 public async Task <IEnumerable <TodoItem> > GetAllTodoItems()
 {
     return(await _context.Set <TodoItem>()
            .AsNoTracking()
            .ToListAsync()
            .ConfigureAwait(false));
 }
예제 #2
0
        public async Task DeleteUser(TodoUser todoUser)
        {
            var todoUserSet = _dbcontext.Set <TodoUser>();

            todoUserSet.Remove(todoUser);
            await _dbcontext.SaveChangesAsync();
        }
예제 #3
0
 public virtual async Task <IEnumerable <T> > GetItemsAsync()
 {
     using (var db = new TodoDbContext())
     {
         return(await db.Set <T>().ToListAsync());
     }
 }
예제 #4
0
 public virtual async Task <IEnumerable <T> > GetItemsAsync(int page, int pageSize)
 {
     using (var db = new TodoDbContext())
     {
         return(await db.Set <T>().Skip((page - 1) * pageSize).Take(pageSize).ToListAsync());
     }
 }
예제 #5
0
 public T GetItem(params object[] key)
 {
     using (var db = new TodoDbContext())
     {
         return(db.Set <T>().Find(key));
     }
 }
예제 #6
0
 public IEnumerable <T> Filter(Func <T, bool> criteria)
 {
     using (var db = new TodoDbContext())
     {
         return(db.Set <T>().Where(criteria).ToList());
     };
 }
예제 #7
0
 public IEnumerable <T> GetItems()
 {
     using (var db = new TodoDbContext())
     {
         return(db.Set <T>().ToList());
     }
 }
예제 #8
0
 public virtual async Task <T> GetItemAsync(params object[] key)
 {
     using (var db = new TodoDbContext())
     {
         return(await db.Set <T>().FindAsync(key));
     }
 }
예제 #9
0
 public virtual async Task <IEnumerable <T> > FilterAsync(Func <T, bool> criteria)
 {
     using (var db = new TodoDbContext())
     {
         return(await Task.FromResult(db.Set <T>().Where(criteria).ToList()));
     };
 }
예제 #10
0
 public virtual async Task <int> RemoveItemsAsync(IEnumerable <T> list)
 {
     using (var context = new TodoDbContext())
     {
         context.Set <T>().RemoveRange(list);
         return(await context.SaveChangesAsync());
     }
 }
예제 #11
0
 public T AddItem(T tEntity)
 {
     using (var db = new TodoDbContext())
     {
         db.Set <T>().AddAsync(tEntity);
         return(db.SaveChanges() == 1 ? tEntity : null);
     }
 }
예제 #12
0
        public virtual async Task <T> AddItemAsync(T tEntity)
        {
            using (var db = new TodoDbContext())
            {
                await db.Set <T>().AddAsync(tEntity);

                return((await db.SaveChangesAsync()) == 1 ? tEntity : null);
            }
        }
예제 #13
0
        public async Task <int> AddItemsAsync(IList <T> entities)
        {
            using (var context = new TodoDbContext())
            {
                await context.Set <T>().AddRangeAsync(entities);

                return(await context.SaveChangesAsync());
            }
        }
예제 #14
0
        public async Task <IEnumerable <Todo> > TodosAsync(int?id, IEnumerable <int> ids, int?completedByPersonId, CancellationToken cancellationToken)
        {
            IQueryable <Todo> query = _db.Set <Todo>();

            if (id.HasValue)
            {
                query = query.Where(x => x.Id == id);
            }
            if (ids != null)
            {
                query = query.Where(x => ids.Contains(x.Id));
            }
            if (completedByPersonId != null)
            {
                query = query.Where(x => x.CompletedByPersonId == completedByPersonId);
            }

            return(await query.ToListAsync(cancellationToken));
        }
예제 #15
0
 public bool RemoveItem(params object[] itemKey)
 {
     using (var context = new TodoDbContext())
     {
         var item = GetItem(itemKey);
         if (item == null)
         {
             return(false);
         }
         context.Set <T>().Remove(item);
         return(context.SaveChanges() == 1);
     }
 }
예제 #16
0
        public virtual async Task <bool> RemoveItemAsync(params object[] itemKey)
        {
            using (var context = new TodoDbContext())
            {
                var item = await GetItemAsync(itemKey);

                if (item == null)
                {
                    return(false);
                }
                context.Set <T>().Remove(item);
                return(await context.SaveChangesAsync() == 1);
            }
        }
예제 #17
0
        public virtual async Task <IEnumerable <TEntity> > ExecuteQueryAsync <TEntity>(string procNameWithParamNames, KeyValuePair <string, object>[] inData, bool isEntitySet = false) where TEntity : class
        {
            try
            {
                using (var context = new TodoDbContext())
                {
                    var parameterString = string.Join(",", inData.Select(k => !(k.Value.GetType() != typeof(string)) ? $"'{k.Value}'" : k.Value).ToArray());
                    var query           = $"call {procNameWithParamNames} ({parameterString})";
                    IEnumerable <TEntity> queryResult = isEntitySet ?
                                                        await context.Set <TEntity>().FromSql(query).ToListAsync() :
                                                        await context.Query <TEntity>().FromSql(query).ToListAsync();

                    return(queryResult);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
예제 #18
0
 public void Add <T>(T entity) where T : class
 {
     dbContext.Set <T>().Add(entity);
 }
예제 #19
0
        public async Task Create(T entity)
        {
            await _dbContext.Set <T>().AddAsync(entity);

            await _dbContext.SaveChangesAsync();
        }
예제 #20
0
 public IEnumerable <T> Find(Func <T, bool> predicate) => Context.Set <T>().Where(predicate);
예제 #21
0
 public void Add(T entity)
 {
     _todoDbContext.Set <T>().Add(entity);
 }
 public GenericRepository(TodoDbContext context)
 {
     this._context = context;
     this._dbSet   = _context.Set <T> ();
 }
예제 #23
0
 public virtual async Task <T> GetByIdAsync(Guid id)
 {
     return(await _dbContext.Set <T>().FindAsync(id));
 }
예제 #24
0
 public virtual async Task <long> GetCountAsync() => await _dbContext.Set <T>().LongCountAsync();
예제 #25
0
        public bool Create(TodoAggregateRoot root)
        {
            var _root = context.Set <TodoAggregateRoot>().Add(root);

            return(_root.State == EntityState.Added);
        }
예제 #26
0
 public TEntity Get(Guid id)
 {
     return(Context.Set <TEntity>().Find(id));
 }
예제 #27
0
 public ActionResult <IEnumerable <Todo> > Get()
 {
     return(_context.Set <Todo>().ToList());
 }
예제 #28
0
 public Repository(TodoDbContext context)
 {
     _context = context;
     _dbSet   = _context.Set <T>();
 }
예제 #29
0
 public void Add(T entity)
 {
     _context.Set <T>().Add(entity);
     _context.SaveChanges();
 }
예제 #30
0
 public async Task <Todo> GetById(Guid aggregateId)
 {
     return(await context.Set <Todo>().FirstOrDefaultAsync(x => x.AggregateId == aggregateId));
 }