AllReady.Controllers.RequestApiController.Post C# (CSharp) Метод

Post() приватный Метод

private Post ( [ viewModel ) : Task
viewModel [
Результат Task
        public async Task<IActionResult> Post([FromBody]RequestApiViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest();
            }

            //we can only accept the requests with the status of "new" from getasmokealarm
            if (viewModel.Status != "new")
            {
                return BadRequest();
            }

            //if we get here, the incoming request is already in our database with a matching ProviderId ("serial" field for getasmokealarm) and the request was sent with a status of "new"
            if (await mediator.SendAsync(new RequestExistsByProviderIdQuery { ProviderRequestId = viewModel.ProviderRequestId }))
            {
                return BadRequest();
            }

            //this returns control to the caller immediately so the client is not left locked while we figure out if we can service the request
            backgroundjobClient.Enqueue<IProcessApiRequests>(x => x.Process(viewModel));

            //https://httpstatuses.com/202
            return StatusCode(202);
        }
    }

Usage Example

        public async Task PostReturnsBadRequest_WhenRequestIdIsNotAGuid()
        {
            var sut = new RequestApiController(Mock.Of<IMediator>());
            var result = await sut.Post(new RequestViewModel {RequestId = "NotAGuid"});

            Assert.IsType<BadRequestObjectResult>(result);
        }
All Usage Examples Of AllReady.Controllers.RequestApiController::Post
RequestApiController