Ejemplo n.º 1
0
        public bool Add(string connectionString, ApiModels.Transaction transaction, Guid id)
        {
            if (transaction != null)
            {
                using (var context = new AccountsDatabase(connectionString))
                {
                    var accountsRepo = new AccountsRepository();
                    var account      = accountsRepo.GetAccount(connectionString, id);
                    account.Amount += transaction.Amount;
                    if (!accountsRepo.Update(connectionString, account))
                    {
                        return(false);
                    }

                    context.Transactions.Add(new Entities.Transaction()
                    {
                        Amount    = transaction.Amount,
                        Date      = transaction.Date,
                        AccountId = account.Id,
                        Id        = Guid.NewGuid()
                    });

                    context.SaveChanges();

                    return(true);
                }
            }

            return(false);
        }
        public IHttpActionResult AddTransaction(Guid id, ApiModels.Transaction transaction)
        {
            var repo = new TransactionsRepository();

            if (repo.Add(_connectionString, transaction, id))
            {
                return(Ok());
            }

            return(BadRequest("Could not update account amount"));;
        }