When I take user data and pass it to a command so I can pass it to the endpoint (controller method), the response doesn't even point me in the direction of the specified endpoint. I'm using Blazor and.net 8 and I want to create a new reservation. It also directs me when I try to access the endpoint without the command.
public async Task<Result<ReservationDto>?> CreateReservationsAsync(string name, string surname, DateOnly birthday, string ssn) { var reservationCommand = new CreateReservationCommand { Name = name, Surname = surname, Birthday = birthday, Ssn = ssn }; var response = await _httpClient.PostAsJsonAsync("api/admin/Reservation/create", reservationCommand); return await response.Content.ReadFromJsonAsync<Result<ReservationDto>>(); } [HttpPost("create")] public async Task<IActionResult> CreateReservationAsync([FromBody] CreateReservationCommand command) { var result = await Mediator?.Send(command)!; if (result.Failed) { return BadRequest(result); } return Ok(result.Value); }I am expectin to direct me to the specified endpoind, with the command provided from front end.
Also, when I change the controller method to this, it works, but i want to use the above type of method:
[HttpPost("create")] public async Task<IActionResult> CreateReservationAsync() { var requestBody = await new StreamReader(Request.Body).ReadToEndAsync(); var command = JsonConvert.DeserializeObject<CreateReservationCommand>(requestBody); var result = await Mediator?.Send(command)!; if (result.Failed) { return BadRequest(result); } return Ok(result.Value); }