private OffhireManagementSystemEntityDetail mapOffhireDataDetailToOffhireManagementSystemEntityDetail(OffhireService.OffhireDataItem dataItem, long companyId, VesselInCompany vesselInCompany)
        {
            Good good = mapOffhireDataGoodToOffhireSystemEntity(dataItem.FuelType, companyId);

            if (good == null)
            {
                //It must be logged that the specified good was not found.
                return null;
            }

            GoodUnit goodUnit = mapOffhireDataMeasureUnitToOffhireSystemEntityMeasureUnit(good, dataItem.UnitTypeCode);

            if (goodUnit == null)
            {
                //It must be logged that the specified good unit was not found.

                return null;
            }

            var detail = new OffhireManagementSystemEntityDetail
                  {
                      Good = good,
                      Unit = goodUnit,
                      Tank = vesselInCompany.Tanks[0],
                      QuantityAmount = dataItem.Quantity
                  };

            return detail;
        }
        private OffhireManagementSystemEntity mapOffhireDataToOffhireSystemEntity(OffhireService.OffhireData offhireData, long companyId)
        {
            var location = activityLocationRepository.First(l => l.Code == offhireData.Location);
            if (location == null)
            {
                //It must be logged that the specified location was not found.
                return null;
            }

            var vessleInCompany = vesselDomainService.GetVesselInCompany(companyId, offhireData.VesselCode);

            if (vessleInCompany == null)
            {
                //It must be logged that the specified VesselCode In Company was not found.
                return null;
            }

            var entity = new OffhireManagementSystemEntity()
                        {
                            VesselInCompany = vessleInCompany,
                            Location = location,
                            StartDateTime = offhireData.StartDateTime,
                            EndDateTime = offhireData.EndDateTime,
                            HasVoucher = offhireData.HasVoucher,
                            ReferenceNumber = offhireData.ReferenceNumber
                        };

            entity.OffhireDetails = new List<OffhireManagementSystemEntityDetail>();

            foreach (var offhireDataItem in offhireData.OffhireDetails)
            {
                var entityDetail = mapOffhireDataDetailToOffhireManagementSystemEntityDetail(offhireDataItem, companyId, vessleInCompany);

                if (entityDetail == null)
                {
                    //It must be logged that the offhireDataItem could not be mapped.

                    return null;
                }

                entity.OffhireDetails.Add(entityDetail);
            }

            return entity;
        }