/// <summary> /// Add further validation logic non-property bound. /// </summary> protected override async Task OnValidateAsync(ValidationContext <Employee> context) { // Ensure that the termination data is always null on an update; unless already terminated then it can no longer be updated. switch (ExecutionContext.Current.OperationType) { case OperationType.Create: context.Value.Termination = null; break; case OperationType.Update: var existing = await _employeeDataSvc.GetAsync(context.Value.Id).ConfigureAwait(false); if (existing == null) { throw new NotFoundException(); } if (existing.Termination != null) { throw new ValidationException("Once an Employee has been Terminated the data can no longer be updated."); } context.Value.Termination = null; break; } }
public Task <Employee?> GetAsync(Guid id) { return(ManagerInvoker.Current.InvokeAsync(this, async() => { ExecutionContext.Current.OperationType = OperationType.Read; Cleaner.CleanUp(id); id.Validate(nameof(id)).Mandatory().Run().ThrowOnError(); return Cleaner.Clean(await _dataService.GetAsync(id).ConfigureAwait(false)); })); }
public async Task <Employee?> GetAsync(Guid id) => await ManagerInvoker.Current.InvokeAsync(this, async() => { Cleaner.CleanUp(id); await id.Validate(nameof(id)).Mandatory().RunAsync(throwOnError: true).ConfigureAwait(false); return(Cleaner.Clean(await _dataService.GetAsync(id).ConfigureAwait(false))); }, BusinessInvokerArgs.Read).ConfigureAwait(false);