/// <summary> /// Converting to model type /// </summary> /// <param name="catalogBase"></param> /// <returns></returns> public static coreModel.Store ToCoreModel(this dataModel.Store dbStore, ShippingMethod[] shippingMethods, PaymentMethod[] paymentMethods, TaxProvider[] taxProviders) { if (dbStore == null) throw new ArgumentNullException("dbStore"); var retVal = new coreModel.Store(); retVal.InjectFrom(dbStore); if(dbStore.DefaultCurrency != null) { retVal.DefaultCurrency = (CurrencyCodes?)Enum.Parse(typeof(CurrencyCodes), dbStore.DefaultCurrency, true); } retVal.StoreState = (coreModel.StoreState)dbStore.StoreState; retVal.Languages = dbStore.Languages.Select(x => x.LanguageCode).ToList(); retVal.Currencies = dbStore.Currencies.Select(x => (CurrencyCodes)Enum.Parse(typeof(CurrencyCodes), x.CurrencyCode, true)).ToList(); //Payment methods need return only contains in registered retVal.PaymentMethods = paymentMethods; foreach (var paymentMethod in paymentMethods) { var dbStoredPaymentMethod = dbStore.PaymentMethods.FirstOrDefault(x => x.Code == paymentMethod.Code); if (dbStoredPaymentMethod != null) { paymentMethod.InjectFrom(dbStoredPaymentMethod); } } //Shipping methods need return only contains in registered retVal.ShippingMethods = shippingMethods; foreach (var shippingMethod in shippingMethods) { var dbStoredShippingMethod = dbStore.ShippingMethods.FirstOrDefault(x => x.Code == shippingMethod.Code); if(dbStoredShippingMethod != null) { shippingMethod.InjectFrom(dbStoredShippingMethod); } } //Tax providers need return only contains in registered retVal.TaxProviders = taxProviders; foreach (var taxProvider in taxProviders) { var dbStoredTaxProvider = dbStore.TaxProviders.FirstOrDefault(x => x.Code == taxProvider.Code); if (dbStoredTaxProvider != null) { taxProvider.InjectFrom(dbStoredTaxProvider); } } return retVal; }
public static webModel.TaxProvider ToWebModel(this coreModel.TaxProvider method) { var retVal = new webModel.TaxProvider(); retVal.InjectFrom(method); if (method.Settings != null) { retVal.Settings = method.Settings.Select(x => x.ToWebModel()).ToList(); } return(retVal); }
public static dataModel.StoreTaxProvider ToDataModel(this coreModel.TaxProvider taxProvider) { if (taxProvider == null) { throw new ArgumentNullException("taxProvider"); } var retVal = new dataModel.StoreTaxProvider(); retVal.InjectFrom(taxProvider); return(retVal); }
public static coreModel.TaxProvider ToCoreModel(this webModel.TaxProvider webTaxProvider, coreModel.TaxProvider taxProvider) { var retVal = taxProvider; retVal.InjectFrom(webTaxProvider); if (webTaxProvider.Settings != null) { retVal.Settings = webTaxProvider.Settings.Select(x => x.ToCoreModel()).ToList(); } return(retVal); }