示例#1
0
 public IHttpActionResult DeleteOrganizationAddress(int id)
 {
     try
     {
         UnitOfWork          unitOfWork = new UnitOfWork(factory);
         OrganizationAddress address    = unitOfWork.OrganizationAddressesRepository
                                          .Get(d => d.Id == id, includeProperties: "Address,Address.Country,OrganizationAddressType,Address.AddressLocality,Address.AddressPlace,Address.AddressRegion,Address.AddressVillage")
                                          .FirstOrDefault();
         address.Deleted = true;
         unitOfWork.OrganizationAddressesRepository.Update(address);
         unitOfWork.Save();
         OrganizationAddressDTO dto = address.ToDTO();
         return(Ok(dto));
     }
     catch (NotFoundException nfe)
     {
         return(NotFound());
     }
     catch (ConflictException ce)
     {
         return(Conflict());
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
示例#2
0
 public IHttpActionResult PutOrganizationAddress(int id, OrganizationAddress organizationAddress)
 {
     if (organizationAddress == null || !ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     if (id != organizationAddress.Id)
     {
         return(BadRequest());
     }
     try
     {
         UnitOfWork unitOfWork = new UnitOfWork(factory);
         unitOfWork.OrganizationAddressesRepository.Update(organizationAddress);
         unitOfWork.Save();
         OrganizationAddressDTO dto = unitOfWork.OrganizationAddressesRepository
                                      .Get(d => d.Id == id, includeProperties: "Address,Address.Country,OrganizationAddressType,Address.AddressLocality,Address.AddressPlace,Address.AddressRegion,Address.AddressVillage")
                                      .FirstOrDefault().ToDTO();
         return(Ok(dto));
     }
     catch (NotFoundException nfe)
     {
         return(NotFound());
     }
     catch (ConflictException ce)
     {
         return(Conflict());
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
示例#3
0
 public IHttpActionResult PostOrganizationAddress(OrganizationAddressDTO organizationAddress)
 {
     if (organizationAddress == null)
     {
         return(BadRequest(ModelState));
     }
     try
     {
         OrganizationAddress address    = organizationAddress.FromDTO();
         UnitOfWork          unitOfWork = new UnitOfWork(factory);
         address.Id         = address.NewId(unitOfWork);
         address.Address.Id = address.Address.NewId(unitOfWork);
         address.AddressId  = address.Address.Id;
         unitOfWork.OrganizationAddressesRepository.Insert(address);
         unitOfWork.Save();
         OrganizationAddressDTO dto = unitOfWork.OrganizationAddressesRepository
                                      .Get(d => d.Id == address.Id, includeProperties: "Address,Address.Country,OrganizationAddressType,Address.AddressLocality,Address.AddressPlace,Address.AddressRegion,Address.AddressVillage")
                                      .FirstOrDefault().ToDTO();
         return(CreatedAtRoute("GetOrganizationAddress", new { id = dto.Id }, dto));
     }
     catch (NotFoundException nfe)
     {
         return(NotFound());
     }
     catch (ConflictException ce)
     {
         return(Conflict());
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
        protected override void Handle(AddDtoRequest <OrganizationAddressDto> request, AddDtoResponse <OrganizationAddressDto> response)
        {
            var organization = _organizationRepository.GetByKey(request.AggregateKey);
            var addressDto   = request.DataTransferObject.Address;
            var address      = new Address(addressDto.FirstStreetAddress,
                                           addressDto.SecondStreetAddress,
                                           addressDto.CityName,
                                           _lookupProvider.Find <StateProvince>(addressDto.StateProvince.Code),
                                           new PostalCode(addressDto.PostalCode));

            var organizationAddressType = _lookupProvider.Find <OrganizationAddressType>(request.DataTransferObject.OrganizationAddressType.Code);
            var organizationAddress     = new OrganizationAddress(organizationAddressType, address, request.DataTransferObject.IsPrimary);
            var originalAddress         = organization.OrganizationAddresses.FirstOrDefault(a => a.GetHashCode() == request.DataTransferObject.OriginalHash);

            if (originalAddress != organizationAddress)
            {
                if (originalAddress != null)
                {
                    organization.RemoveAddress(originalAddress);
                }
                organization.AddAddress(organizationAddress);
            }
            else if (organizationAddress.IsPrimary)
            {
                organization.MakePrimary(organizationAddress);
            }
            response.AggregateKey           = organization.Key;
            response.DataTransferObject     = Mapper.Map <OrganizationAddress, OrganizationAddressDto>(organizationAddress);
            response.DataTransferObject.Key = organization.Key;
        }
示例#5
0
 private void CheckTranslation(VmAddressSimple source, OrganizationAddress target)
 {
     target.Should().NotBe(Guid.Empty);
     target.Address.Should().NotBeNull();
     target.Character.Should().NotBeNull();
     target.Character.Code.Should().Be(source.AddressCharacter.ToString());
 }
示例#6
0
        public void PostPassport_ShoulAddPassport()
        {
            var passportsTestData = new List <OrganizationAddress>()
            {
                new OrganizationAddress {
                    Id = 1, OrganizationId = 2
                },
                new OrganizationAddress {
                    Id = 2, Deleted = true, OrganizationId = 2
                },
                new OrganizationAddress {
                    Id = 3, OrganizationId = 3
                }
            };
            var passports = MockHelper.MockDbSet(passportsTestData);

            passports.Setup(d => d.Find(It.IsAny <object>())).Returns <object[]>((keyValues) => { return(passports.Object.SingleOrDefault(product => product.Id == (int)keyValues.Single())); });
            passports.Setup(d => d.Add(It.IsAny <OrganizationAddress>())).Returns <OrganizationAddress>((contact) =>
            {
                passportsTestData.Add(contact);
                passports = MockHelper.MockDbSet(passportsTestData);
                return(contact);
            });

            var dbContext = new Mock <IAppDbContext>();

            dbContext.Setup(m => m.OrganizationAddresses).Returns(passports.Object);
            dbContext.Setup(d => d.Set <OrganizationAddress>()).Returns(passports.Object);

            dbContext.Setup(d => d.ExecuteStoredProcedure <int>(It.IsAny <string>(), It.IsAny <object[]>()))
            .Returns <string, object[]>((query, parameters) =>
            {
                List <int> list = new List <int>();
                if (query.Contains("NewTableId"))
                {
                    int i = passports.Object.Max(d => d.Id) + 1;
                    list.Add(i);
                }
                else
                {
                    list.Add(0);
                }
                return(list);
            });

            var factory = new Mock <IDbContextFactory>();

            factory.Setup(m => m.CreateDbContext()).Returns(dbContext.Object);
            OrganizationAddress passport = new OrganizationAddress {
                Id = 0, OrganizationId = 3, Address = new Address {
                    Apartment = "3", BuildingNumber = 45
                }
            };
            var controller = new OrganizationAddressesController(factory.Object);
            var result     = controller.PostOrganizationAddress(passport.ToDTO()) as CreatedAtRouteNegotiatedContentResult <OrganizationAddressDTO>;

            Assert.IsNotNull(result);
            Assert.AreEqual(4, result.Content.Id);
            Assert.AreEqual(3, result.Content.OrganizationId);
        }
示例#7
0
        public void AddOrganizationAddressTest()
        {
            var newItem = new OrganizationAddress
            {
                OrganizationId = 1,
                AddressId      = 2,
                CreatedBy      = "test",
                CreatedDate    = DateTime.Now
            };

            this.repository.Add(newItem);
            var rows = this.repository.GetByOrganization(1);

            Assert.AreNotEqual(0, rows.Count);

            var find = rows.SingleOrDefault(x => x.AddressId == 2);

            Assert.IsNotNull(find);
            Assert.AreEqual("test", find.CreatedBy);
        }
示例#8
0
        public void DeletePassport_ShouldDeleteAndReturnOk()
        {
            var passportsTestData = new List <OrganizationAddress>()
            {
                new OrganizationAddress {
                    Id = 1, OrganizationId = 2
                },
                new OrganizationAddress {
                    Id = 2, Deleted = true, OrganizationId = 2
                },
                new OrganizationAddress {
                    Id = 3, OrganizationId = 3
                }
            };
            var passports = MockHelper.MockDbSet(passportsTestData);

            passports.Setup(d => d.Find(It.IsAny <object>())).Returns <object[]>((keyValues) => { return(passports.Object.SingleOrDefault(product => product.Id == (int)keyValues.Single())); });

            var dbContext = new Mock <IAppDbContext>();

            dbContext.Setup(m => m.OrganizationAddresses).Returns(passports.Object);
            dbContext.Setup(d => d.Set <OrganizationAddress>()).Returns(passports.Object);


            var factory = new Mock <IDbContextFactory>();

            factory.Setup(m => m.CreateDbContext()).Returns(dbContext.Object);

            OrganizationAddress passport = new OrganizationAddress {
                Id = 3, OrganizationId = 3
            };
            var controller = new OrganizationAddressesController(factory.Object);
            var result     = controller.DeleteOrganizationAddress(3) as OkNegotiatedContentResult <OrganizationAddressDTO>;

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.Content.Id);
            Assert.AreEqual(3, result.Content.OrganizationId);
        }
 /// <summary>
 ///     Initializes a new instance of the <see cref="OrganizationAddressAddedEvent" /> class.
 /// </summary>
 /// <param name="key">The key.</param>
 /// <param name="version">The version.</param>
 /// <param name="organizationAddress">The organization address.</param>
 public OrganizationAddressAddedEvent(Guid key, int version, OrganizationAddress organizationAddress)
     : base(key, version)
 {
     OrganizationAddress = organizationAddress;
 }
示例#10
0
        public static XDocument CargowiseToOCEBOS(string fPath)
        {
            XDocument cargowiseDoc = XDocument.Load(fPath);
            var       docStr       = cargowiseDoc.ToString();
            var       shipmentStr  = Regex.Match(docStr, @"<Shipment[\S\s]*?</Shipment>").Value;
            var       shipment     = XElement.Parse(shipmentStr);
            var       OCEBOSDoc    = new XDocument(
                new XComment("Sample XML file generated by XMLSpy v2008 sp1 (http://www.altova.com)")
                );

            OCEBOSDoc.Declaration = new XDeclaration("1.0", "UTF-8", "");
            var root = new XElement("Shipment");

            if (shipment.Element("SubShipmentCollection").Element("SubShipment") != null)
            {
                root = AnalyseSubshipment(shipment);
                if (root.HasElements)
                {
                    OCEBOSDoc.Add(root);
                    return(OCEBOSDoc);
                }
            }

            OCEBOSDoc.Add(root);
            var    datacontext   = shipment.Element("DataContext");
            string mshipmentType = shipment.Element("ContainerMode").Element("Code").Value;
            string movementType  = shipment.Element("TransportMode").Element("Code").Value;
            string mVessel       = shipment.Element("VesselName").Value;
            string mVoyage       = shipment.Element("VoyageFlightNo").Value;

            string mMSWB_NUM = shipment.Element("BookingConfirmationReference").Value;
            string mSWB_NUM  = datacontext.Element("DataSourceCollection").Elements("DataSource").Where(x => x.Element("Type").Value == "ForwardingShipment").FirstOrDefault().Element("Key").Value;

            var siteid        = datacontext.Element("EnterpriseID").Value + datacontext.Element("Company").Element("Code").Value;
            var sqlHelper     = new SQLHelper(Resource1.ATP_SEA);
            var dt            = sqlHelper.ExecuteQuery2DataTable("select * From dbo.Ocebos_Number", System.Data.CommandType.Text);
            var Ocebos_Number = "";

            if (dt != null && dt.Rows.Count > 0)
            {
                Ocebos_Number = dt.Rows[0][0].ToString();
                Ocebos_Number = addstr(Ocebos_Number);
                sqlHelper.ExecuteNoQuery("update Ocebos_Number set maxid=maxid+1", System.Data.CommandType.Text);
            }

            var dateColection = shipment.Element("DateCollection");

            XElement TransactionId = new XElement("TransactionId");

            TransactionId.Value = "SEA" + DateTime.Now.ToString("yyyyMMddhhmm");
            root.Add(TransactionId);

            XElement TransactionDateTime = new XElement("TransactionDateTime");

            TransactionDateTime.Value = DateTime.Now.Date.ToString("yyyy-MM-dd hh:mm:ss");
            root.Add(TransactionDateTime);

            XElement TransactionSetPurpose = new XElement("TransactionSetPurpose");

            TransactionSetPurpose.Value = "Add";
            root.Add(TransactionSetPurpose);

            XElement ShipmentType = new XElement("ShipmentType");

            ShipmentType.Value = mshipmentType;
            root.Add(ShipmentType);


            XElement DocumentDate = new XElement("DocumentDate");
            var      documentdate = dateColection.Elements().Where(x => x.Name.LocalName == "BillIssued").FirstOrDefault().Value;

            documentdate = documentdate.Length > 10 ? documentdate.Substring(0, 10) : documentdate;
            root.Add(DocumentDate);

            XElement FileNumber = new XElement("FileNumber");

            FileNumber.Value = "File" + Ocebos_Number;
            root.Add(FileNumber);

            XElement MasterBillNumber = new XElement("MasterBillNumber");

            MasterBillNumber.Value = mMSWB_NUM;
            root.Add(MasterBillNumber);

            XElement HouseBillNumber = new XElement("HouseBillNumber");

            HouseBillNumber.Value = mSWB_NUM;
            root.Add(HouseBillNumber);

            XElement SubHouseBillNumber = new XElement("SubHouseBillNumber");

            SubHouseBillNumber.Value = "";
            root.Add(SubHouseBillNumber);

            XElement ITNumber = new XElement("ITNumber");

            ITNumber.Value = "aaaaaaaa";
            root.Add(ITNumber);

            XElement BookingNumber = new XElement("BookingNumber");

            BookingNumber.Value = "";// SWB.Rows[0]["jobid"].ToString();
            root.Add(BookingNumber);

            XElement OriginReference = new XElement("OriginReference");

            OriginReference.Value = "aaaaaaaa";
            root.Add(OriginReference);

            XElement Division = new XElement("Division");

            Division.Value = siteid;
            root.Add(Division);

            XElement PaymentMethod = new XElement("PaymentMethod");

            PaymentMethod.Value = "";//mswbTbl.Rows[0]["Pay_term"].ToString();
            root.Add(PaymentMethod);

            XElement TransportationMethod = new XElement("TransportationMethod");

            TransportationMethod.Value = "OCEAN";
            root.Add(TransportationMethod);

            XElement TypeOfMove = new XElement("TypeOfMove");

            TypeOfMove.Value = movementType;
            root.Add(TypeOfMove);

            XElement VesselName = new XElement("VesselName");

            VesselName.Value = mVessel;
            root.Add(VesselName);

            XElement VoyageFlightNumber = new XElement("VoyageFlightNumber");

            VoyageFlightNumber.Value = mVoyage;
            root.Add(VoyageFlightNumber);

            XElement DepartureDateTime = new XElement("DepartureDateTime");

            DepartureDateTime.Value = dateColection.Elements().Where(x => x.Element("Type").Value == "ShippedOnBoard").FirstOrDefault().Value;
            root.Add(DepartureDateTime);

            XElement ArrivalDateTime = new XElement("ArrivalDateTime");

            ArrivalDateTime.Value = dateColection.Elements().Where(x => x.Element("Type").Value == "FirstForeignArrival").FirstOrDefault().Value;
            root.Add(ArrivalDateTime);

            XElement ImportDate = new XElement("ImportDate");

            ImportDate.Value = ArrivalDateTime.Value.Length > 0 ? ArrivalDateTime.Value.Substring(0, 10) : "";
            root.Add(ImportDate);

            XElement FIRMSCode = new XElement("FIRMSCode");

            FIRMSCode.Value = "aaaaaaaa";
            root.Add(FIRMSCode);

            XElement Parties = new XElement("Parties");

            root.Add(Parties);

            var OrganCollect = shipment.Elements("OrganizationAddressCollection").Elements();

            foreach (var OrganizationAddress in OrganCollect)
            {
                var Party = new XElement("Party");
                Parties.Add(Party);
                var      OrganizationCode = OrganizationAddress.Element("AddressType").Value;
                XElement PartyType        = new XElement("PartyType");
                PartyType.Value = OrganizationCode;
                Party.Add(PartyType);

                XElement PartyCode = new XElement("PartyCode");
                PartyCode.Value = OrganizationCode;
                Party.Add(PartyCode);

                XElement PartyName = new XElement("Name");
                PartyName.Value = OrganizationAddress.Element("CompanyName").Value;
                Party.Add(PartyName);

                XElement PartyAddress1 = new XElement("Address1");
                PartyAddress1.Value = OrganizationAddress.Element("Address1").Value;
                Party.Add(PartyAddress1);

                XElement PartyAddress2 = new XElement("Address2");
                PartyAddress2.Value = OrganizationAddress.Element("Address2").Value;
                Party.Add(PartyAddress2);

                string str_cityname            = OrganizationAddress.Element("City").Value,
                       str_StateOrProvinceCode = OrganizationAddress.Element("State").Value,
                       str_CountryCode         = OrganizationAddress.Element("Country").Element("Code").Value;

                XElement CityName = new XElement("CityName");
                CityName.Value = str_cityname;
                Party.Add(CityName);

                XElement StateOrProvinceCode = new XElement("StateOrProvinceCode");
                StateOrProvinceCode.Value = str_StateOrProvinceCode;
                Party.Add(StateOrProvinceCode);

                XElement PostalCode = new XElement("PostalCode");
                PostalCode.Value = OrganizationAddress.Element("Postcode").Value;
                Party.Add(PostalCode);

                XElement CountryCode = new XElement("CountryCode");
                CountryCode.Value = str_CountryCode;
                Party.Add(CountryCode);

                XElement IdCode = new XElement("IdCode");
                IdCode.Value = OrganizationCode;
                Party.Add(IdCode);

                XElement IdCodeQualifier = new XElement("IdCodeQualifier");
                IdCodeQualifier.Value = OrganizationCode;
                Party.Add(IdCodeQualifier);
            }

            /*
             * 把各种地点类型放在字典里,循环读取添加
             */
            XElement Locations = new XElement("Locations");

            root.Add(Locations);

            foreach (var key in LocationTypeDict.Keys)
            {
                root.Add(getLocation(siteid, mSWB_NUM, key, shipment));
            }

            /**************************/

            XElement Containers = new XElement("Containers");

            root.Add(Containers);

            var containerCollection = shipment.Element("ContainerCollection").Elements("Container");

            foreach (var XContainer in containerCollection)
            {
                var Container = new XElement("Container");
                Containers.Add(Container);

                XElement EquipmentInitial = new XElement("EquipmentInitial");
                var      containerNum     = XContainer.Element("ContainerNumber").Value;
                //EquipmentInitial.Value = containerNum.Length > 4 ? containerNum.Substring(0, 4) : containerNum;
                EquipmentInitial.Value = containerNum;
                Container.Add(EquipmentInitial);

                XElement EquipmentNumber = new XElement("EquipmentNumber");
                //EquipmentNumber.Value = containerNum.Length > 4 ? containerNum.Substring(0, 4) : containerNum;
                EquipmentNumber.Value = containerNum;
                Container.Add(EquipmentNumber);

                XElement SealNumber1 = new XElement("SealNumber1");
                SealNumber1.Value = XContainer.Element("Seal").Value;
                Container.Add(SealNumber1);

                XElement EquipmentTypeCode = new XElement("EquipmentTypeCode");
                EquipmentTypeCode.Value = XContainer.Element("ContainerType").Element("Code").Value;
                Container.Add(EquipmentTypeCode);

                var Contents = new XElement("Contents");
                Contents.Value = "";
                Container.Add(Contents);

                var Content = new XElement("Content");
                Contents.Add(Content);

                XElement QuantityShipped = new XElement("QuantityShipped");
                QuantityShipped.Value = string.Empty;
                Content.Add(QuantityShipped);

                XElement UnitOfMeasure = new XElement("UnitOfMeasure");
                UnitOfMeasure.Value = string.Empty;
                Content.Add(UnitOfMeasure);

                XElement Description = new XElement("Description");
                Description.Value = "aaaaaaaa";
                Content.Add(Description);

                XElement GrossWeight = new XElement("GrossWeight");
                GrossWeight.Value = XContainer.Elements("GrossWeight").Where(x => int.Parse(x.Value) > 0).FirstOrDefault().Value;
                Content.Add(GrossWeight);

                XElement NetWeight = new XElement("NetWeight");
                NetWeight.Value = GrossWeight.Value;
                Content.Add(NetWeight);

                XElement WeightUnit = new XElement("WeightUnit");
                WeightUnit.Value = XContainer.Element("WeightUnit").Value;
                Content.Add(WeightUnit);

                XElement VolumeWeight = new XElement("VolumeWeight");
                VolumeWeight.Value = GrossWeight.Value;
                Content.Add(VolumeWeight);

                var height = XContainer.Element("TotalHeight").Value;
                var length = XContainer.Element("TotalLength").Value;
                var width  = XContainer.Element("TotalWidth").Value;
                var volumn = 0.0;
                try
                {
                    volumn = float.Parse(height) * float.Parse(length) * float.Parse(width);
                }
                catch
                {
                    volumn = 0.0;
                }
                XElement Volume = new XElement("Volume");
                Volume.Value = volumn.ToString();
                Content.Add(Volume);

                XElement VolumeUnit = new XElement("VolumeUnit");
                VolumeUnit.Value = XContainer.Element("VolumeUnit").Value;
                Content.Add(VolumeUnit);

                XElement ScheduleBNumber = new XElement("ScheduleBNumber");
                ScheduleBNumber.Value = "";
                Content.Add(ScheduleBNumber);

                XElement HTSNumber = new XElement("HTSNumber");
                HTSNumber.Value = string.Empty;
                Content.Add(HTSNumber);

                XElement Value = new XElement("Value");
                Value.Value = "";
                Content.Add(Value);
            }


            var Charges = new XElement("Charges");

            Charges.Value = "";
            root.Add(Charges);

            XElement MarksNumbers = new XElement("MarksNumbers");

            //MarksNumbers.Value = "AWBServiceLevel:" + shipment.Element("AWBServiceLevel").Element("Description").Value + Environment.NewLine + "ContainerMode:" + shipment.Element("ContainerMode").Element("Description").Value;
            MarksNumbers.Value = string.Empty;
            return(OCEBOSDoc);
        }
 protected ITranslationDefinitions <OrganizationAddress, TModel> CreateBaseEntityVmDefinitions(OrganizationAddress entity)
 {
     return(CreateEntityViewModelDefinition <TModel>(entity)
            .AddNavigation(i => typesCache.GetByValue <AddressCharacter>(i.CharacterId), o => o.Type)
            .AddPartial(i => i.Address));
 }
 public override TModel TranslateEntityToVm(OrganizationAddress entity)
 {
     return(CreateBaseEntityVmDefinitions(entity).GetFinal());
 }
示例#13
0
 public void Init()
 {
     instance = new OrganizationAddress();
 }