diff options
Diffstat (limited to 'src/app/Cmpp298.Assignment3.Desktop.Presentation/EditInvoicePresenter.cs')
| -rw-r--r-- | src/app/Cmpp298.Assignment3.Desktop.Presentation/EditInvoicePresenter.cs | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/app/Cmpp298.Assignment3.Desktop.Presentation/EditInvoicePresenter.cs b/src/app/Cmpp298.Assignment3.Desktop.Presentation/EditInvoicePresenter.cs new file mode 100644 index 0000000..eaaf8e6 --- /dev/null +++ b/src/app/Cmpp298.Assignment3.Desktop.Presentation/EditInvoicePresenter.cs @@ -0,0 +1,62 @@ +using Cmpp298.Assignment3.Domain;
+using Cmpp298.Assignment3.Dto;
+using Cmpp298.Assignment3.Task;
+
+namespace Cmpp298.Assignment3.Presentation {
+ public class EditInvoicePresenter {
+ private readonly string _invoiceId;
+ private readonly IEditInvoiceView _view;
+ private readonly IInvoiceTask _task;
+ private readonly ITermTask _termTask;
+
+ public EditInvoicePresenter( string invoiceId, IEditInvoiceView view )
+ : this( invoiceId, view, new InvoiceTask( ), new TermTask( ) ) {}
+
+ public EditInvoicePresenter( string invoiceId, IEditInvoiceView view, IInvoiceTask task, ITermTask termTask ) {
+ _view = view;
+ _task = task;
+ _termTask = termTask;
+ _invoiceId = invoiceId;
+ }
+
+ public void Initialize( ) {
+ _view.TermsDropDown.BindTo( _termTask.GetAll( ) );
+ UpdateViewFrom( _task.GetInvoiceBy( _invoiceId ) );
+ }
+
+ public void UpdateInvoice( ) {
+ if ( IsValidInput( ) ) {
+ _task.UpdateInvoice( CreateDtoFromView( ) );
+ }
+ else {
+ _view.ShowError( "Invalid input detected" );
+ }
+ }
+
+ private void UpdateViewFrom( DisplayInvoiceDto dto ) {
+ _view.VendorName = dto.VendorName;
+ _view.InvoiceNumber = dto.InvoiceNumber;
+ _view.InvoiceDate = dto.InvoiceDate;
+ _view.InvoiceTotal = dto.InvoiceTotal;
+ _view.PaymentTotal = dto.PaymentTotal;
+ _view.CreditTotal = dto.CreditTotal;
+ _view.DueDate = dto.DueDate;
+ _view.PaymentDate = dto.PaymentDate;
+ _view.TermsDropDown.SetSelectedItemTo( dto.Terms );
+ }
+
+ private bool IsValidInput( ) {
+ AmountEntrySpecification specification = new AmountEntrySpecification( );
+ return
+ specification.IsSatisfiedBy( _view.CreditTotal )
+ && specification.IsSatisfiedBy( _view.PaymentTotal )
+ && specification.IsSatisfiedBy( _view.InvoiceTotal );
+ }
+
+ private UpdateInvoiceDto CreateDtoFromView( ) {
+ return
+ new UpdateInvoiceDto( _invoiceId, _view.InvoiceNumber, _view.InvoiceDate, _view.InvoiceTotal, _view.PaymentTotal,
+ _view.CreditTotal, _view.DueDate, _view.PaymentDate, _view.TermsDropDown.SelectedItem.Value );
+ }
+ }
+}
\ No newline at end of file |
