Beispiel #1
0
        public async Task <bool> Handle(ChangeStatusOrderAlterationCommend request, CancellationToken cancellationToken)
        {
            if (request == null)
            {
                throw new NullReferenceException("CangeOrderStatusCommand is null!");
            }

            var orderAlter = await _orderAlterationRepository.SingleOrDefaultAsync(x => x.Id == request.Id);

            if (orderAlter == null)
            {
                return(false);
            }

            orderAlter.SetOrderStatus(request.OrderStatus);

            try
            {
                _orderAlterationRepository.UpdateUoW(orderAlter);


                ////Save Local Integration Event with pending status (InsertOrderPaidEvent Or InsertAlterationFinishedEvent)
                //var orderPaidEvent = await InsertOrderPaidEvent(orderAlter);
                //var alterationFinishedEvent = await InsertAlterationFinishedEvent(orderAlter);

                await _orderAlterationRepository.SaveChangesAsync();


                try
                {
                    // publish Integration event
                    if (orderAlter.OrderStatusId == Status.Paid.Id)
                    {
                        var orderPaidEvent = new OrderPaidEvent(orderAlter.Id);
                        await _endpoint.Publish(orderPaidEvent);
                    }
                    else if (orderAlter.OrderStatusId == Status.Done.Id)
                    {
                        var alterationFinishedEvent = new AlterationFinishedEvent(orderAlter.Id);
                        await _endpoint.Publish(alterationFinishedEvent);
                    }
                }
                catch (Exception ex)
                {
                    //update Local Integration Event to ready status
                    //await _localIntegrationEventRepository.UpdateLocalIntegrationEvent(orderPaidEvent.Id);
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return(true);
        }
        public async Task <bool> Handle(CreateOrderAlterationCommand request, CancellationToken cancellationToken)
        {
            if (request == null)
            {
                throw new NullReferenceException("CreateOrderAlterCommand is null!");
            }

            OrderAlteration orderALteraion = new OrderAlteration(request.LeftSleeve, request.RightSleeve, request.LeftTrouser, request.RightTrouser, Status.Created, request.CustomerName);

            await _orderAlterationRepository.CreateAsyncUoW(orderALteraion);

            await _orderAlterationRepository.SaveChangesAsync();

            return(true);
        }