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();
            }
        }
        /// <summary>
        /// Inicializa o objeto singleton do aplicativo.  Esta é a primeira linha de código criado
        /// executado e, como tal, é o equivalente lógico de main() ou WinMain().
        /// </summary>
        public App()
        {
            this.InitializeComponent();
            this.Suspending += OnSuspending;

            using (var db = new FinancialManagerDbContext())
            {
                db.Database.Migrate();
            }
        }
 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 CarregarTodosAsync()
        {
            using (var context = new FinancialManagerDbContext())
            {
                Items.Clear();

                var accounts = context.Accounts.Include(x => x.Transactions).ToList();

                foreach (var account in accounts)
                {
                    Items.Add(account);
                }
            }
        }
        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();
            }
        }
Пример #9
0
 public TransactionRepository(FinancialManagerDbContext dbContext) : base(dbContext)
 {
     _dbContext = dbContext;
 }
 public GenericRepository(FinancialManagerDbContext dbContext)
 {
     _dbContext = dbContext;
 }
 public CustomerRepository(FinancialManagerDbContext dbContext) : base(dbContext)
 {
     _dbContext = dbContext;
 }