Пример #1
0
        public void CheckingAllBasicValues(object value, string expected)
        {
            var sut    = new DefaultConverter();
            var result = sut.Convert(value);

            result.Should().Be(expected);
        }
        public static void ConfigureNameAndAddress <TInner, TSecondContract>(ConverterConfigurator <TInner, PartyInfo, TSecondContract, NameAndAddress, NameAndAddress> configurator, TestConverterContext context, DefaultConverter defaultConverter)
        {
            configurator.Target(nameAndAddress => nameAndAddress.PartyNameType.PartyName)
            .Set(party => party.RussianPartyInfo.RussianPartyType == RussianPartyType.IP
                                          ? new[] { party.RussianPartyInfo.IPInfo.LastName, party.RussianPartyInfo.IPInfo.FirstName, party.RussianPartyInfo.IPInfo.MiddleName }
                                          : ArrayStringConverter.ToArrayString(party.RussianPartyInfo.ULInfo.Name, 35, 5));

            configurator.Target(nameAndAddress => nameAndAddress.PartyNameType.PartyNameFormatCode)
            .Set(party => party.RussianPartyInfo.RussianPartyType == RussianPartyType.IP ? "IP" : "UL");

            var addressConfigurator = configurator.GoTo(address => address, party => party.PartyAddress);

            addressConfigurator.If((x, address) => address.CityName != null ||
                                   address.CountrySubEntityDetails.CountrySubEntityNameCode != null ||
                                   address.CountrySubEntityDetails.CountrySubEntityName != null ||
                                   address.PostalIdentificationCode != null ||
                                   address.Street.StreetAndNumberOrPostBoxIdentifier != null)
            .Target(address => address.CountryNameCode)
            .Set(address => defaultConverter.Convert(address.AddressType == AddressType.Russian ? "643" : address.ForeignAddressInfo.CountryCode));

            var useSemicolon = new[] { MutatorsContextType.None }.Contains(context.MutatorsContextType);

            addressConfigurator.Target(address => address.Street.StreetAndNumberOrPostBoxIdentifier)
            .Set(address => address.AddressType == AddressType.Russian
                                                   ? new[] { address.RussianAddressInfo.Street, address.RussianAddressInfo.House, address.RussianAddressInfo.Flat }.JoinIgnoreEmpty(useSemicolon ? "; " : ", ")
                                                   : address.ForeignAddressInfo.Address,
                 s => ArrayStringConverter.ToArrayString(s, 35, 4));

            addressConfigurator.Target(address => address.CityName)
            .Set(address => address.AddressType == AddressType.Russian
                                                   ? new[] { address.RussianAddressInfo.City, address.RussianAddressInfo.Village }.JoinIgnoreEmpty(", ") : null);

            addressConfigurator.Target(address => address.CountrySubEntityDetails.CountrySubEntityName)
            .Set(address => address.AddressType == AddressType.Russian
                                                   ? new[] { defaultConverter.Convert(address.RussianAddressInfo.RegionCode), address.RussianAddressInfo.District }.JoinIgnoreEmpty(", ") : null);

            addressConfigurator.Target(address => address.PostalIdentificationCode)
            .Set(address => address.AddressType == AddressType.Russian ? address.RussianAddressInfo.PostalCode : null);
        }
Пример #3
0
        bool FilterProperty(LeafNode leafnode, Type proptype, DetachedCriteria query, string prop, string mode)
        {
            var converter   = new DefaultConverter();
            var isconverted = false;
            var val         = converter.Convert(proptype, leafnode.Value, out isconverted);

            if (prop == mode)
            {
                if (isconverted)
                {
                    query.Add(Restrictions.Eq(prop, val));
                    SetParam(leafnode);
                }
            }
            else
            {
                if (isconverted)
                {
                    SetParam(leafnode);
                    switch (mode.ToLower())
                    {
                    case "gt":
                        query.Add(Restrictions.Gt(prop, val));
                        break;

                    case "ge":
                        query.Add(Restrictions.Ge(prop, val));
                        break;

                    case "lt":
                        query.Add(Restrictions.Le(prop, val));
                        break;

                    case "le":
                        query.Add(Restrictions.Le(prop, val));
                        break;

                    case "like":
                        query.Add(Restrictions.InsensitiveLike(prop, val.ToString(), MatchMode.Anywhere));
                        break;

                    case "startswith":
                        query.Add(Restrictions.InsensitiveLike(prop, val.ToString(), MatchMode.Start));
                        break;
                    }
                }
            }
            return(isconverted);
        }
Пример #4
0
        public static void ConfigureFromFirstContractToInner <TFirst, TInner>(
            ConverterConfigurator <TFirst, FirstContractPartyInfo, TInner, PartyInfo, PartyInfo> configurator, DefaultConverter defaultConverter)
        {
            configurator.Target(x => x.Gln).Set(x => x.Gln);

            configurator.Target(x => x.PartyInfoType).If(x => x.SelfEmployed != null || x.Organization != null).Set(x => PartyInfoType.Russian);
            configurator.Target(x => x.PartyInfoType).If(x => x.ForeignOrganization != null).Set(x => PartyInfoType.Foreign);
            configurator.Target(x => x.PartyAddress.AddressType).Set(x => x.ForeignAddress.IsEmpty() ? AddressType.Russian : AddressType.Foreign);
            configurator.Target(x => x.UsesSimplifiedTaxSystem).Set(x => x.TaxSystem == "Simplified");

            var russianConfigurator = configurator.If((x, y) => y.PartyAddress.AddressType == AddressType.Russian)
                                      .GoTo(x => x.PartyAddress.RussianAddressInfo);

            russianConfigurator.Target(x => x.PostalCode).Set(x => x.RussianAddress.PostalCode);
            russianConfigurator.Target(x => x.City).Set(x => x.RussianAddress.City);

            var foreignConfigurator = configurator.If((x, y) => y.PartyAddress.AddressType == AddressType.Foreign)
                                      .GoTo(x => x.PartyAddress.ForeignAddressInfo);

            foreignConfigurator.Target(x => x.CountryCode).Set(x => defaultConverter.Convert(x.ForeignAddress.CountryIsoCode));
            foreignConfigurator.Target(x => x.Address).Set(x => x.ForeignAddress.Address);

            configurator.Target(x => x.RussianPartyInfo.RussianPartyType).Set(x => x.SelfEmployed == null ? RussianPartyType.UL : RussianPartyType.IP);

            var ulConfigurator = configurator.If((x, y) => y.RussianPartyInfo.RussianPartyType == RussianPartyType.UL)
                                 .GoTo(x => x.RussianPartyInfo.ULInfo);

            ulConfigurator.Target(x => x.Inn).Set(x => x.Organization.Inn);
            ulConfigurator.Target(x => x.Name).Set(x => x.Organization.Name);

            var ipConfigurator = configurator.If((x, y) => y.RussianPartyInfo.RussianPartyType == RussianPartyType.IP)
                                 .GoTo(x => x.RussianPartyInfo.IPInfo);

            ipConfigurator.Target(x => x.Inn).Set(x => x.SelfEmployed.Inn);
            ipConfigurator.Target(x => x.FirstName).Set(x => x.SelfEmployed.FullName.FirstName);
            ipConfigurator.Target(x => x.LastName).Set(x => x.SelfEmployed.FullName.LastName);

            var chiefConfigurator = configurator.GoTo(x => x.Chief, x => x.ContactInfo.Ceo);

            chiefConfigurator.Target(x => x.Name).Set(x => x.Name);
            chiefConfigurator.Target(x => x.Phone).Set(x => x.Phone);

            configurator.If(x => string.IsNullOrEmpty(x.ContactInfo.Ceo.Phone)).Target(x => x.Chief.Phone).Set(x => x.AdditionalInfo.Phone);
            configurator.If(x => string.IsNullOrEmpty(x.ContactInfo.Ceo.Name)).Target(x => x.Chief.Name).Set(x => x.AdditionalInfo.NameOfCeo);
        }
Пример #5
0
        public static void ConfigureFromInnerToFirstContract(ConverterConfigurator <InnerDocument, PartyInfo, FirstContractDocument, FirstContractPartyInfo, FirstContractPartyInfo> configurator, DefaultConverter defaultConverter)
        {
            configurator.Target(x => x.Gln).Set(x => x.Gln);
            configurator.Target(x => x.TaxSystem).If(x => x.UsesSimplifiedTaxSystem).Set("Simplified");

            var foreignConfigurator = configurator.If(x => x.PartyInfoType == PartyInfoType.Foreign)
                                      .GoTo(x => x.ForeignOrganization, x => x.ForeignPartyInfo);

            foreignConfigurator.Target(x => x.Name).Set(x => x.Name);

            var orgConfigurator = configurator.GoTo(x => x.Organization, x => x.RussianPartyInfo.ULInfo);

            orgConfigurator.Target(x => x.Inn).Set(x => x.Inn);
            orgConfigurator.Target(x => x.Name).Set(x => x.Name);

            var ipConfigurator = configurator.GoTo(x => x.SelfEmployed, x => x.RussianPartyInfo.IPInfo);

            ipConfigurator.Target(x => x.Inn).Set(x => x.Inn);
            ipConfigurator.Target(x => x.FullName.FirstName).Set(x => x.FirstName);
            ipConfigurator.Target(x => x.FullName.LastName).Set(x => x.LastName);

            var rusAddrConfigurator = configurator.GoTo(x => x.RussianAddress, x => x.PartyAddress.RussianAddressInfo);

            rusAddrConfigurator.Target(x => x.PostalCode).Set(x => x.PostalCode);
            rusAddrConfigurator.Target(x => x.City).Set(x => x.City);

            var foreignAddrConfigurator = configurator.GoTo(x => x.ForeignAddress, x => x.PartyAddress.ForeignAddressInfo);

            foreignAddrConfigurator.Target(x => x.Address).Set(x => x.Address);
            foreignAddrConfigurator.Target(x => x.CountryIsoCode).Set(x => defaultConverter.Convert(x.CountryCode));

            var chiefConfigurator = configurator.GoTo(x => x.ContactInfo.Ceo, x => x.Chief);

            chiefConfigurator.Target(x => x.Name).Set(x => x.Name);
            chiefConfigurator.Target(x => x.Phone).Set(x => x.Phone);

            var aiConfigurator = configurator.GoTo(x => x.AdditionalInfo);

            aiConfigurator.Target(x => x.Phone).Set(x => string.IsNullOrEmpty(x.OrderContact.Phone) ? x.Chief.Phone : x.OrderContact.Phone);
            aiConfigurator.Target(x => x.NameOfCeo).Set(x => string.IsNullOrEmpty(x.OrderContact.Name) ? x.Chief.Name : x.OrderContact.Name);
        }
        public static IEnumerable <FreeText> FreeTexts(this CommonGoodItem item, DefaultConverter defaultConverter)
        {
            if (item == null)
            {
                yield break;
            }

            if (item.FlowType != null)
            {
                yield return(new FreeText
                {
                    TextSubjectCodeQualifier = "DEL",
                    FreeTextFunctionCode = "ZZZ",
                    TextLiteral = new TextLiteral {
                        FreeTextValue = new[] { defaultConverter.Convert(item.FlowType) }
                    },
                });
            }

            var freeTextItems = new[]
            {
                new { subjectCodeQualifier = "PRD", value = item.Dimensions },
                new { subjectCodeQualifier = "ACB", value = item.Comment },
            };

            foreach (var freeTextItem in freeTextItems)
            {
                if (freeTextItem.value != null)
                {
                    yield return new FreeText
                           {
                               TextSubjectCodeQualifier = freeTextItem.subjectCodeQualifier,
                               TextLiteral = new TextLiteral {
                                   FreeTextValue = ArrayStringConverter.ToArrayString(freeTextItem.value, 512, 5)
                               },
                           }
                }
                ;
            }
        }
 private object Convert(Type desiredType, string input)
 {
     return(converter.Convert(desiredType, typeof(string), input, out convSucceed));
 }