コード例 #1
0
        public static dataModel.Store ToDataModel(this coreModel.Store store)
        {
            if (store == null)
            {
                throw new ArgumentNullException("store");
            }

            var retVal = new dataModel.Store();

            retVal.InjectFrom(store);
            retVal.StoreState = (int)store.StoreState;

            if (store.DefaultCurrency != null)
            {
                retVal.DefaultCurrency = store.DefaultCurrency.ToString();
            }
            if (store.FulfillmentCenter != null)
            {
                retVal.FulfillmentCenterId = store.FulfillmentCenter.Id;
            }
            if (store.ReturnsFulfillmentCenter != null)
            {
                retVal.ReturnsFulfillmentCenterId = store.ReturnsFulfillmentCenter.Id;
            }
            if (store.Languages != null)
            {
                retVal.Languages = new ObservableCollection <dataModel.StoreLanguage>(store.Languages.Select(x => new dataModel.StoreLanguage
                {
                    LanguageCode = x,
                    StoreId      = retVal.Id
                }));
            }

            if (store.Currencies != null)
            {
                retVal.Currencies = new ObservableCollection <dataModel.StoreCurrency>(store.Currencies.Select(x => new dataModel.StoreCurrency
                {
                    CurrencyCode = x.ToString(),
                    StoreId      = retVal.Id
                }));
            }

            if (store.ShippingMethods != null)
            {
                retVal.ShippingMethods = new ObservableCollection <dataModel.StoreShippingMethod>(store.ShippingMethods.Select(x => x.ToDataModel()));
            }
            if (store.PaymentMethods != null)
            {
                retVal.PaymentMethods = new ObservableCollection <dataModel.StorePaymentMethod>(store.PaymentMethods.Select(x => x.ToDataModel()));
            }
            if (store.TaxProviders != null)
            {
                retVal.TaxProviders = new ObservableCollection <dataModel.StoreTaxProvider>(store.TaxProviders.Select(x => x.ToDataModel()));
            }
            return(retVal);
        }
コード例 #2
0
        /// <summary>
        /// Patch changes
        /// </summary>
        /// <param name="source"></param>
        /// <param name="target"></param>
        public static void Patch(this dataModel.Store source, dataModel.Store target)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }
            var patchInjectionPolicy = new PatchInjection <dataModel.Store>(x => x.FulfillmentCenterId, x => x.ReturnsFulfillmentCenterId,
                                                                            x => x.AdminEmail, x => x.Catalog,
                                                                            x => x.Country, x => x.CreditCardSavePolicy,
                                                                            x => x.DefaultCurrency, x => x.DefaultLanguage,
                                                                            x => x.Description, x => x.DisplayOutOfStock,
                                                                            x => x.Email, x => x.Name, x => x.Region, x => x.SecureUrl,
                                                                            x => x.TimeZone, x => x.Url, x => x.StoreState);

            target.InjectFrom(patchInjectionPolicy, source);


            if (!source.Languages.IsNullCollection())
            {
                var languageComparer = AnonymousComparer.Create((dataModel.StoreLanguage x) => x.LanguageCode);
                source.Languages.Patch(target.Languages, languageComparer,
                                       (sourceLang, targetLang) => targetLang.LanguageCode = sourceLang.LanguageCode);
            }
            if (!source.Currencies.IsNullCollection())
            {
                var currencyComparer = AnonymousComparer.Create((dataModel.StoreCurrency x) => x.CurrencyCode);
                source.Currencies.Patch(target.Currencies, currencyComparer,
                                        (sourceCurrency, targetCurrency) => targetCurrency.CurrencyCode = sourceCurrency.CurrencyCode);
            }
            if (!source.TrustedGroups.IsNullCollection())
            {
                var trustedGroupComparer = AnonymousComparer.Create((dataModel.StoreTrustedGroup x) => x.GroupName);
                source.TrustedGroups.Patch(target.TrustedGroups, trustedGroupComparer,
                                           (sourceGroup, targetGroup) => sourceGroup.GroupName = targetGroup.GroupName);
            }
            if (!source.PaymentMethods.IsNullCollection())
            {
                var paymentComparer = AnonymousComparer.Create((dataModel.StorePaymentMethod x) => x.Code);
                source.PaymentMethods.Patch(target.PaymentMethods, paymentComparer,
                                            (sourceMethod, targetMethod) => sourceMethod.Patch(targetMethod));
            }
            if (!source.ShippingMethods.IsNullCollection())
            {
                var shippingComparer = AnonymousComparer.Create((dataModel.StoreShippingMethod x) => x.Code);
                source.ShippingMethods.Patch(target.ShippingMethods, shippingComparer,
                                             (sourceMethod, targetMethod) => sourceMethod.Patch(targetMethod));
            }
            if (!source.TaxProviders.IsNullCollection())
            {
                var shippingComparer = AnonymousComparer.Create((dataModel.StoreTaxProvider x) => x.Code);
                source.TaxProviders.Patch(target.TaxProviders, shippingComparer,
                                          (sourceProvider, targetProvider) => sourceProvider.Patch(targetProvider));
            }
        }
コード例 #3
0
		public static dataModel.Store ToDataModel(this coreModel.Store store)
		{
			if (store == null)
				throw new ArgumentNullException("store");

			var retVal = new dataModel.Store();

			retVal.InjectFrom(store);
			retVal.StoreState = (int)store.StoreState;
			
			if(store.DefaultCurrency != null)
			{
				retVal.DefaultCurrency = store.DefaultCurrency.ToString();
			}
			if (store.FulfillmentCenter != null)
			{
				retVal.FulfillmentCenterId = store.FulfillmentCenter.Id;
			}
			if (store.ReturnsFulfillmentCenter != null)
			{
				retVal.ReturnsFulfillmentCenterId = store.ReturnsFulfillmentCenter.Id;
			}
			if (store.Languages != null)
			{
				retVal.Languages = new ObservableCollection<dataModel.StoreLanguage>(store.Languages.Select(x=> new dataModel.StoreLanguage
					{
						LanguageCode = x,
						StoreId = retVal.Id
					}));
			}
		
			if(store.Currencies != null)
			{
				retVal.Currencies = new ObservableCollection<dataModel.StoreCurrency>(store.Currencies.Select(x => new dataModel.StoreCurrency
				{
					CurrencyCode = x.ToString(),
					StoreId = retVal.Id
				}));
			}
			
			if (store.ShippingMethods != null)
			{
				retVal.ShippingMethods = new ObservableCollection<dataModel.StoreShippingMethod>(store.ShippingMethods.Select(x => x.ToDataModel()));
			}
			if (store.PaymentMethods != null)
			{
				retVal.PaymentMethods = new ObservableCollection<dataModel.StorePaymentMethod>(store.PaymentMethods.Select(x => x.ToDataModel()));
			}
            if (store.TaxProviders != null)
            {
                retVal.TaxProviders = new ObservableCollection<dataModel.StoreTaxProvider>(store.TaxProviders.Select(x => x.ToDataModel()));
            }
            return retVal;
		}