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); }
public async Task <Result> Handle(DeleteWorkOrderCommand request, CancellationToken cancellationToken) { Result result; try { await _workOrderWriteRepository.DeleteAsync(request.Id, request.Version); result = Result.Ok(); } 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 (EntityVersionDbException) { result = Result.Fail(new System.Collections.Generic.List <Failure>() { new HandlerFault() { Code = HandlerFaultCode.NotMet.Name, Message = HandlerFailures.NotMet, Target = "version" } } ); } catch (Exception ex) { _logAs.Error(CustomFailures.DeleteWorkOrderFailure, ex); result = Result.Fail(CustomFailures.DeleteWorkOrderFailure); } return(result); }
public async Task <Result> Handle(ListWorkOrderQuery request, CancellationToken cancellationToken) { Result result; try { var filter = _filterProvider.Replace(request.Filter, Item.DictionaryOrderItemPath()); int?skip = request.Skip.ToNullableInt(); int?limit = request.Top.ToNullableInt(); var workOrderDomains = await _workOrderReadRepository.ListAsync(filter, skip, limit); var workOrderModels = _mapper.Map <IEnumerable <WorkOrderModel> >(workOrderDomains); var count = workOrderModels.Count(); var workOrdersModels = new WorkOrdersModel { Value = workOrderModels, Count = count, NextLink = null }; result = Result.Ok(workOrdersModels); } catch (FilterODataException) { result = Result.Fail(new System.Collections.Generic.List <Failure>() { new HandlerFault() { Code = HandlerFaultCode.InvalidQueryFilter.Name, Message = HandlerFailures.InvalidQueryFilter, Target = "$filter" } } ); } catch (Exception ex) { _logAs.Error(CustomFailures.ListWorkOrderFailure, ex); result = Result.Fail(CustomFailures.ListWorkOrderFailure); } return(result); }
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); }
public async Task <Result> Handle(CreateWorkOrderCommand request, CancellationToken cancellationToken) { //var order = new Order.Builder() // .WithSite(request.Order.Site) // .WithCustomer(request.Order.Customer) // .WithOperationalDepartment(request.Order.OperationalDepartment) // .WithLicensePlateTrailer(request.Order.LicensePlateTrailer) // .WithLicensePlateTruck(request.Order.LicensePlateTruck) // .WithContainer(request.Order.Container) // .WithContainerLocation(request.Order.ContainerLocation) // .WithDockingZone(request.Order.DockingZone) // .Build(); Result result; try { var order = new Order() { Origin = new Origin() { Source = "ECC" }, Number = null, Customer = new Customer() { Code = null, ProductionSite = null, Reference1 = null, Reference2 = null, Reference3 = null, Reference4 = null, Reference5 = null }, Customs = new Customs() { CertificateOfOrigin = null, Document = new Document() { Name = null, Number = null, Office = null, Date = null } }, Transport = new Transport() { Kind = null, Type = null, Driver = new Driver() { Name = null, Wait = Wait.Undefined }, Delivery = new Delivery() { Place = null }, Loading = new Loading() { Place = null, Reference = null, }, Truck = new Truck() { LicensePlateTruck = null, LicensePlateTrailer = null, }, Container = new Container() { Number = null, Location = null, StackLocation = null }, Railcar = new Railcar() { Number = null }, Ard = new Ard() { Reference1 = null, Reference2 = null, Reference3 = null, Reference4 = null, Reference5 = null, Reference6 = null, Reference7 = null, Reference8 = null, Reference9 = null, Reference10 = null }, Arrival = new Arrival() { Expected = null, Arrived = null, Latest = null }, BillOfLading = new BillOfLading() { Number = null, WeightNet = null, WeightGross = null }, Carrier = new Carrier() { Arrived = null, Booked = null }, Weighbridge = new Weighbridge() { Net = null, Gross = null }, Seal = new Seal() { Seal1 = null, Seal2 = null, Seal3 = null }, Adr = null }, Operation = new Operation() { Dispatch = new Dispatch() { Priority = null, To = null, Comment = null }, Type = OperationType.Inbound, Name = request.Operation, UnitPlanning = null, TypePlanning = null, Site = request.Site, Zone = null, OperationalDepartment = request.Department, DockingZone = null, LoadingDock = null, ProductOverview = null, LotbatchOverview = null } }; var operational = new Operational(Status.Open); var workOrder = new WorkOrder.Builder() .WithId(_identifierProvider.Generate()) .WithIsEditable(true) .WithCreatedOn(new CreatedOn(DateTime.UtcNow)) .WithUserCreated(request.UserCreated) .WithOrder(order) .WithOperational(operational) .Build(); workOrder.Version = _versionProvider.Generate(); await _workOrderWriteRepository.CreateAsync(workOrder); result = Result.Ok(workOrder.Id, workOrder.Version); } catch (UniqueKeyDbException) { result = Result.Fail(new System.Collections.Generic.List <Failure>() { new HandlerFault() { Code = HandlerFaultCode.Conflict.Name, Message = HandlerFailures.Conflict, Target = "workOrder" } }); } catch (Exception ex) { _logAs.Error(CustomFailures.CreateWorkOrderFailure, ex); result = Result.Fail(CustomFailures.CreateWorkOrderFailure); } return(result); }
public async Task <Result> Handle(UpdateWorkOrderCommand request, CancellationToken cancellationToken) { Result result; try { var workOrderToUpdate = await _workOrderReadRepository.GetAsync(request.Id); if (workOrderToUpdate.Version != request.Version) { throw new CommandVersionException(); } if (request.Operant.HasValue) { var operant = request.Operant.Value; workOrderToUpdate.Operational.SetOperant(operant); } if (request.Status.HasValue) { var status = Status.Parse(request.Status.Value); workOrderToUpdate.Operational.ChangeStatus(status); } if (request.StartedOn.HasValue) { var startedOnValue = _dateTimeProvider.Parse(request.StartedOn.Value); if (startedOnValue.HasValue) { var startedOn = new DateOn(startedOnValue.Value); workOrderToUpdate.Operational.SetStartedOn(startedOn); } } if (request.HandledUnits.HasValue) { workOrderToUpdate.Operational.ClearHandledUnits(); foreach (var handledUnitDto in request.HandledUnits.Value) { var id = new Guid(handledUnitDto.Id); var operantId = new Guid(handledUnitDto.OperantId); var operantLogin = new Login(handledUnitDto.OperantLogin); var sourceUnitId = new Guid(handledUnitDto.SourceUnitId); var locationWarehouse = handledUnitDto.Warehouse; var locationGate = handledUnitDto.Gate; var locationRow = handledUnitDto.Row; var locationPosition = handledUnitDto.Position; var units = new Units(int.Parse(handledUnitDto.Units)); var isPartial = bool.Parse(handledUnitDto.IsPartial); var isMixed = bool.Parse(handledUnitDto.IsMixed); var quantity = new Quantity(int.Parse(handledUnitDto.Quantity)); var weightNet = new Weight(float.Parse(handledUnitDto.WeightNet)); var weightGross = new Weight(float.Parse(handledUnitDto.WeightGross)); var palletNumber = handledUnitDto.PalletNumber; var ssccNumber = handledUnitDto.SsccNumber; var operant = new Operant(operantId, operantLogin); var sourceUnit = workOrderToUpdate.Order.Units.First(x => x.Id == sourceUnitId); var handledOn = new HandledOn(_dateTimeProvider.Parse(handledUnitDto.HandledOn).Value); var location = new Location( new Warehouse(new Label(locationWarehouse)), new Gate(new Label(locationGate)), new Row(new Label(locationRow)), new Position(new Label(locationPosition)) ); var type = sourceUnit.Type; var goodDtos = handledUnitDto.Products; var goods = new List <Good>(); foreach (var goodDto in goodDtos) { var goodId = new Guid(goodDto.Id); var good = new Good(goodId); good.SetConfiguration( new Configuration( code: goodDto.CongfigurationCode, description: goodDto.CongfigurationDescription, quantity: goodDto.CongfigurationQuantity, unitType: goodDto.CongfigurationUnitType, netPerUnit: goodDto.CongfigurationNetPerUnit, netPerUnitAlwaysDifferent: goodDto.CongfigurationNetPerUnitAlwaysDifferent, grossPerUnit: goodDto.CongfigurationGrossPerUnit ) ); good.SetCode(goodDto.Code); good.SetCustomer(goodDto.Customer); good.SetArrival(goodDto.Arrival); good.SetArticle(goodDto.Article); good.SetArticlePackagingCode(goodDto.ArticlePackagingCode); good.SetName(goodDto.Code); good.SetGtin(goodDto.Gtin); good.SetProductType(goodDto.ProductType); good.SetMaterialType(goodDto.MaterialType); good.SetColor(goodDto.Color); good.SetShape(goodDto.Shape); good.SetLotbatch(goodDto.Lotbatch); good.SetLotbatch2(goodDto.Lotbatch2); good.SetClientReference(goodDto.ClientReference); good.SetClientReference2(null); good.SetBestBeforeDate(_dateTimeProvider.Parse(goodDto.BestBeforeDate).HasValue ? new DateOn(_dateTimeProvider.Parse(goodDto.BestBeforeDate).Value) : null); good.SetDateFifo(_dateTimeProvider.Parse(goodDto.DateFifo).HasValue ? new DateOn(_dateTimeProvider.Parse(goodDto.DateFifo).Value) : null); good.SetCustomsDocument(goodDto.CustomsDocument); good.SetStorageStatus(goodDto.StorageStatus); good.SetStackheight(goodDto.Stackheight); good.SetLength(goodDto.Length); good.SetWidth(goodDto.Width); good.SetHeight(goodDto.Height); good.SetOriginalContainer(goodDto.OriginalContainer); good.SetQuantity(new Quantity(_typeConverterProvider.ToInt(goodDto.Quantity))); good.SetWeightNet(new Weight(_typeConverterProvider.ToFloat(goodDto.WeightNet))); good.SetWeightGross(new Weight(_typeConverterProvider.ToFloat(goodDto.WeightGross))); goods.Add(good); } var handledUnit = new HandledUnit(id, sourceUnit); handledUnit.SetOperant(operant); handledUnit.SetHandledOn(handledOn); handledUnit.SetLocation(location); handledUnit.SetType(type); handledUnit.SetUnits(units); handledUnit.SetIsPartial(isPartial); handledUnit.SetIsMixed(isMixed); handledUnit.SetQuantity(quantity); handledUnit.SetWeightNet(weightNet); handledUnit.SetWeightGross(weightGross); handledUnit.SetPalletNumber(palletNumber); handledUnit.SetSsccNumber(ssccNumber); foreach (var good in goods) { handledUnit.AddGood(good); } workOrderToUpdate.Operational.AddHandledUnit(handledUnit); } } if (request.Remarks.HasValue) { workOrderToUpdate.Operational.ClearRemarks(); foreach (var remarkDto in request.Remarks.Value) { var operantId = new Guid(remarkDto.OperantId); var operantLogin = remarkDto.Operant; var operant = new Operant(operantId, new Login(operantLogin)); var createdOn = new CreatedOn(_dateTimeProvider.Parse(remarkDto.CreatedOn).Value); var text = remarkDto.Text; var remark = new Remark(operant, createdOn, text); workOrderToUpdate.Operational.AddRemark(remark); } } if (request.Pictures.HasValue) { workOrderToUpdate.Operational.ClearPictures(); foreach (var pictureDto in request.Pictures.Value) { var operantId = new Guid(pictureDto.OperantId); var operantLogin = pictureDto.Operant; var operant = new Operant(operantId, new Login(operantLogin)); var createdOn = new CreatedOn(_dateTimeProvider.Parse(pictureDto.CreatedOn).Value); var name = pictureDto.Name; var picture = new Picture(operant, createdOn, name); workOrderToUpdate.Operational.AddPicture(picture); } } if (request.Inputs.HasValue) { workOrderToUpdate.Operational.ClearInputs(); foreach (var inputDto in request.Inputs.Value) { var operantId = new Guid(inputDto.OperantId); var operantLogin = inputDto.Operant; var operant = new Operant(operantId, new Login(operantLogin)); var createdOn = new CreatedOn(_dateTimeProvider.Parse(inputDto.CreatedOn).Value); var value = inputDto.Value; var property = inputDto.Property; var input = new Input(operant, createdOn, value, property); workOrderToUpdate.Operational.AddInput(input); } } workOrderToUpdate.Version = _versionProvider.Generate(); await _workOrderWriteRepository.UpdateAsync(workOrderToUpdate); result = Result.Ok(workOrderToUpdate.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 (CommandVersionException) { result = Result.Fail(new System.Collections.Generic.List <Failure>() { new HandlerFault() { Code = HandlerFaultCode.NotMet.Name, Message = HandlerFailures.NotMet, Target = "version" } } ); } catch (UniqueKeyDbException) { result = Result.Fail(new System.Collections.Generic.List <Failure>() { new HandlerFault() { Code = HandlerFaultCode.Conflict.Name, Message = HandlerFailures.Conflict, Target = "workOrder" } } ); } catch (Exception ex) { _logAs.Error(CustomFailures.UpdateWorkOrderFailure, ex); result = Result.Fail(CustomFailures.UpdateWorkOrderFailure); } return(result); }