Exemplo n.º 1
0
        public static TAddress CloneTo <TAddress>(this IAddress from)
            where TAddress : IAddress, new()
        {
            var to = new TAddress();

            from.CopyTo(to);
            return(to);
        }
Exemplo n.º 2
0
 public static square.Address ToNativeSquareAddress(this IAddress data)
 {
     if (typeof(square.Address).IsInstanceOfType(data))
     {
         return((square.Address)data);
     }
     else
     {
         var ret = new DataContracts.SquareAddress();
         data.CopyTo(ret);
         return(ret);
     }
 }
Exemplo n.º 3
0
        public static Expression <Func <IAddress, bool> > ToLambda(this IAddress filter)
        {
            if (filter == null)
            {
                return(x => false);
            }

            if (filter.ValidateDataAnnotations().Any(v => !string.IsNullOrEmpty(v.ErrorMessage)))
            {
                return(x => false);
            }

            AddressImplementor trimmedAddress = new AddressImplementor();

            filter.CopyTo(trimmedAddress, true);
            if (trimmedAddress.Address1 != null)
            {
                trimmedAddress.Address1 = trimmedAddress.Address1.Trim().ToUpper();
            }
            if (trimmedAddress.City != null)
            {
                trimmedAddress.City = trimmedAddress.City.Trim().ToUpper();
            }
            if (trimmedAddress.Country != null)
            {
                trimmedAddress.Country = trimmedAddress.Country.Trim().ToUpper();
            }
            if (trimmedAddress.PostalCode != null)
            {
                trimmedAddress.PostalCode = trimmedAddress.PostalCode.Replace(" ", "").Trim().ToUpper();
            }
            if (trimmedAddress.Province != null)
            {
                trimmedAddress.Province = trimmedAddress.Province.Trim().ToUpper();
            }
            if (trimmedAddress.ProvinceName != null)
            {
                trimmedAddress.ProvinceName = trimmedAddress.ProvinceName.Trim().ToUpper();
            }

            Expression res;
            Expression <Func <IAddress, bool> > ret = x => true;
            var expParam = ret.Parameters.First();

            res = ret.Body;

            //???: Do we need to serve IsResidential ?

            if (trimmedAddress.AddressId != default(int))
            {
                res = Expression.AndAlso(Expression.Equal(expParam.GetFieldAccessExpression("AddressId"), Expression.Constant(trimmedAddress.AddressId)), res);
            }
            if (!string.IsNullOrEmpty(trimmedAddress.Address1))
            {
                res = Expression.AndAlso(Expression.Equal(expParam.GetFieldAccessExpression("Address1"), Expression.Constant(trimmedAddress.Address1)), res);
            }
            if (!string.IsNullOrEmpty(trimmedAddress.City))
            {
                res = Expression.AndAlso(Expression.Equal(expParam.GetFieldAccessExpression("City"), Expression.Constant(trimmedAddress.City)), res);
            }
            if (!string.IsNullOrEmpty(trimmedAddress.Country))
            {
                res = Expression.AndAlso(Expression.Equal(expParam.GetFieldAccessExpression("Country"), Expression.Constant(trimmedAddress.Country)), res);
            }
            if (!string.IsNullOrEmpty(trimmedAddress.PostalCode))
            {
                res = Expression.AndAlso(Expression.Equal(expParam.GetFieldAccessExpression("PostalCode"), Expression.Constant(trimmedAddress.PostalCode)), res);
            }
            if (!string.IsNullOrEmpty(trimmedAddress.Province))
            {
                res = Expression.AndAlso(Expression.Equal(expParam.GetFieldAccessExpression("Province"), Expression.Constant(trimmedAddress.Province)), res);
            }
            if (!string.IsNullOrEmpty(trimmedAddress.ProvinceName))
            {
                res = Expression.AndAlso(Expression.Equal(expParam.GetFieldAccessExpression("ProvinceName"), Expression.Constant(trimmedAddress.ProvinceName)), res);
            }
            if (trimmedAddress.ValidityLevel != default(byte))
            {
                res = Expression.AndAlso(Expression.GreaterThanOrEqual(expParam.GetFieldAccessExpression("ValidityLevel"), Expression.Constant(trimmedAddress.ValidityLevel)), res);
            }

            return(Expression.Lambda <Func <IAddress, bool> >(res, expParam));
        }