public IHttpActionResult Create(int?Id, TransactionBindingModel transactionBinding)
        {
            // Id being the id of the bankAccount
            if (ModelState is null || !ModelState.IsValid || Id is null)
            {
                return(BadRequest(ModelState));
            }

            var bankAccount = DbContext.BankAccounts.FirstOrDefault(p => p.Id == Id);

            if (bankAccount is null)
            {
                return(BadRequest("No bank account with that Id"));
            }

            // Ensure that the bank account and category are in the same houeshold.
            if (!bankAccount.Household.Categories.Any(p => p.Id == transactionBinding.CategoryId))
            {
                return(BadRequest("No category with that Id"));
            }

            var transaction = new Transaction
            {
                Title         = transactionBinding.Title,
                Description   = transactionBinding.Description,
                CategoryId    = transactionBinding.CategoryId,
                Date          = transactionBinding.Date,
                Amount        = transactionBinding.Amount,
                CreatorId     = User.Identity.GetUserId(),
                DateCreated   = DateTime.Now,
                DateUpdated   = null,
                BankAccountId = (int)Id,
                IsVoid        = false
            };

            bankAccount.AddTransaction(transaction);
            DbContext.SaveChanges();

            var transactionView = TransactionHelpers.MapToView(transaction);

            return(Created(Url.Link(
                               "GetTransactionById",
                               new { transaction.Id }),
                           transactionView
                           ));
        }
        public IHttpActionResult GetAllByHousehold(int?Id)
        {
            var userId = User.Identity.GetUserId();

            if (userId is null)
            {
                return(Unauthorized());
            }

            var transactions = DbContext.Households.FirstOrDefault(p => p.Id == Id).BankAccounts.SelectMany(p => p.Transactions).ToList();

            if (transactions is null)
            {
                return(BadRequest("No Transactions for this household"));
            }

            var transactionsView = transactions.Select(p => TransactionHelpers.MapToView(p));

            return(Ok(transactionsView));
        }
        private IHttpActionResult OkView(List <Transaction> transactions)
        {
            var transactionViews = transactions.Select(p => TransactionHelpers.MapToView(p));

            return(Ok(transactionViews));
        }
        private IHttpActionResult OkView(Transaction transaction)
        {
            var transactionView = TransactionHelpers.MapToView(transaction);

            return(Ok(transactionView));
        }