Ejemplo n.º 1
0
        public async Task <Transaction> CreateWithRelated(TransactionDto t)
        {
            var tran = new Transaction
            {
                Amount            = t.Amount,
                ExecutionDate     = t.ExecutionDate,
                TransactionTypeId = t.TransactionType.Id,
                OriginCustomerId  = t.OriginCustomer.Id,
                DestCustomerId    = t.DestCustomer.Id,
                TransactionDetail = new TransactionDetail
                {
                    IsFraud        = t.TransactionDetail.IsFraud,
                    IsFlaggedFraud = t.TransactionDetail.IsFlaggedFraud,
                    OldBalanceOrig = t.OriginCustomer.LastBalance,
                    NewBalanceOrig = (t.OriginCustomer.LastBalance - t.Amount),
                    OldBalanceDest = t.DestCustomer.LastBalance,
                    NewBalanceDest = (t.DestCustomer.LastBalance + t.Amount)
                }
            };

            await _dbContext.AddAsync(tran);

            await _dbContext.SaveChangesAsync();

            return(_dbContext.Transaction.Include(x => x.TransactionType)
                   .Include(x => x.DestCustomer)
                   .Include(x => x.OriginCustomer)
                   .Include(x => x.TransactionDetail)
                   .FirstOrDefault(x => x.Id.Equals(tran.Id)));
        }
 public override async Task AtualizarAsync(Account entity)
 {
     using (var context = new FinancialManagerDbContext())
     {
         context.Entry(entity).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
         await context.SaveChangesAsync();
     }
 }
        public override async Task CriarAsync(Account entity)
        {
            using (var context = new FinancialManagerDbContext())
            {
                Items.Add(entity);
                context.Accounts.Add(entity);

                await context.SaveChangesAsync();
            }
        }
 public override async Task AtualizarAsync(Transaction entity)
 {
     using (var context = new FinancialManagerDbContext())
     {
         context.Entry(entity).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
         try
         {
             context.Accounts.Attach(entity.Account);
         }
         catch { }
         await context.SaveChangesAsync();
     }
 }
        public override async Task ExcluirAsync(Account entity)
        {
            var account = Items.SingleOrDefault(c => c.Id == entity.Id);

            if (account != null)
            {
                using (var context = new FinancialManagerDbContext())
                {
                    Items.Remove(account);

                    context.Accounts.Remove(account);
                    await context.SaveChangesAsync();
                }
            }
        }
        public override async Task ExcluirAsync(Transaction entity)
        {
            var transaction = Items.SingleOrDefault(c => c.Id == entity.Id);

            if (transaction != null)
            {
                using (var context = new FinancialManagerDbContext())
                {
                    Items.Remove(transaction);

                    context.Transactions.Remove(transaction);
                    await context.SaveChangesAsync();
                }
            }
        }
        public override async Task CriarAsync(Transaction entity)
        {
            using (var context = new FinancialManagerDbContext())
            {
                Items.Add(entity);
                try
                {
                    context.Accounts.Attach(entity.Account);
                }
                catch { }
                context.Transactions.Add(entity);

                await context.SaveChangesAsync();
            }
        }
        public async Task Create(TEntity entity)
        {
            await _dbContext.Set <TEntity>().AddAsync(entity);

            await _dbContext.SaveChangesAsync();
        }