public async Task <IEnumerable <TodoItem> > GetAllTodoItems() { return(await _context.Set <TodoItem>() .AsNoTracking() .ToListAsync() .ConfigureAwait(false)); }
public async Task DeleteUser(TodoUser todoUser) { var todoUserSet = _dbcontext.Set <TodoUser>(); todoUserSet.Remove(todoUser); await _dbcontext.SaveChangesAsync(); }
public virtual async Task <IEnumerable <T> > GetItemsAsync() { using (var db = new TodoDbContext()) { return(await db.Set <T>().ToListAsync()); } }
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()); } }
public T GetItem(params object[] key) { using (var db = new TodoDbContext()) { return(db.Set <T>().Find(key)); } }
public IEnumerable <T> Filter(Func <T, bool> criteria) { using (var db = new TodoDbContext()) { return(db.Set <T>().Where(criteria).ToList()); }; }
public IEnumerable <T> GetItems() { using (var db = new TodoDbContext()) { return(db.Set <T>().ToList()); } }
public virtual async Task <T> GetItemAsync(params object[] key) { using (var db = new TodoDbContext()) { return(await db.Set <T>().FindAsync(key)); } }
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())); }; }
public virtual async Task <int> RemoveItemsAsync(IEnumerable <T> list) { using (var context = new TodoDbContext()) { context.Set <T>().RemoveRange(list); return(await context.SaveChangesAsync()); } }
public T AddItem(T tEntity) { using (var db = new TodoDbContext()) { db.Set <T>().AddAsync(tEntity); return(db.SaveChanges() == 1 ? tEntity : null); } }
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); } }
public async Task <int> AddItemsAsync(IList <T> entities) { using (var context = new TodoDbContext()) { await context.Set <T>().AddRangeAsync(entities); return(await context.SaveChangesAsync()); } }
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)); }
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); } }
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); } }
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; } }
public void Add <T>(T entity) where T : class { dbContext.Set <T>().Add(entity); }
public async Task Create(T entity) { await _dbContext.Set <T>().AddAsync(entity); await _dbContext.SaveChangesAsync(); }
public IEnumerable <T> Find(Func <T, bool> predicate) => Context.Set <T>().Where(predicate);
public void Add(T entity) { _todoDbContext.Set <T>().Add(entity); }
public GenericRepository(TodoDbContext context) { this._context = context; this._dbSet = _context.Set <T> (); }
public virtual async Task <T> GetByIdAsync(Guid id) { return(await _dbContext.Set <T>().FindAsync(id)); }
public virtual async Task <long> GetCountAsync() => await _dbContext.Set <T>().LongCountAsync();
public bool Create(TodoAggregateRoot root) { var _root = context.Set <TodoAggregateRoot>().Add(root); return(_root.State == EntityState.Added); }
public TEntity Get(Guid id) { return(Context.Set <TEntity>().Find(id)); }
public ActionResult <IEnumerable <Todo> > Get() { return(_context.Set <Todo>().ToList()); }
public Repository(TodoDbContext context) { _context = context; _dbSet = _context.Set <T>(); }
public void Add(T entity) { _context.Set <T>().Add(entity); _context.SaveChanges(); }
public async Task <Todo> GetById(Guid aggregateId) { return(await context.Set <Todo>().FirstOrDefaultAsync(x => x.AggregateId == aggregateId)); }