public async Task <IActionResult> CreateInvestment([FromBody] CreateInvestmentCommand command, [FromHeader(Name = "x-requestid")] string requestId) { bool commandResult = false; try { if (Guid.TryParse(requestId, out Guid guid) && guid != Guid.Empty) { var request = new IdentifiedCommand <CreateInvestmentCommand, bool>(command, guid); commandResult = await _mediator.Send(request); } return(commandResult ? (IActionResult)Ok() : (IActionResult)BadRequest()); } catch (Exception ex) { return(BadRequest(ex.Message + " Details: " + ex.InnerException.ToString())); } }
public async Task <IActionResult> CreateInvestment([FromRoute] Guid userId, [FromRoute] Guid accountId, [FromBody] CreateInvestmentRequest request) { var userInfo = this.GetUserInfo(); if (!userId.Equals(userInfo.UserId) || !accountId.Equals(userInfo.AccountId)) { return(BadRequest("Invalid token.")); } if (request is null) { return(BadRequest("Request is null")); } var command = new CreateInvestmentCommand(userInfo.UserId, userInfo.AccountId, request.Description, request.Value, request.Type); var result = await _mediator.Send(command); return(Created($"user/{userId}/account/investment/balance/{result}", new { id = result })); }