public async Task <IActionResult> CreateItem([FromBody] CatalogItemCreateViewModel model, [FromHeader(Name = "x-requestid")] string requestId) { model.RequestId = (Guid.TryParse(requestId, out Guid guid) && guid != Guid.Empty) ? guid : Guid.NewGuid(); if (ModelState.IsValid) { if (model.RequestId != Guid.Empty) { var createCatalogItemCommand = new CreateCatalogItemCommand(model.Name, model.Price, model.Color); var requestUpdateCatalogItem = new IdentifiedCommand <CreateCatalogItemCommand, CatalogItem>(createCatalogItemCommand, model.RequestId); var result = await _mediator.Send(requestUpdateCatalogItem); } return(Ok(model)); } return(BadRequest(ModelState)); }
public async Task <IActionResult> CreateCatalogItemAsync(CreateCatalogItemCommand command) { return(Ok(await _mediator.Send(command))); }