public async Task <ActionResult <CheckResult> > Get([FromRoute] CheckOrderOnStockCommand command) { var result = new CheckResult(); // the lab business rule has exploded and we decide to return a bad request // in a real system a middleware/filter and a proper problem details implementation should // should be used for proper error and return code handling try { result.OnStock = await _orderCheckingService.IsOnStockAsync(command); if (result.OnStock) { return(Ok(result)); } else { return(NotFound(result)); } } catch (ArgumentOutOfRangeException e) { return(BadRequest(e.Message)); } }
public async Task <bool> IsOnStockAsync(CheckOrderOnStockCommand command) { var labs = await _labProvider.GetExistingLabNamesAsync(); // check business rules - in this case we check if we have a valid lab command.Validate(labs); return(await _repo.IsOrderOnStockAsync(command.OPC, command.Lab)); }
public static void Validate(this CheckOrderOnStockCommand checkOrder, List <string> validLabs) { // check if we have a valid lab if (!validLabs.Contains(checkOrder.Lab)) { throw new ArgumentOutOfRangeException($"The lab '{checkOrder.Lab}' does not exist."); } }