public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { var financierId = (Guid)context.ActionArguments["financierId"]; GetFinancier queryParams = new GetFinancier { FinancierID = financierId }; FinancierDetail readModel = await _queryService.Query(queryParams); if (readModel is null) { _logger.LogInfo($"A financier with id: {financierId} does not exist in the database."); context.Result = new NotFoundResult(); } else { EditFinancierInfo editFinancierInfo = new EditFinancierInfo { Id = readModel.FinancierId, FinancierName = readModel.FinancierName, Telephone = readModel.Telephone, IsActive = readModel.IsActive, UserId = readModel.UserId }; context.HttpContext.Items.Add("EditFinancierInfo", editFinancierInfo); await next(); } }
public async Task ShouldGet_FinancierDetails_UsingGetFinancierDetailsQueryParameters() { var getFinancierDetails = new GetFinancier { FinancierID = new Guid("94b1d516-a1c3-4df8-ae85-be1f34966601") }; var financierDetails = await _financierQrySvc.Query(getFinancierDetails); Assert.Equal("Paul Van Horn Enterprises", financierDetails.FinancierName); Assert.Equal("415-328-9870", financierDetails.Telephone); }
public async Task <IActionResult> CreateFinancierInfo([FromBody] CreateFinancierInfo writeModel) { try { await _commandHandler.Handle(writeModel); GetFinancier queryParams = new GetFinancier { FinancierID = writeModel.Id }; IActionResult retValue = await _queryRequestHandler.Handle <GetFinancier>(queryParams, HttpContext, Response); return(CreatedAtAction(nameof(GetFinancierDetails), new { financierId = writeModel.Id }, (retValue as OkObjectResult).Value)); } catch (Exception ex) { _logger.LogError(ex.Message); return(BadRequest(ex.Message)); } }
public async Task <IActionResult> GetFinancierDetails(Guid financierId) { GetFinancier queryParams = new GetFinancier { FinancierID = financierId }; try { var retValue = await _queryRequestHandler.Handle <GetFinancier>(queryParams, HttpContext, Response); return(retValue); } catch (Exception ex) { _logger.LogError($"An exception has been thrown: {ex}"); return(BadRequest(ex.Message)); } }