Ejemplo n.º 1
0
        public async Task <IActionResult> ContinueApplication([FromRoute] long applicationNumber, [FromBody] ContinueApplicationCommand command)
        {
            command.ApplicationNumber = applicationNumber;
            command.Username          = GetUsernameFromToken();
            command.AuditLog          = AuditLog();

            var           continueApplicationCommand = new IdentifiedCommand <ContinueApplicationCommand, CommandStatus>(command, new Guid());
            CommandStatus commandStatus = await _mediator.Send(continueApplicationCommand);

            if (commandStatus.CommandResult.Equals(StandardCommandResult.OK))
            {
                return(Ok());
            }
            else if (commandStatus.CommandResult.Equals(StandardCommandResult.BAD_REQUEST))
            {
                if (commandStatus.CustomError != null)
                {
                    return(BadRequest(commandStatus.CustomError));
                }
                return(BadRequest());
            }
            else if (commandStatus.CommandResult.Equals(StandardCommandResult.NOT_FOUND))
            {
                return(NotFound());
            }
            else
            {
                return(StatusCode(500));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> SetStatusToAvailableAsync(
            [FromRoute] SetAvailableDeliveryStatusCommand setAvailableDeliveryStatusCommand,
            [FromHeader(Name = "x-requestid")] Guid requestId)
        {
            var commandResult = false;

            if (requestId != Guid.Empty)
            {
                var requestSetAvailableDeliveryStatusCommand =
                    new IdentifiedCommand <SetAvailableDeliveryStatusCommand, bool>(setAvailableDeliveryStatusCommand,
                                                                                    requestId);

                _logger.LogInformation(
                    "----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})",
                    requestSetAvailableDeliveryStatusCommand.GetGenericTypeName(),
                    nameof(requestSetAvailableDeliveryStatusCommand.Command.DeliveryId),
                    requestSetAvailableDeliveryStatusCommand.Command.DeliveryId,
                    requestSetAvailableDeliveryStatusCommand);

                commandResult = await _mediator.Send(requestSetAvailableDeliveryStatusCommand);
            }

            if (!commandResult)
            {
                return(BadRequest());
            }

            return(Ok());
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> DeleteAsync([FromRoute] DeleteDeliveryCommand deleteDeliveryCommand,
                                                      [FromHeader(Name = "x-requestid")] Guid requestId)
        {
            var commandResult = false;

            if (requestId != Guid.Empty)
            {
                var requestDeleteDelivery =
                    new IdentifiedCommand <DeleteDeliveryCommand, bool>(deleteDeliveryCommand, requestId);

                _logger.LogInformation(
                    "----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})",
                    requestDeleteDelivery.GetGenericTypeName(),
                    nameof(requestDeleteDelivery.Command.DeliveryId),
                    requestDeleteDelivery.Command.DeliveryId,
                    requestDeleteDelivery);

                commandResult = await _mediator.Send(requestDeleteDelivery);
            }

            if (!commandResult)
            {
                return(BadRequest());
            }

            return(NoContent());
        }
Ejemplo n.º 4
0
        private async Task <bool?> HandleSuppliersBuyersReportRemoved(string messageName, MessageEvent messageEvent)
        {
            _logger.LogDebug("Handling message {MessageName}", messageName);
            _logger.LogDebug("Handling message content {MessageContent}", messageEvent.getText());
            string applicationNumber;

            try
            {
                applicationNumber = messageEvent.getStringProperty("XAseeApplicationNumber");
            }
            catch (KeyNotFoundException e)
            {
                _logger.LogError(e, "An error occurred while handling removal of suppliers-buyers report");
                return(false);
            }
            dynamic reportData = JsonConvert.DeserializeObject(messageEvent.getText());

            if (reportData == null || string.IsNullOrEmpty(reportData["party-number"]?.ToString()))
            {
                return(false);
            }

            var customerNumber = reportData["party-number"].ToString();

            var updateDocumentStatusCommand = new IdentifiedCommand <SetSuppliersBuyersReportCommand, bool?>
                                                  (new SetSuppliersBuyersReportCommand
                                                  (
                                                      long.Parse(applicationNumber), customerNumber, null
                                                  ), new Guid());

            return(await _mediator.Send(updateDocumentStatusCommand));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> ShipOrderAsync([FromBody] ShipOrderCommand command, [FromHeader(Name = "x-requestid")] string requestId)
        {
            bool commandResult = false;

            if (Guid.TryParse(requestId, out Guid guid) && guid != Guid.Empty)
            {
                var requestShipOrder = new IdentifiedCommand <ShipOrderCommand, bool>(command, guid);

                _logger.LogInformation(
                    "----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})",
                    requestShipOrder.GetGenericTypeName(),
                    nameof(requestShipOrder.Command.OrderNumber),
                    requestShipOrder.Command.OrderNumber,
                    requestShipOrder);

                commandResult = await _mediator.Send(requestShipOrder);
            }

            if (!commandResult)
            {
                return(BadRequest());
            }

            return(Ok());
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> AnonymizeGdprData([FromBody] AnonymizeGdprDataCommand message)
        {
            try
            {
                var anonymizeCommand = new IdentifiedCommand <AnonymizeGdprDataCommand, string>(message, new Guid());
                var commandResult    = await _mediator.Send(anonymizeCommand);

                return(Content(commandResult, "application/json"));
            }
            catch (DuplicateObjectException e)
            {
                Console.WriteLine(e);
                return(BadRequest(new { message = e.Message }));
            }
            catch (ArgumentException e)
            {
                Console.WriteLine(e);
                return(BadRequest(new { message = e.Message }));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(BadRequest(new { message = "An unknown error occurred." }));
            }
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> RetrieveCurrentExposure([FromRoute] long applicationNumber)
        {
            Console.WriteLine("Offer - EndPoint POST RetrieveCurrentExposure !!!");
            var dateBeforeCall = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.fff",
                                                          CultureInfo.InvariantCulture);

            Console.WriteLine("Before Call RetrieveCurrentExposure {0}", dateBeforeCall);

            var           RetrieveCurrentExposureCommand = new IdentifiedCommand <RetrieveCurrentExposureCommand, CommandStatus>(new RetrieveCurrentExposureCommand(applicationNumber, GetUsernameFromToken()), new Guid());
            CommandStatus commandResult = await _mediator.Send(RetrieveCurrentExposureCommand);

            if (commandResult.CommandResult.Equals(StandardCommandResult.OK))
            {
                var dateAfterCall = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.fff",
                                                             CultureInfo.InvariantCulture);;
                Console.WriteLine("Offer RetrieveCurrentExposure - After Call: {0} ", dateAfterCall);

                double milDiff = DateTime.Parse(dateAfterCall).Subtract(DateTime.Parse(dateBeforeCall)).TotalMilliseconds;
                Console.WriteLine("Offer RetrieveCurrentExposure - END - COUNT: {0} !!!", milDiff);
                return(Ok());
            }
            else if (commandResult.CommandResult.Equals(StandardCommandResult.NOT_FOUND))
            {
                return(NotFound());
            }
            else
            {
                return(StatusCode(500));
            }
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> PostExtendedData([FromRoute] long applicationNumber,
                                                           [FromBody] API.Application.Commands.Application.PutExtendedPartyCommand command)
        {
            command.ApplicationNumber = applicationNumber;
            var           postExtendedDataCommand = new IdentifiedCommand <API.Application.Commands.Application.PutExtendedPartyCommand, CommandStatus>(command, new Guid());
            CommandStatus commandResult           = await _mediator.Send(postExtendedDataCommand);

            if (commandResult.CommandResult.Equals(StandardCommandResult.OK))
            {
                return(Ok());
            }
            else if (commandResult.CommandResult.Equals(StandardCommandResult.BAD_REQUEST))
            {
                return(BadRequest());
            }
            else if (commandResult.CommandResult.Equals(StandardCommandResult.NOT_FOUND))
            {
                return(NotFound());
            }
            else if (commandResult.Equals(StandardCommandResult.INTERNAL_ERROR))
            {
                _logger.LogError(commandResult.Exception, "An error occurred while putting extended sections to application");
                return(StatusCode(500));
            }
            else
            {
                _logger.LogError("An unknown error occurred while putting extended sections to application");
                return(StatusCode(500));
            }
        }
Ejemplo n.º 9
0
        public async Task Handle_ExceptionIsThrown_ReturnFalse(
            [Frozen] Mock <IRequestManager> requestManagerMock,
            [Frozen] Mock <IMediator> mediatorMock,
            IdentifiedCommandHandler <CreateSalesOrderCommand, bool> sut,
            IdentifiedCommand <CreateSalesOrderCommand, bool> command
            )
        {
            //Arrange
            requestManagerMock.Setup(_ => _.ExistAsync(It.IsAny <Guid>()))
            .ReturnsAsync(false);
            mediatorMock.Setup(_ => _.Send <bool>(
                                   It.IsAny <CreateSalesOrderCommand>(),
                                   It.IsAny <CancellationToken>()
                                   ))
            .Throws <Exception>();

            //Act
            var result = await sut.Handle(command, CancellationToken.None);

            //Assert
            result.Should().Be(false);
            requestManagerMock.Verify(_ => _.CreateRequestForCommandAsync <CreateSalesOrderCommand>(
                                          It.IsAny <Guid>())
                                      );
        }
Ejemplo n.º 10
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="TResult"></typeparam>
 /// <param name="mediator"></param>
 /// <param name="request"></param>
 /// <param name="requestId"></param>
 /// <param name="aggregateId"></param>
 /// <param name="cancellationToken"></param>
 /// <returns></returns>
 public static async Task <TResult> IdempotencySendAsync <TResult>(this IMediator mediator, IRequest <TResult> request, string requestId, Guid aggregateId, CancellationToken cancellationToken = default(CancellationToken))
 {
     if (Guid.TryParse(requestId, out var guid) && guid != Guid.Empty)
     {
         var identified = new IdentifiedCommand <IRequest <TResult>, TResult>(request, guid, aggregateId);
         return(await mediator.Send(identified, cancellationToken));
     }
     return(default);
        public async Task <bool> Handle(IntegrationEventNotification <PriceCalculatedIntegrationEvent> notification, CancellationToken cancellationToken)
        {
            var command = new UpdatePriceCommand(notification.Data.OrderId, notification.Data.Total);

            var identifiedCommand = new IdentifiedCommand <UpdatePriceCommand, bool>(command, notification.Data.Id);

            return(await _mediator.Send(identifiedCommand, cancellationToken));
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> UpsertQuestionnaire([FromRoute] long applicationNumber, [FromRoute] string questionnaireId, [FromBody] UpsertQuestionnaireCommand command)
        {
            command.ApplicationNumber = applicationNumber;
            command.QuestionnaireId   = questionnaireId;
            var upsertQuestionnaire = new IdentifiedCommand <UpsertQuestionnaireCommand, bool?>(command, new Guid());
            var commandResult       = await _mediator.Send(upsertQuestionnaire);

            return(commandResult.HasValue ? commandResult.Value ? (IActionResult)Ok() : (IActionResult)BadRequest() : NotFound());
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> PriceCalculation([FromBody] InitiatePriceCalculationCommand command)
        {
            PriceCalculationResponse commandResult;
            var calculateOfferCommand = new IdentifiedCommand <InitiatePriceCalculationCommand, PriceCalculationResponse>(command, new Guid());

            commandResult = await _mediator.Send(calculateOfferCommand);

            return(commandResult != null ? (IActionResult)Json(commandResult) : (IActionResult)BadRequest());
        }
Ejemplo n.º 14
0
        public async Task <IActionResult> TransferAsync(UserTransferCommand command, [FromHeader(Name = "x-requestid")] string requestId)
        {
            var requestCommand = IdentifiedCommand <UserTransferCommand, bool> .Create(command, requestId);

            command.RequestId = requestCommand.Id;
            var result = await mediator.Send(requestCommand);

            return(Ok(result));
        }
        public async Task <IActionResult> UpsertArrangementRequestsToApplication([FromRoute] long applicationNumber,
                                                                                 [FromBody] ArrangementRequestsAvailabilityCommand command)
        {
            command.ApplicationId = applicationNumber;
            var updatRequestsAvailability = new IdentifiedCommand <ArrangementRequestsAvailabilityCommand, bool?>(command, new Guid());
            var commandResult             = await _mediator.Send(updatRequestsAvailability);

            return(commandResult.HasValue ? commandResult.Value ? (IActionResult)Ok() : (IActionResult)BadRequest() : NotFound());
        }
Ejemplo n.º 16
0
        public async Task <JArray> GetArrangements(string customerNumber, string activeStatuses = null, string activeRoles = null, string arrangementType = null)
        {
            var getArrangements = new IdentifiedCommand <GetArrangementsCommand, JArray>(new GetArrangementsCommand
            {
                CustomerNumber = customerNumber
            }, new Guid());

            return(await _mediator.Send(getArrangements));
        }
Ejemplo n.º 17
0
        public async Task <IActionResult> Recharge(Guid uid, RechargeBalanceCommand command, [FromHeader(Name = "x-requestid")] string requestId)
        {
            command.Uid = uid;
            var requestCommand = IdentifiedCommand <RechargeBalanceCommand, bool> .Create(command, requestId);

            command.RequestId = requestCommand.Id;
            var result = await mediator.Send(requestCommand);

            return(Ok(result));
        }
Ejemplo n.º 18
0
        public async Task <ProjectGetResponseModel> Post([FromBody] CreateProjectCommand command, [FromHeader(Name = "X-Request-Id")] string?requestId)
        {
            requestId ??= Activity.Current?.Id ?? HttpContext.TraceIdentifier;

            var identifiedCommand = new IdentifiedCommand <CreateProjectCommand, ProjectGetResponseModel>(command, requestId);

            ProjectGetResponseModel result = await _mediator.Send(identifiedCommand);

            return(result);
        }
        public async Task <IActionResult> PullPartyDataAsync([FromRoute] long applicationNumber)
        {
            bool            auditLog = AuditLog();
            ApplicationView commandResult;
            var             PullPartyDataCommand = new IdentifiedCommand <PullPartyDataCommand, ApplicationView>(new PullPartyDataCommand(applicationNumber, auditLog), new Guid());

            commandResult = await _mediator.Send(PullPartyDataCommand);

            return(commandResult != null ? (IActionResult)Ok() : NotFound());
        }
        public async Task <IActionResult> SetArrangementRequestAvailability([FromRoute] long applicationNumber,
                                                                            [FromRoute] int arrangementRequestId, [FromBody] SetArrangementRequestAvailabilityCommand command)
        {
            command.ApplicationId        = applicationNumber;
            command.ArrangementRequestId = arrangementRequestId;
            var setArrangementRequestAvailabilityCommand = new IdentifiedCommand <SetArrangementRequestAvailabilityCommand, bool?>
                                                               (command, new Guid());
            var commandResult = await _mediator.Send(setArrangementRequestAvailabilityCommand);

            return(commandResult.HasValue ? commandResult.Value ? (IActionResult)Ok() : (IActionResult)BadRequest() : NotFound());
        }
        public async Task Handle_command_is_null()
        {
            //arrange
            CancellationToken token = default(System.Threading.CancellationToken);
            IdentifiedCommand <CreatePedidoCommand, bool> request = new IdentifiedCommand <CreatePedidoCommand, bool>(null, new Guid());
            var handler = new CreatePedidoCommandHandler(loggerMock.Object, pedidoRepositoryMock.Object, busMock.Object, configurationMock.Object);

            //act
            //assert
            await Assert.ThrowsAsync <ArgumentNullException>(async() => await handler.Handle(request, token));
        }
Ejemplo n.º 22
0
        public async Task <IActionResult> Ship(OrderShipCommand command, [FromHeader(Name = "x-requestid")] string requestId)
        {
            bool commandResult = false;

            if (Guid.TryParse(requestId, out Guid guid) && guid != Guid.Empty)
            {
                var requestCancelOrder = new IdentifiedCommand <OrderShipCommand, bool>(guid, command);
                commandResult = await _mediator.Send(requestCancelOrder);
            }
            return(commandResult ? Ok() : (IActionResult)BadRequest());
        }
Ejemplo n.º 23
0
        public async Task <IActionResult> Put(int id, [FromBody] CreateAppointmentCommand command, [FromHeader(Name = "x-requestid")] string requestId)
        {
            bool commandResult = false;

            if (Guid.TryParse(requestId, out Guid guid) && guid != Guid.Empty)
            {
                var requestCancelOrder = new IdentifiedCommand <CreateAppointmentCommand, bool>(command, guid);
                commandResult = await _mediator.Send(requestCancelOrder);
            }
            return(Ok(commandResult));
        }
Ejemplo n.º 24
0
        public async Task <ActionResult <bool> > CreateOrderFromBasketDataAsync([FromBody] CreateOrderCommand command, [FromHeader(Name = "x-requestid")] string requestId)
        {
            var result = false;

            if (Guid.TryParse(requestId, out Guid guid) && guid != Guid.Empty)
            {
                var identifiedCommand = new IdentifiedCommand <CreateOrderCommand, bool>(command, guid);
                result = await _mediator.Send(identifiedCommand);
            }
            return(Ok(result));
        }
Ejemplo n.º 25
0
        protected override async Task <bool> CreateResultForDuplicateRequestAsync(IdentifiedCommand <UserTransferCommand, bool> request)
        {
            var isDone = await transcationQueryService.IsExistTranscationAsync(request.Id);

            if (isDone)
            {
                return(true);
            }

            return(await base.CreateResultForDuplicateRequestAsync(request));
        }
        public async Task Handle_command_is_null()
        {
            //arrange
            var handler = new RegistrationCommandHandler(mediatorMock.Object, loggerMock.Object, claimsManagerMock.Object);

            IdentifiedCommand <RegistrationCommand, bool> request = new IdentifiedCommand <RegistrationCommand, bool>(null, Guid.NewGuid());
            CancellationToken token = default(System.Threading.CancellationToken);
            //act
            //assert
            await Assert.ThrowsAsync <ArgumentNullException>(() => handler.Handle(request, token));
        }
Ejemplo n.º 27
0
        public async Task <IActionResult> UpdateApplicationStatus([FromRoute] long applicationNumber, [FromBody] UpdateApplicationStatusCommand updateApplicationStatus)
        {
            bool commandResult = false;

            updateApplicationStatus.ApplicationId = applicationNumber;
            var updateApplicationStatusCommand = new IdentifiedCommand <UpdateApplicationStatusCommand, bool>(updateApplicationStatus, new Guid());

            commandResult = await _mediator.Send(updateApplicationStatusCommand);

            return(commandResult ? Ok() : StatusCode(500));
        }
        public async Task <IActionResult> AddCollateralRequirement([FromRoute] long applicationNumber, [FromRoute] int arrangementRequestId, [FromBody] AddCollateralRequirementCommand command)
        {
            command.ApplicationNumber    = applicationNumber;
            command.ArrangementRequestId = arrangementRequestId;
            bool?commandResult;
            var  addCollateralCommand = new IdentifiedCommand <AddCollateralRequirementCommand, bool?>(command, new Guid());

            commandResult = await _mediator.Send(addCollateralCommand);

            return(commandResult.HasValue ? commandResult.Value ? (IActionResult)StatusCode(201) : (IActionResult)BadRequest() : NotFound());
        }
Ejemplo n.º 29
0
        public async Task Handle_guid_is_empty()
        {
            //arrange
            CancellationToken token = default(System.Threading.CancellationToken);
            IdentifiedCommand <CreateOrderCommand, bool> request = new IdentifiedCommand <CreateOrderCommand, bool>(new CreateOrderCommand(), Guid.Empty);
            var handler = new CreateOrderCommandHandler(loggerMock.Object, orderRepositoryMock.Object, busMock.Object, configurationMock.Object);

            //act
            //assert
            await Assert.ThrowsAsync <ArgumentException>(async() => await handler.Handle(request, token));
        }
Ejemplo n.º 30
0
        public async Task Handle_guid_is_empty()
        {
            //arrange
            var handler = new CadastroCommandHandler(mediatorMock.Object, loggerMock.Object, claimsManagerMock.Object);

            IdentifiedCommand <CadastroCommand, bool> request = new IdentifiedCommand <CadastroCommand, bool>(new CadastroCommand(), Guid.Empty);
            CancellationToken token = default(System.Threading.CancellationToken);
            //act
            //assert
            await Assert.ThrowsAsync <ArgumentException>(() => handler.Handle(request, token));
        }