Пример #1
0
        public async Task <IActionResult> CreateAuditApplicationAsync([FromBody] CreateAuditApplicationCommand command, [FromHeader(Name = "x-requestid")] string requestId)
        {
            if (Guid.TryParse(requestId, out Guid guid) && guid != Guid.Empty)
            {
                var requestCreateAuditApplication = new IdentifiedCommand <CreateAuditApplicationCommand, Result <long> >(command, guid);

                _logger.LogInformation(
                    "----- Sending command: {CommandName} - ({@Command})",
                    requestCreateAuditApplication.GetGenericTypeName(),
                    requestCreateAuditApplication);

                var commandResult = await _mediator.Send(requestCreateAuditApplication).ConfigureAwait(false);

                if (commandResult.IsFailure)
                {
                    return(BadRequest());
                }
            }
            else
            {
                return(BadRequest(Constants.ErrorMessages.XRequestIdIsMissing));
            }

            return(StatusCode(201));
        }
Пример #2
0
        public async Task PostAudit()
        {
            //Arrange
            var createAuditApplicationCommand = new CreateAuditApplicationCommand
            {
                Name        = "NewTestAuditApplication",
                Description = "New Audit Application",
                ClientId    = "aClientId"
            };

            //Act
            var response = await _client.PostAsJsonAsync("/api/v1/applications", createAuditApplicationCommand);

            response.EnsureSuccessStatusCode();

            //Assert
            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
        }
Пример #3
0
        public async Task <IActionResult> CreateAuditApplicationAsync([FromBody] CreateAuditApplicationCommand command, [FromHeader(Name = "x-requestid")] string requestId)
        {
            long commandResult = -1;

            if (Guid.TryParse(requestId, out Guid guid) && guid != Guid.Empty)
            {
                var requestCreateAuditApplication = new IdentifiedCommand <CreateAuditApplicationCommand, long>(command, guid);

                _logger.LogInformation(
                    "----- Sending command: {CommandName} - ({@Command})",
                    requestCreateAuditApplication.GetGenericTypeName(),
                    requestCreateAuditApplication);

                commandResult = await _mediator.Send(requestCreateAuditApplication).ConfigureAwait(false);
            }

            if (commandResult == -1)
            {
                return(BadRequest());
            }

            return(Ok(commandResult));
        }