public async Task <T> Create(T entity) { using (CryptoDbContext context = _contextFactory.CreateDbContext()) { EntityEntry <T> createdResult = await context.Set <T>().AddAsync(entity); await context.SaveChangesAsync(); return(createdResult.Entity); } }
public async Task <Account> Get(int id) { using (CryptoDbContext context = _contextFactory.CreateDbContext()) { Account entity = await context.Accounts.Include(a => a.AccountOwner) .Include(a => a.CryptoInvestments) .FirstOrDefaultAsync((e) => e.Id == id); return(entity); } }
public async Task <bool> Delete(int id) { using (CryptoDbContext context = _contextFactory.CreateDbContext()) { T entity = await context.Set <T>().FirstOrDefaultAsync((e) => e.Id == id); context.Set <T>().Remove(entity); await context.SaveChangesAsync(); return(true); } }
public async Task <CryptoCurrency> Create(CryptoCurrency entity) { using (CryptoDbContext context = _contextFactory.CreateDbContext()) { EntityEntry <CryptoCurrency> created = await context.Set <CryptoCurrency>().AddAsync(entity); await context.SaveChangesAsync(); return(created.Entity); } }