Beispiel #1
0
        public async Task <IActionResult> CreateNew(int courseId, [FromForm] NotificationCreateCommand command)
        {
            if (!_userResolver.HasCoursePrivilege(courseId, new List <PrivilegeEnum>()
            {
                PrivilegeEnum.CanManageCourse, PrivilegeEnum.CanManageNotifications
            }))
            {
                return(Unauthorized());
            }
            await _commandBus.ExecuteAsync(command);

            await _hubContext.Clients.All.SendAsync("newNotification");

            return(Ok());
        }
Beispiel #2
0
        public IActionResult Deposit([FromBody] TransactionRequest request)
        {
            //ESTA COMUNICACION ESPERA RESPUESTA ES MEDIANTE EL PROTOCOLO HTTP
            Model.Transaction transaction = new Model.Transaction()
            {
                AccountId    = request.AccountId,
                Amount       = request.Amount,
                CreationDate = DateTime.Now.ToShortDateString(),
                Type         = "Deposit"
            };

            transaction = _transactionService.Deposit(transaction);

            //ACA ESTAMOS ACTUALIZANDO LA INFORMACION DEL MICROSERVICIO ACCOUNT

            bool isProcess = _accountService.Execute(transaction);

            if (isProcess)
            {
                //ESTE OTRO TIPO DE COMUNICACION NO ESPERA RESPUESTA Y SE ESTA TRABAJANDO CON EL PROTOCOLO AMQP
                //ESTE SOLO LANZA EL COMANDO Y LISTO
                var createCommand = new DepositCreateCommand(
                    idTransaction: transaction.Id,
                    amount: transaction.Amount,
                    creationDate: transaction.CreationDate,
                    type: transaction.Type,
                    accountId: transaction.AccountId
                    );

                _bus.SendCommand(createCommand);

                //ACA ESTAMOS MANDANDO EL MENSAJE A LA COLA DE NOTIFICACIONES
                var createCommandNotification = new NotificationCreateCommand(
                    idTransaction: transaction.Id,
                    amount: transaction.Amount,
                    type: transaction.Type,
                    accountId: transaction.AccountId
                    );

                _bus.SendCommand(createCommandNotification);
            }

            /*END ACTUALIZACION*/

            return(Ok());
        }
Beispiel #3
0
        public IActionResult Pagos([FromBody] InvoiceRequest request)
        {
            _metricsRegistry.IncrementFindQuery();
            _logger.LogInformation("Post Pay(Pagos)");

            Model.Transaction transaction = new Model.Transaction()
            {
                IdInvoice = request.IdInvoice,
                Amount    = request.Amount,
                Date      = DateTime.Now.ToString()
            };
            transaction = _transactionService.Pay(transaction);

            bool isProccess = _invoiceService.Execute(transaction);

            if (isProccess)
            {
                var createCommad = new TransactionPayCreatedCommand(
                    idOperation: transaction.IdOperation,
                    amount: transaction.Amount,
                    date: transaction.Date,
                    idInvoice: transaction.IdInvoice
                    );
                _bus.SendCommand(createCommad);

                var createdInvoice = new InvoiceCreatedCommand(
                    idInvoice: transaction.IdInvoice,
                    amount: transaction.Amount,
                    state: "PAGADO"
                    );

                _bus.SendCommand(createdInvoice);

                var createCommadNotification = new NotificationCreateCommand(
                    idOperation: transaction.IdOperation,
                    idInvoice: transaction.IdInvoice,
                    amount: transaction.Amount);

                _bus.SendCommand(createCommadNotification);
            }

            return(Ok(transaction));
        }
Beispiel #4
0
        public IActionResult Withtdrawal([FromBody] TransactionRequest request)
        {
            Model.Transaction transaction = new Model.Transaction()
            {
                AccountId    = request.AccountId,
                Amount       = request.Amount,
                CreationDate = DateTime.Now.ToString(),
                Type         = "Retiro"
            };
            transaction = _transactionService.Withtdrawal(transaction);

            //Ejecutando el CircuiBraker
            bool isProccess = _accountService.Execute(transaction);

            if (isProccess)
            {
                var createdCommand = new WithtdrawalCreateCommand(

                    idTransaction: transaction.Id,
                    amount: transaction.Amount,
                    type: transaction.Type,
                    creationDate: transaction.CreationDate,
                    accountId: transaction.AccountId
                    );
                _bus.SendCommand(createdCommand);

                var createCommandNotification = new NotificationCreateCommand(
                    idTransaction: transaction.Id,
                    amount: transaction.Amount,
                    type: transaction.Type,
                    accountId: transaction.AccountId
                    );

                _bus.SendCommand(createCommandNotification);
            }



            return(Ok(new { transaction.Id }));
        }