public async Task <IActionResult> Execute(JObject obj, string subject, string commonId) { if (obj == null) { throw new ArgumentNullException(nameof(obj)); } if (string.IsNullOrWhiteSpace(subject)) { throw new ArgumentNullException(nameof(subject)); } // 1. Check the request AddMessageCommand command = null; try { command = _requestBuilder.GetAddMessage(obj); } catch (ArgumentException ex) { var error = _responseBuilder.GetError(ErrorCodes.Request, ex.Message); return(_controllerHelper.BuildResponse(HttpStatusCode.BadRequest, error)); } command.From = subject; var validationResult = await _addMessageValidator.Validate(command); if (!validationResult.IsValid) { var error = _responseBuilder.GetError(ErrorCodes.Request, validationResult.Message); return(_controllerHelper.BuildResponse(HttpStatusCode.BadRequest, error)); } command.Id = Guid.NewGuid().ToString(); command.CreateDateTime = DateTime.UtcNow; command.CommonId = commonId; // 2. Send the command. var res = new { id = command.Id }; _commandSender.Send(command); return(new OkObjectResult(res)); }