Ejemplo n.º 1
0
        public Task Handle(ApartmentsReserved message, IMessageHandlerContext context)
        {
            _logger.Info($"ApartmentsReserved message recived, apartments id: {message.ApartmentsId}, reservation id: {message.ReservationId}");
            _hubContext.Clients.All.SendAsync(NotificationTypes.primary.ToString(), $"ApartmentsReserved message recived, apartments id: {message.ApartmentsId}, reservation id: {message.ReservationId}");

            _repository.Find(_ => _.ApartmentsId == message.ApartmentsId).ReservationId = message.ReservationId;
            return(Task.CompletedTask);
        }
Ejemplo n.º 2
0
        public Task Handle(PayCompleted message, IMessageHandlerContext context)
        {
            _logger.Info($"PayCompleted message recived, reservation id: {message.ReservationId}, invoice id: {message.InvoiceId}");
            _hubContext.Clients.All.SendAsync(NotificationTypes.primary.ToString(), $"PayCompleted message recived, reservation id: {message.ReservationId}, invoice id: {message.InvoiceId}");

            _repository.Find(_ => _.ReservationId == message.ReservationId && _.Payment.InvoiceId == message.InvoiceId).Payment.IsPaid = true;
            return(Task.CompletedTask);
        }
        public Task Handle(BookingCompleted message, IMessageHandlerContext context)
        {
            _logger.Info($"BookingCompleted message recived, apartments id: {message.ApartmentsId}");
            _hubContext.Clients.All.SendAsync(NotificationTypes.success.ToString(), $"BookingCompleted message recived, apartments id: {message.ApartmentsId}");

            _repository.Find(_ => _.ApartmentsId == message.ApartmentsId).IsCompleted = true;
            return(Task.CompletedTask);
        }
        public Task Handle(InvoiceCreated message, IMessageHandlerContext context)
        {
            _logger.Info($"InvoiceCreated message recived, invoice id: {message.InvoiceId}");
            _hubContext.Clients.All.SendAsync(NotificationTypes.primary.ToString(), $"InvoiceCreated message recived, invoice id: {message.InvoiceId}");


            var booking = _repository.Find(_ => _.ReservationId == message.ReservationId);

            if (booking == null)
            {
                _logger.Error($"Booking with reservation id '{message.ReservationId}' was not found");
                _hubContext.Clients.All.SendAsync(NotificationTypes.danger.ToString(), $"Booking with reservation id '{message.ReservationId}' was not found");
                return(Task.CompletedTask);
            }

            booking.Payment = new Models.PaymentModel {
                InvoiceId = message.InvoiceId
            };
            return(Task.CompletedTask);
        }
        public async Task PayInvoice()
        {
            var reservation = _repository.Find(_ => !_.IsCompleted && _.Payment != null && !_.Payment.IsPaid);

            if (reservation == null)
            {
                await _hubContext.Clients.All.SendAsync(NotificationTypes.warning.ToString(), "Not found reserved apartments");

                return;
            }

            var command = new PayInvoice();

            command.ReservationId = reservation.ReservationId;
            command.InvoiceId     = reservation.Payment.InvoiceId;
            command.ApartmentsId  = reservation.ApartmentsId;

            await _hubContext.Clients.All.SendAsync(NotificationTypes.primary.ToString(), $"Sending PayInvoice command, invoice id = {command.InvoiceId}, reservation id = { command.ReservationId}");

            await _component.SendCommand(command);
        }