public async Task <bool> StoreInvoice(Invoice invoice) { if (invoice.InvoiceNumber <= 0) { throw new InvalidInvoiceNumberException(); } var beforeSavingEventArgs = new InvoiceBeforeSavingEventArgs(); OnBeforeSaving(beforeSavingEventArgs); if (beforeSavingEventArgs.Cancel) { return(false); } // Process of saving to a remote database would be here... await Task.Delay(500); OnSaved(EventArgs.Empty); return(true); }
protected virtual void OnBeforeSaving(InvoiceBeforeSavingEventArgs e) { BeforeSaving?.Invoke(this, e); }