diff --git a/Commands/Handlers/Transaction/AddCreditTransaction/AddCreditTransactionHandler.cs b/Commands/Handlers/Transaction/AddCreditTransaction/AddCreditTransactionHandler.cs index b78c3f8e..0fae06f9 100644 --- a/Commands/Handlers/Transaction/AddCreditTransaction/AddCreditTransactionHandler.cs +++ b/Commands/Handlers/Transaction/AddCreditTransaction/AddCreditTransactionHandler.cs @@ -1,6 +1,4 @@ - -using Commands.Handlers.FinancialYear.AddFinancialYear; -using Commands.Handlers.Transaction.AddAttachments; +using Commands.Handlers.Transaction.AddAttachments; using Domain; using Domain.Interfaces; @@ -17,12 +15,12 @@ public AddCreditTransactionHandler(IFinancialYearRepository financialYearReposit _financialYearRepository = financialYearRepository; _mediator = mediator; } - + public async Task Handle(AddCreditTransactionCommand request, CancellationToken cancellationToken) { var financialYear = - await _financialYearRepository.GetFinancialYearByTransactionId(request.FinancialYearId, cancellationToken) - ?? await _mediator.Send(new AddFinancialYearCommand(), cancellationToken); + await _financialYearRepository.GetByIdAsync(request.FinancialYearId, cancellationToken) + ?? throw new Exception("Could not get financial year specified in AddTransaction command"); var totalAmount = request.TransactionTypeAmounts.Sum(x => x.Amount); var transaction = new CreditTransaction(request.CounterPartyName, request.BankAccountId, totalAmount, diff --git a/Commands/Handlers/Transaction/AddDebitTransaction/AddDebitTransactionHandler.cs b/Commands/Handlers/Transaction/AddDebitTransaction/AddDebitTransactionHandler.cs index fc7c1362..94b2a9b6 100644 --- a/Commands/Handlers/Transaction/AddDebitTransaction/AddDebitTransactionHandler.cs +++ b/Commands/Handlers/Transaction/AddDebitTransaction/AddDebitTransactionHandler.cs @@ -1,5 +1,4 @@ -using Commands.Handlers.FinancialYear.AddFinancialYear; -using Commands.Handlers.Transaction.AddAttachments; +using Commands.Handlers.Transaction.AddAttachments; using Domain; using Domain.Interfaces; @@ -19,8 +18,8 @@ public AddDebitTransactionHandler(IFinancialYearRepository financialYearReposito public async Task Handle(AddDebitTransactionCommand request, CancellationToken cancellationToken) { var financialYear = - await _financialYearRepository.GetFinancialYearByTransactionId(request.FinancialYearId, cancellationToken) - ?? await _mediator.Send(new AddFinancialYearCommand(), cancellationToken); + await _financialYearRepository.GetByIdAsync(request.FinancialYearId, cancellationToken) + ?? throw new Exception("Could not get financial year specified in AddTransaction command"); var totalAmount = request.TransactionTypeAmounts.Sum(x => x.Amount); var transaction = new DebitTransaction(request.CounterPartyName, request.BankAccountId, totalAmount, diff --git a/Commands/Handlers/Transaction/EditTransaction/EditTransactionHandler.cs b/Commands/Handlers/Transaction/EditTransaction/EditTransactionHandler.cs index 4e567be8..1d8b4050 100644 --- a/Commands/Handlers/Transaction/EditTransaction/EditTransactionHandler.cs +++ b/Commands/Handlers/Transaction/EditTransaction/EditTransactionHandler.cs @@ -1,5 +1,4 @@ -using Commands.Handlers.FinancialYear.AddFinancialYear; -using Commands.Handlers.Transaction.AddAttachments; +using Commands.Handlers.Transaction.AddAttachments; using Domain.Interfaces; @@ -18,9 +17,8 @@ public EditTransactionHandler(IFinancialYearRepository financialYearRepository, public async Task Handle(EditTransactionCommand request, CancellationToken cancellationToken) { - var financialYear = - await _financialYearRepository.GetFinancialYearByTransactionId(request.Id, cancellationToken) - ?? throw new ArgumentException($"No transaction found for Id {request.Id}", nameof(request)); + var financialYear = await _financialYearRepository.GetFinancialYearByTransactionId(request.Id, cancellationToken) + ?? throw new ArgumentException($"No transaction found for Id {request.Id}", nameof(request)); if (financialYear.StartDate <= request.ReceivedDateTime && financialYear.EndDate >= request.ReceivedDateTime) @@ -33,9 +31,8 @@ await _financialYearRepository.GetFinancialYearByTransactionId(request.Id, cance var transaction = financialYear.Transactions.First(x => x.Id == request.Id); var matchingFinancialYear = - await _financialYearRepository.GetFinancialYearByTransactionId(request.FinancialYearId, - cancellationToken) - ?? await _mediator.Send(new AddFinancialYearCommand(), cancellationToken); + await _financialYearRepository.GetByIdAsync(request.FinancialYearId, cancellationToken) + ?? throw new Exception("Could not get financial year specified in AddTransaction command"); matchingFinancialYear.AddTransaction(transaction); matchingFinancialYear.ChangeTransaction(request.Id, request.CounterPartyName, request.MemberId, request.BankAccountId, diff --git a/Web/Pages/FinancialYears/FinancialYears.razor b/Web/Pages/FinancialYears/FinancialYears.razor index 8d1f22c6..2afe5070 100644 --- a/Web/Pages/FinancialYears/FinancialYears.razor +++ b/Web/Pages/FinancialYears/FinancialYears.razor @@ -1,5 +1,6 @@ @page "/financialyears" @attribute [Authorize] +@using Commands.Handlers.FinancialYear.AddFinancialYear; @using Queries.FinancialYears @using Commands.Handlers.FinancialYear.CloseFinancialYear @@ -14,6 +15,11 @@ ServerData="@(new Func>>(ServerReload))"> Financial years + + + Add Financial Year + @@ -67,7 +73,7 @@ private async Task> ServerReload(TableState state) { StateHasChanged(); - + var query = new GetFinancialYearsQuery(); var data = await _mediator.Send(query); @@ -99,4 +105,10 @@ table?.ReloadServerData(); } } + + private async Task AddFinancialYear() + { + await _mediator.Send(new AddFinancialYearCommand()); + table?.ReloadServerData(); + } } \ No newline at end of file