Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 4
0
        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);
            }
        }