예제 #1
0
        public virtual void Patch(StoreEntity target)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            target.AdminEmail        = AdminEmail;
            target.Catalog           = Catalog;
            target.Country           = Country;
            target.DefaultCurrency   = DefaultCurrency;
            target.DefaultLanguage   = DefaultLanguage;
            target.Description       = Description;
            target.DisplayOutOfStock = DisplayOutOfStock;
            target.Email             = Email;
            target.ModifiedBy        = ModifiedBy;
            target.ModifiedDate      = ModifiedDate;
            target.Name                       = Name;
            target.Region                     = Region;
            target.SecureUrl                  = SecureUrl;
            target.TimeZone                   = TimeZone;
            target.Url                        = Url;
            target.StoreState                 = (int)StoreState;
            target.FulfillmentCenterId        = FulfillmentCenterId;
            target.ReturnsFulfillmentCenterId = ReturnsFulfillmentCenterId;

            if (!Languages.IsNullCollection())
            {
                var languageComparer = AnonymousComparer.Create((StoreLanguageEntity x) => x.LanguageCode);
                Languages.Patch(target.Languages, languageComparer,
                                (sourceLang, targetLang) => targetLang.LanguageCode = sourceLang.LanguageCode);
            }
            if (!Currencies.IsNullCollection())
            {
                var currencyComparer = AnonymousComparer.Create((StoreCurrencyEntity x) => x.CurrencyCode);
                Currencies.Patch(target.Currencies, currencyComparer,
                                 (sourceCurrency, targetCurrency) => targetCurrency.CurrencyCode = sourceCurrency.CurrencyCode);
            }
            if (!TrustedGroups.IsNullCollection())
            {
                var trustedGroupComparer = AnonymousComparer.Create((StoreTrustedGroupEntity x) => x.GroupName);
                TrustedGroups.Patch(target.TrustedGroups, trustedGroupComparer,
                                    (sourceGroup, targetGroup) => sourceGroup.GroupName = targetGroup.GroupName);
            }

            if (!PaymentMethods.IsNullCollection())
            {
                var paymentComparer = AnonymousComparer.Create((StorePaymentMethodEntity x) => x.Code);
                PaymentMethods.Patch(target.PaymentMethods, paymentComparer,
                                     (sourceMethod, targetMethod) => sourceMethod.Patch(targetMethod));
            }
            if (!ShippingMethods.IsNullCollection())
            {
                var shippingComparer = AnonymousComparer.Create((StoreShippingMethodEntity x) => x.Code);
                ShippingMethods.Patch(target.ShippingMethods, shippingComparer,
                                      (sourceMethod, targetMethod) => sourceMethod.Patch(targetMethod));
            }
            if (!TaxProviders.IsNullCollection())
            {
                var shippingComparer = AnonymousComparer.Create((StoreTaxProviderEntity x) => x.Code);
                TaxProviders.Patch(target.TaxProviders, shippingComparer,
                                   (sourceProvider, targetProvider) => sourceProvider.Patch(targetProvider));
            }
            if (!FulfillmentCenters.IsNullCollection())
            {
                var fulfillmentCenterComparer = AnonymousComparer.Create((StoreFulfillmentCenterEntity fc) => $"{fc.FulfillmentCenterId}-{fc.Type}");
                FulfillmentCenters.Patch(target.FulfillmentCenters, fulfillmentCenterComparer,
                                         (sourceFulfillmentCenter, targetFulfillmentCenter) => sourceFulfillmentCenter.Patch(targetFulfillmentCenter));
            }
        }