Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        public async Task UpdateOperationalHandledUnitsShouldSucceed()
        {
            // Arrange
            var id     = Guid.NewGuid();
            var order  = new Order();
            var unitId = Guid.NewGuid();

            var unit     = new Unit(unitId, UnitType.Single);
            var location = new Location(
                new Warehouse(new Label("Warehouse")),
                new Gate(new Label("Gate")),
                new Row(new Label("Row")),
                new Position(new Label("Position"))
                );

            unit.SetLocation(location);
            unit.SetGroup(new Group(
                              key: "groupKey",
                              weightNet: new Weight(12),
                              weightGross: new Weight(14)
                              )
                          );
            unit.SetMixed(new Mixed(key: null, palletNumber: null));
            unit.SetUnits(new Units(1));
            unit.SetIsPartial(false);
            unit.SetQuantity(new Quantity(55));
            unit.SetWeightNet(new Weight(12));
            unit.SetWeightGross(new Weight(14));
            unit.SetPalletNumber("PalletNumber");
            unit.SetSsccNumber("SsccNumber");


            order.Units = new List <Unit>()
            {
                unit
            };
            var workOrderToUpdate   = RepositoryHelper.ForWorkOrder.CreateWorkOrder(id, "anyUser", order);
            var operationalToUpdate = workOrderToUpdate.Operational;

            operationalToUpdate.ClearHandledUnits();


            var handledUnitId     = Guid.NewGuid();
            var operantId         = Guid.NewGuid();
            var operantLogin      = new Login("OperantLogin");
            var sourceUnitId      = unit.Id;
            var locationWarehouse = "Warehouse";
            var locationGate      = "Gate";
            var locationRow       = "Row";
            var locationPosition  = "Position";
            var units             = new Units(1);
            var isPartial         = false;
            var isMixed           = false;
            var quantity          = new Quantity(55);
            var weightNet         = new Weight(13);
            var weightGross       = new Weight(15);
            var palletNumber      = "PalletNumber";
            var ssccNumber        = "SsccNumber";

            var operant         = new Operant(operantId, operantLogin);
            var sourceUnit      = workOrderToUpdate.Order.Units.First(x => x.Id == sourceUnitId);
            var handledOn       = new HandledOn(DateTime.UtcNow);
            var handledLocation = 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 handledUnit = new HandledUnit(handledUnitId, sourceUnit);

            handledUnit.SetOperant(operant);
            handledUnit.SetHandledOn(handledOn);
            handledUnit.SetLocation(handledLocation);
            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);

            operationalToUpdate.AddHandledUnit(handledUnit);

            operationalToUpdate.SetOperant("Operant");
            operationalToUpdate.SetStartedOn(new DateOn(_dateTimeProvider.Parse("2019-04-19T12:15:57Z").Value));

            // Act
            await _repository.UpdateAsync(workOrderToUpdate);

            // Assert
            var data = RepositoryHelper.ForWorkOrder.GetWorkOrders();

            data.Should().HaveCount(1);
            var result = data.First();

            result.Should().NotBeNull();
            result.Operational.HandledUnits.Count.Should().Be(1);
        }
        public WorkOrder ToDomain(WorkOrderClass workOrderClass)
        {
            var workOrder = new WorkOrder(workOrderClass.Id)
            {
                UserCreated = workOrderClass.UserCreated,
                CreatedOn   = new CreatedOn(workOrderClass.CreatedOn),
                Version     = workOrderClass.Version,

                Order = new Order()
                {
                    Number = workOrderClass.OrderNumber,

                    Origin = new Origin()
                    {
                        Source      = workOrderClass.OrderOriginSource,
                        EntryNumber = workOrderClass.OrderOriginEntryNumber
                    },

                    Customer = new Customer()
                    {
                        Code           = workOrderClass.OrderCustomerCode,
                        ProductionSite = workOrderClass.OrderCustomerProductionSite,
                        Reference1     = workOrderClass.OrderCustomerReference1,
                        Reference2     = workOrderClass.OrderCustomerReference2,
                        Reference3     = workOrderClass.OrderCustomerReference3,
                        Reference4     = workOrderClass.OrderCustomerReference4,
                        Reference5     = workOrderClass.OrderCustomerReference5
                    },

                    Customs = new Customs()
                    {
                        CertificateOfOrigin = workOrderClass.OrderCustomsCertificateOfOrigin,
                        Document            = new Document()
                        {
                            Name   = workOrderClass.OrderCustomsDocumentName,
                            Number = workOrderClass.OrderCustomsDocumentNumber,
                            Office = workOrderClass.OrderCustomsDocumentOffice,
                            Date   = workOrderClass.OrderCustomsDocumentDate.HasValue ? new DateOn(workOrderClass.OrderCustomsDocumentDate.Value) : null,
                        }
                    },

                    Transport = new Transport()
                    {
                        Kind   = workOrderClass.OrderTransportKind,
                        Type   = workOrderClass.OrderTransportType,
                        Driver = new Driver()
                        {
                            Name = workOrderClass.OrderTransportDriverName,
                            Wait = (Wait)Enum.Parse(typeof(Wait), workOrderClass.OrderTransportDriverWait),
                        },
                        Delivery = new Delivery()
                        {
                            Eta       = workOrderClass.OrderTransportDeliveryEta.HasValue ? new DateOn(workOrderClass.OrderTransportDeliveryEta.Value) : null,
                            Lta       = workOrderClass.OrderTransportDeliveryLta.HasValue ? new DateOn(workOrderClass.OrderTransportDeliveryLta.Value) : null,
                            Place     = workOrderClass.OrderTransportDeliveryPlace,
                            Reference = workOrderClass.OrderTransportDeliveryReference
                        },
                        Loading = new Loading()
                        {
                            Eta       = workOrderClass.OrderTransportLoadingEta.HasValue ? new DateOn(workOrderClass.OrderTransportLoadingEta.Value) : null,
                            Lta       = workOrderClass.OrderTransportLoadingLta.HasValue ? new DateOn(workOrderClass.OrderTransportLoadingLta.Value) : null,
                            Place     = workOrderClass.OrderTransportLoadingPlace,
                            Reference = workOrderClass.OrderTransportLoadingReference
                        },
                        Truck = new Truck()
                        {
                            LicensePlateTruck   = workOrderClass.OrderTransportTruckLicensePlateTruck,
                            LicensePlateTrailer = workOrderClass.OrderTransportTruckLicensePlateTrailer
                        },
                        Container = new Container()
                        {
                            FreeUntilOnTerminal = new FreeUntilOnTerminal()
                            {
                                ShippingLine = workOrderClass.OrderTransportContainerFreeUntilOnTerminalShippingLine,
                                Customer     = workOrderClass.OrderTransportContainerFreeUntilOnTerminalCustomer
                            },
                            Number        = workOrderClass.OrderTransportContainerNumber,
                            Location      = workOrderClass.OrderTransportContainerLocation,
                            StackLocation = workOrderClass.OrderTransportContainerStackLocation
                        },
                        Railcar = new Railcar()
                        {
                            Number = workOrderClass.OrderTransportRailcarNumber
                        },
                        Ard = new Ard()
                        {
                            Reference1  = workOrderClass.OrderTransportArdReference1,
                            Reference2  = workOrderClass.OrderTransportArdReference2,
                            Reference3  = workOrderClass.OrderTransportArdReference3,
                            Reference4  = workOrderClass.OrderTransportArdReference4,
                            Reference5  = workOrderClass.OrderTransportArdReference5,
                            Reference6  = workOrderClass.OrderTransportArdReference6,
                            Reference7  = workOrderClass.OrderTransportArdReference7,
                            Reference8  = workOrderClass.OrderTransportArdReference8,
                            Reference9  = workOrderClass.OrderTransportArdReference9,
                            Reference10 = workOrderClass.OrderTransportArdReference10
                        },
                        Arrival = new Arrival()
                        {
                            Expected = workOrderClass.OrderTransportArrivalExpected.HasValue ? new DateOn(workOrderClass.OrderTransportArrivalExpected.Value) : null,
                            Latest   = workOrderClass.OrderTransportArrivalLatest.HasValue ? new DateOn(workOrderClass.OrderTransportArrivalLatest.Value) : null,
                            Arrived  = workOrderClass.OrderTransportArrivalArrived.HasValue ? new DateOn(workOrderClass.OrderTransportArrivalArrived.Value) : null,
                        },
                        BillOfLading = new BillOfLading()
                        {
                            Number      = workOrderClass.OrderTransportBillOfLadingNumber,
                            WeightNet   = workOrderClass.OrderTransportBillOfLadingWeightNet,
                            WeightGross = workOrderClass.OrderTransportBillOfLadingWeightGross
                        },
                        Carrier = new Carrier()
                        {
                            Booked  = workOrderClass.OrderTransportCarrierBooked,
                            Arrived = workOrderClass.OrderTransportCarrierArrived
                        },
                        Weighbridge = new Weighbridge()
                        {
                            Net   = workOrderClass.OrderTransportWeighbridgeNet,
                            Gross = workOrderClass.OrderTransportWeighbridgeGross
                        },
                        Seal = new Seal()
                        {
                            Seal1 = workOrderClass.OrderTransportSealSeal1,
                            Seal2 = workOrderClass.OrderTransportSealSeal2,
                            Seal3 = workOrderClass.OrderTransportSealSeal3
                        },
                        Adr = workOrderClass.OrderTransportAdr
                    },

                    Operation = new Operation()
                    {
                        Priority = new Priority()
                        {
                            Code  = workOrderClass.OrderOperationPriorityCode,
                            Value = workOrderClass.OrderOperationPriorityValue
                        },
                        Dispatch = new Dispatch()
                        {
                            Priority = workOrderClass.OrderOperationDispatchPriority,
                            To       = workOrderClass.OrderOperationDispatchTo,
                            Comment  = workOrderClass.OrderOperationDispatchComment
                        },

                        Type                  = OperationType.Parse(workOrderClass.OrderOperationType),
                        Name                  = workOrderClass.OrderOperationName,
                        Group                 = workOrderClass.OrderOperationGroup,
                        UnitPlanning          = workOrderClass.OrderOperationUnitPlanning,
                        TypePlanning          = workOrderClass.OrderOperationTypePlanning,
                        Site                  = workOrderClass.OrderOperationSite,
                        Zone                  = workOrderClass.OrderOperationZone,
                        OperationalDepartment = workOrderClass.OrderOperationOperationalDepartment,
                        DockingZone           = workOrderClass.OrderOperationDockingZone,
                        LoadingDock           = workOrderClass.OrderOperationLoadingDock,
                        ProductOverview       = workOrderClass.OrderOperationProductOverview,
                        LotbatchOverview      = workOrderClass.OrderOperationLotbatchOverview
                    },
                }
            };

            #region Units

            var units = new List <Unit>();

            foreach (var unitClass in workOrderClass.OrderUnits)
            {
                var products = new List <Product>();

                foreach (var productClass in unitClass.Products)
                {
                    var productRemarks = new List <string>();
                    foreach (var remarkComment in productClass.Remarks)
                    {
                        productRemarks.Add(remarkComment);
                    }

                    var safetyRemarks = new List <string>();
                    foreach (var safetyRemarkComment in productClass.SafetyRemarks)
                    {
                        safetyRemarks.Add(safetyRemarkComment);
                    }

                    var notes = new List <string>();
                    foreach (var noteComment in productClass.Notes)
                    {
                        notes.Add(noteComment);
                    }

                    var product = new Product(productClass.Id)
                    {
                        Remarks       = productRemarks,
                        SafetyRemarks = safetyRemarks,
                        Notes         = notes
                    };
                    product.SetConfiguration(
                        new Configuration(
                            code: productClass.ConfigurationCode,
                            description: productClass.ConfigurationDescription,
                            quantity: productClass.ConfigurationQuantity,
                            unitType: productClass.ConfigurationUnitType,
                            netPerUnit: productClass.ConfigurationNetPerUnit,
                            netPerUnitAlwaysDifferent: productClass.ConfigurationNetPerUnitAlwaysDifferent,
                            grossPerUnit: productClass.ConfigurationGrossPerUnit
                            )
                        );
                    product.SetCode(productClass.Code);
                    product.SetCustomer(productClass.Customer);
                    product.SetArrival(productClass.Arrival);
                    product.SetArticle(productClass.Article);
                    product.SetArticlePackagingCode(productClass.ArticlePackagingCode);
                    product.SetName(productClass.Name);
                    product.SetGtin(productClass.Gtin);
                    product.SetProductType(productClass.ProductType);
                    product.SetMaterialType(productClass.MaterialType);
                    product.SetColor(productClass.Color);
                    product.SetShape(productClass.Shape);
                    product.SetLotbatch(productClass.Lotbatch);
                    product.SetLotbatch2(productClass.Lotbatch2);
                    product.SetClientReference(productClass.ClientReference);
                    product.SetClientReference2(productClass.ClientReference2);
                    product.SetBestBeforeDate(productClass.BestBeforeDate.HasValue ? new DateOn(productClass.BestBeforeDate.Value) : null);
                    product.SetDateFifo(productClass.DateFifo.HasValue ? new DateOn(productClass.DateFifo.Value) : null);
                    product.SetCustomsDocument(productClass.CustomsDocument);
                    product.SetStorageStatus(productClass.StorageStatus);
                    product.SetStackheight(productClass.Stackheight);
                    product.SetLength(productClass.Length);
                    product.SetWidth(productClass.Width);
                    product.SetHeight(productClass.Height);
                    product.SetOriginalContainer(productClass.OriginalContainer);
                    product.SetQuantity(new Quantity(productClass.Quantity));
                    product.SetWeightNet(new Weight(_typeConverterProvider.ToFloat(productClass.WeightNet)));
                    product.SetWeightGross(new Weight(_typeConverterProvider.ToFloat(productClass.WeightGross)));
                    products.Add(product);
                }


                var unit     = new Unit(unitClass.Id, UnitType.Parse(unitClass.UnitType));
                var location = new Location(
                    new Warehouse(new Label(unitClass.LocationWarehouse)),
                    new Gate(new Label(unitClass.LocationGate)),
                    new Row(new Label(unitClass.LocationRow)),
                    new Position(new Label(unitClass.LocationPosition))
                    );
                unit.SetLocation(location);
                unit.SetGroup(new Group(
                                  key: unitClass.GroupKey,
                                  weightNet: unitClass.GroupWeightNet != null ? new Weight(_typeConverterProvider.ToFloat(unitClass.GroupWeightNet)) : null,
                                  weightGross: unitClass.GroupWeightGross != null ? new Weight(_typeConverterProvider.ToFloat(unitClass.GroupWeightGross)) : null
                                  )
                              );
                unit.SetMixed(new Mixed(key: unitClass.MixedKey, palletNumber: unitClass.MixedPalletNumber));
                unit.SetUnits(new Units(unitClass.Units));
                unit.SetIsPartial(unitClass.IsPartial);
                unit.SetQuantity(new Quantity(unitClass.Quantity));
                unit.SetWeightNet(new Weight(_typeConverterProvider.ToFloat(unitClass.WeightNet)));
                unit.SetWeightGross(new Weight(_typeConverterProvider.ToFloat(unitClass.WeightGross)));
                unit.SetPalletNumber(unitClass.PalletNumber);
                unit.SetSsccNumber(unitClass.SsccNumber);
                unit.SetProducts(products);
                units.Add(unit);
            }
            workOrder.Order.Units = new List <Unit>(units);

            #endregion

            var extraActivities = new List <ExtraActivity>();
            foreach (var extraActivityClass in workOrderClass.OrderOperationExtraActivities)
            {
                var extraActivity = new ExtraActivity()
                {
                    Code        = extraActivityClass.Code,
                    Activity    = extraActivityClass.Activity,
                    Description = extraActivityClass.Description,
                    IsExecuted  = extraActivityClass.IsExecuted,
                    Quantity    = extraActivityClass.Quantity,
                    Remark      = extraActivityClass.Remark
                };
                extraActivities.Add(extraActivity);
            }
            workOrder.Order.Operation.ExtraActivities = new List <ExtraActivity>(extraActivities);

            var operationalRemarks = new List <string>();
            foreach (var operationalRemark in workOrderClass.OrderOperationOperationalRemarks)
            {
                operationalRemarks.Add(operationalRemark);
            }
            workOrder.Order.Operation.OperationalRemarks = operationalRemarks;

            #region Operational

            var handledUnits = new List <HandledUnit>();
            foreach (var handledUnitClass in workOrderClass.OperationalUnits)
            {
                var sourceUnit  = workOrder.Order.Units.First(x => x.Id == handledUnitClass.SourceUnitId);
                var handledUnit = new HandledUnit(handledUnitClass.Id, sourceUnit);
                var operant     = new Operant(handledUnitClass.OperantId, new Login(handledUnitClass.OperantLogin));
                var location    = new Location(
                    new Warehouse(new Label(handledUnitClass.LocationWarehouse)),
                    new Gate(new Label(handledUnitClass.LocationGate)),
                    new Row(new Label(handledUnitClass.LocationRow)),
                    new Position(new Label(handledUnitClass.LocationPosition))
                    );
                handledUnit.SetOperant(operant);
                handledUnit.SetHandledOn(new HandledOn(handledUnitClass.HandledOn));
                handledUnit.SetLocation(location);
                handledUnit.SetUnits(new Units(handledUnitClass.Units));
                handledUnit.SetIsPartial(handledUnitClass.IsPartial);
                handledUnit.SetQuantity(new Quantity(handledUnitClass.Quantity));
                handledUnit.SetWeightNet(new Weight(_typeConverterProvider.ToFloat(handledUnitClass.WeightNet)));
                handledUnit.SetWeightGross(new Weight(_typeConverterProvider.ToFloat(handledUnitClass.WeightGross)));
                handledUnit.SetPalletNumber(handledUnitClass.PalletNumber);
                handledUnit.SetSsccNumber(handledUnitClass.SsccNumber);

                foreach (var goodClass in handledUnitClass.Products)
                {
                    var good = new Good(goodClass.Id);
                    good.SetConfiguration(
                        new Configuration(
                            code: goodClass.ConfigurationCode,
                            description: goodClass.ConfigurationDescription,
                            quantity: goodClass.ConfigurationQuantity,
                            unitType: goodClass.ConfigurationUnitType,
                            netPerUnit: goodClass.ConfigurationNetPerUnit,
                            netPerUnitAlwaysDifferent: goodClass.ConfigurationNetPerUnitAlwaysDifferent,
                            grossPerUnit: goodClass.ConfigurationGrossPerUnit
                            )
                        );
                    good.SetCode(goodClass.Code);
                    good.SetCustomer(goodClass.Customer);
                    good.SetArrival(goodClass.Arrival);
                    good.SetArticle(goodClass.Article);
                    good.SetArticlePackagingCode(goodClass.ArticlePackagingCode);
                    good.SetName(goodClass.Name);
                    good.SetGtin(goodClass.Gtin);
                    good.SetProductType(goodClass.ProductType);
                    good.SetMaterialType(goodClass.MaterialType);
                    good.SetColor(goodClass.Color);
                    good.SetShape(goodClass.Shape);
                    good.SetLotbatch(goodClass.Lotbatch);
                    good.SetLotbatch2(goodClass.Lotbatch2);
                    good.SetClientReference(goodClass.ClientReference);
                    good.SetClientReference2(goodClass.ClientReference2);
                    good.SetBestBeforeDate(goodClass.BestBeforeDate.HasValue ? new DateOn(goodClass.BestBeforeDate.Value) : null);
                    good.SetDateFifo(goodClass.DateFifo.HasValue ? new DateOn(goodClass.DateFifo.Value) : null);
                    good.SetCustomsDocument(goodClass.CustomsDocument);
                    good.SetStorageStatus(goodClass.StorageStatus);
                    good.SetStackheight(goodClass.Stackheight);
                    good.SetLength(goodClass.Length);
                    good.SetWidth(goodClass.Width);
                    good.SetHeight(goodClass.Height);
                    good.SetOriginalContainer(goodClass.OriginalContainer);
                    good.SetQuantity(new Quantity(goodClass.Quantity));
                    good.SetWeightNet(new Weight(_typeConverterProvider.ToFloat(goodClass.WeightNet)));
                    good.SetWeightGross(new Weight(_typeConverterProvider.ToFloat(goodClass.WeightGross)));

                    handledUnit.AddGood(good);
                }

                handledUnits.Add(handledUnit);
            }

            var remarks = new List <Remark>();
            foreach (var remarkClass in workOrderClass.OperationalRemarks)
            {
                var operantId    = remarkClass.OperantId;
                var operantLogin = remarkClass.OperantLogin;
                var operant      = new Operant(operantId, new Login(operantLogin));
                var createdOn    = new CreatedOn(remarkClass.CreatedOn);
                var text         = remarkClass.Text;
                var remark       = new Remark(operant, createdOn, text);

                remarks.Add(remark);
            }

            var pictures = new List <Picture>();
            foreach (var pictureClass in workOrderClass.OperationalPictures)
            {
                var operantId    = pictureClass.OperantId;
                var operantLogin = pictureClass.OperantLogin;
                var operant      = new Operant(operantId, new Login(operantLogin));
                var createdOn    = new CreatedOn(pictureClass.CreatedOn);
                var name         = pictureClass.Name;
                var picture      = new Picture(operant, createdOn, name);

                pictures.Add(picture);
            }

            var inputs = new List <Input>();
            foreach (var inputClass in workOrderClass.OperationalInputs)
            {
                var operantId    = inputClass.OperantId;
                var operantLogin = inputClass.OperantLogin;
                var operant      = new Operant(operantId, new Login(operantLogin));
                var createdOn    = new CreatedOn(inputClass.CreatedOn);
                var value        = inputClass.Value;
                var property     = inputClass.Property;
                var input        = new Input(operant, createdOn, value, property);

                inputs.Add(input);
            }

            var operational = new Operational(Status.Parse(workOrderClass.OperationalStatus));
            operational.SetOperant(workOrderClass.OperationalOperant);

            foreach (var handledUnit in handledUnits)
            {
                operational.AddHandledUnit(handledUnit);
            }

            foreach (var remark in remarks)
            {
                operational.AddRemark(remark);
            }

            foreach (var picture in pictures)
            {
                operational.AddPicture(picture);
            }

            foreach (var input in inputs)
            {
                operational.AddInput(input);
            }

            if (workOrderClass.OperationalStartedOn.HasValue)
            {
                operational.SetStartedOn(new DateOn(workOrderClass.OperationalStartedOn.Value));
            }

            workOrder.Operational = operational;

            #endregion

            return(workOrder);
        }