Example #1
0
        public async Task <Result> Handle(CreatePlatoOrderCommand request, CancellationToken cancellationToken)
        {
            Result result;

            try
            {
                var platoOrderId = _identifierProvider.Generate();
                await _platoOrderWriteRepository.CreateAsync(new PlatoOrder(platoOrderId, request.PlatoOrder));


                var platoOrderOverview = _platoOrderProvider.GetPlatoOrderOverview(request.PlatoOrder);

                //_platoOrderChecker.Check(platoOrderOverview);

                var order = _domainConverter.ToOrder(platoOrderOverview);

                Operational operational = new Operational(Status.Open);

                var workOrder = new WorkOrder.Builder()
                                .WithId(Guid.NewGuid())
                                .WithIsEditable(false)
                                .WithCreatedOn(new CreatedOn(DateTime.UtcNow))
                                .WithUserCreated("Plato")
                                .WithOrder(order)
                                .WithOperational(operational)
                                .Build();

                workOrder.Version = _versionProvider.Generate();
                await _workOrderWriteRepository.CreateAsync(workOrder);

                result = Result.Ok(workOrder.Id, workOrder.Version);
            }
            catch (PlatoOrderOverviewCheckException ex)
            {
                _logAs.Error(CustomFailures.CreatePlatoOrderFailure, ex);
                result = Result.Fail(CustomFailures.CreatePlatoOrderFailure);
            }
            catch (Exception ex)
            {
                _logAs.Error(CustomFailures.CreatePlatoOrderFailure, ex);
                result = Result.Fail(CustomFailures.CreatePlatoOrderFailure);
            }
            return(result);
        }
Example #2
0
        public async Task <Result> Handle(GetWorkOrderQuery request, CancellationToken cancellationToken)
        {
            Result result;

            try
            {
                var workorder = await _workOrderReadRepository.GetAsync(request.Id);

                if (!"ecc".Equals(workorder.Order.Origin.Source, StringComparison.InvariantCultureIgnoreCase))
                {
                    var jsonBody = new
                    {
                        source         = workorder.Order.Origin.Source,
                        relationType   = workorder.Order.Operation.Type.Name,
                        transportNo    = workorder.Order.Origin.EntryNumber,
                        operationGroup = workorder.Order.Operation.Group,
                        operation      = workorder.Order.Operation.Name
                    };
                    var jsonBodyAsString   = JsonConvert.SerializeObject(jsonBody);
                    var jsonPlatoOrderFull = await _orchestrator.GetOrder(jsonBodyAsString);

                    var platoOrderFull = _platoOrderProvider.GetPlatoOrderFull(jsonPlatoOrderFull);
                    workorder.Order = _domainConverter.ToOrder(platoOrderFull.Transport);

                    // example
                    //var jsonOrder = JsonConvert.SerializeObject(workorder.Order);

                    await _workOrderWriteRepository.UpdateAsync(workorder);
                }

                var workOrderModel = _mapper.Map <WorkOrderModel>(workorder);
                result = Result.Ok(workOrderModel, workorder.Version);
            }
            catch (EntityNotFoundDbException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.NotFound.Name,
                        Message = string.Format(HandlerFailures.NotFound, "WorkOrder"),
                        Target  = "id"
                    }
                }
                                     );
            }
            catch (Exception ex) when(ex is BiztalkCallException || ex is PlatoCallException)
            {
                _logAs.Error(ex);
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.UpstreamAccessBiztalk.Name,
                        Message = HandlerFailures.UpstreamAccessBiztalk,
                        Target  = "request"
                    }
                }
                                     );
            }
            catch (Exception ex)
            {
                _logAs.Error(CustomFailures.GetWorkOrderFailure, ex);
                result = Result.Fail(CustomFailures.GetWorkOrderFailure);
            }
            return(result);
        }