public virtual async Task <SwiperSliderModel> PrepareSliderModelAsync(SwiperSliderModel model, Slider slider) { if (slider != null) { if (model == null) { model = slider.ToModel <SwiperSliderModel>(); } await PrepareSliderItemSearchModelAsync(model.SwiperSliderItemSearchModel, slider); } if (slider == null) { model.Published = true; } //prepare model customer roles await _aclSupportedModelFactory.PrepareModelCustomerRolesAsync(model, slider, false); //prepare model stores await _storeMappingSupportedModelFactory.PrepareModelStoresAsync(model, slider, false); return(model); }
/// <summary> /// Prepare language model /// </summary> /// <param name="model">Language model</param> /// <param name="language">Language</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns>Language model</returns> public virtual async Task <LanguageModel> PrepareLanguageModelAsync(LanguageModel model, Language language, bool excludeProperties = false) { if (language != null) { //fill in model values from the entity model ??= language.ToModel <LanguageModel>(); //prepare nested search model PrepareLocaleResourceSearchModel(model.LocaleResourceSearchModel, language); } //set default values for the new model if (language == null) { model.DisplayOrder = (await _languageService.GetAllLanguagesAsync()).Max(l => l.DisplayOrder) + 1; model.Published = true; } //prepare available currencies await _baseAdminModelFactory.PrepareCurrenciesAsync(model.AvailableCurrencies, defaultItemText : await _localizationService.GetResourceAsync("Admin.Common.EmptyItemText")); //prepare available stores await _storeMappingSupportedModelFactory.PrepareModelStoresAsync(model, language, excludeProperties); return(model); }
/// <summary> /// Prepare news item model /// </summary> /// <param name="model">News item model</param> /// <param name="newsItem">News item</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the news item model /// </returns> public virtual async Task <NewsItemModel> PrepareNewsItemModelAsync(NewsItemModel model, NewsItem newsItem, bool excludeProperties = false) { //fill in model values from the entity if (newsItem != null) { if (model == null) { model = newsItem.ToModel <NewsItemModel>(); model.SeName = await _urlRecordService.GetSeNameAsync(newsItem, newsItem.LanguageId, true, false); } model.StartDateUtc = newsItem.StartDateUtc; model.EndDateUtc = newsItem.EndDateUtc; } //set default values for the new model if (newsItem == null) { model.Published = true; model.AllowComments = true; } //prepare available languages await _baseAdminModelFactory.PrepareLanguagesAsync(model.AvailableLanguages, false); //prepare available stores await _storeMappingSupportedModelFactory.PrepareModelStoresAsync(model, newsItem, excludeProperties); return(model); }
/// <summary> /// Prepare poll model /// </summary> /// <param name="model">Poll model</param> /// <param name="poll">Poll</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the poll model /// </returns> public virtual async Task <PollModel> PreparePollModelAsync(PollModel model, Poll poll, bool excludeProperties = false) { if (poll != null) { //fill in model values from the entity model ??= poll.ToModel <PollModel>(); model.StartDateUtc = poll.StartDateUtc; model.EndDateUtc = poll.EndDateUtc; //prepare nested search model PreparePollAnswerSearchModel(model.PollAnswerSearchModel, poll); } //set default values for the new model if (poll == null) { model.Published = true; model.ShowOnHomepage = true; } //prepare available languages await _baseAdminModelFactory.PrepareLanguagesAsync(model.AvailableLanguages, false); //prepare available stores await _storeMappingSupportedModelFactory.PrepareModelStoresAsync(model, poll, excludeProperties); return(model); }
/// <summary> /// Prepare topic model /// </summary> /// <param name="model">Topic model</param> /// <param name="topic">Topic</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns>Topic model</returns> public virtual async Task <TopicModel> PrepareTopicModelAsync(TopicModel model, Topic topic, bool excludeProperties = false) { Action <TopicLocalizedModel, int> localizedModelConfiguration = null; if (topic != null) { //fill in model values from the entity if (model == null) { model = topic.ToModel <TopicModel>(); model.SeName = await _urlRecordService.GetSeNameAsync(topic, 0, true, false); } model.Url = _urlHelperFactory.GetUrlHelper(_actionContextAccessor.ActionContext) .RouteUrl("Topic", new { SeName = await _urlRecordService.GetSeNameAsync(topic) }, _webHelper.GetCurrentRequestProtocol()); //define localized model configuration action localizedModelConfiguration = async(locale, languageId) => { locale.Title = await _localizationService.GetLocalizedAsync(topic, entity => entity.Title, languageId, false, false); locale.Body = await _localizationService.GetLocalizedAsync(topic, entity => entity.Body, languageId, false, false); locale.MetaKeywords = await _localizationService.GetLocalizedAsync(topic, entity => entity.MetaKeywords, languageId, false, false); locale.MetaDescription = await _localizationService.GetLocalizedAsync(topic, entity => entity.MetaDescription, languageId, false, false); locale.MetaTitle = await _localizationService.GetLocalizedAsync(topic, entity => entity.MetaTitle, languageId, false, false); locale.SeName = await _urlRecordService.GetSeNameAsync(topic, languageId, false, false); }; } //set default values for the new model if (topic == null) { model.DisplayOrder = 1; model.Published = true; } //prepare localized models if (!excludeProperties) { model.Locales = await _localizedModelFactory.PrepareLocalizedModelsAsync(localizedModelConfiguration); } //prepare available topic templates await _baseAdminModelFactory.PrepareTopicTemplatesAsync(model.AvailableTopicTemplates, false); //prepare model customer roles await _aclSupportedModelFactory.PrepareModelCustomerRolesAsync(model, topic, excludeProperties); //prepare model stores await _storeMappingSupportedModelFactory.PrepareModelStoresAsync(model, topic, excludeProperties); return(model); }
/// <summary> /// Prepare paged message template list model /// </summary> /// <param name="searchModel">Message template search model</param> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the message template list model /// </returns> public virtual async Task <MessageTemplateListModel> PrepareMessageTemplateListModelAsync(MessageTemplateSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //get message templates var messageTemplates = (await _messageTemplateService .GetAllMessageTemplatesAsync(storeId: searchModel.SearchStoreId)).ToPagedList(searchModel); //prepare store names (to avoid loading for each message template) var stores = (await _storeService.GetAllStoresAsync()).Select(store => new { store.Id, store.Name }).ToList(); //prepare list model var model = await new MessageTemplateListModel().PrepareToGridAsync(searchModel, messageTemplates, () => { return(messageTemplates.SelectAwait(async messageTemplate => { //fill in model values from the entity var messageTemplateModel = messageTemplate.ToModel <MessageTemplateModel>(); //fill in additional values (not existing in the entity) var storeNames = stores.Select(store => store.Name); if (messageTemplate.LimitedToStores) { await _storeMappingSupportedModelFactory.PrepareModelStoresAsync(messageTemplateModel, messageTemplate, false); storeNames = stores .Where(store => messageTemplateModel.SelectedStoreIds.Contains(store.Id)).Select(store => store.Name); } messageTemplateModel.ListOfStores = string.Join(", ", storeNames); return messageTemplateModel; })); }); return(model); }
/// <summary> /// Prepare checkout attribute model /// </summary> /// <param name="model">Checkout attribute model</param> /// <param name="checkoutAttribute">Checkout attribute</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the checkout attribute model /// </returns> public virtual async Task <CheckoutAttributeModel> PrepareCheckoutAttributeModelAsync(CheckoutAttributeModel model, CheckoutAttribute checkoutAttribute, bool excludeProperties = false) { Func <CheckoutAttributeLocalizedModel, int, Task> localizedModelConfiguration = null; if (checkoutAttribute != null) { //fill in model values from the entity model ??= checkoutAttribute.ToModel <CheckoutAttributeModel>(); //prepare nested search model PrepareCheckoutAttributeValueSearchModel(model.CheckoutAttributeValueSearchModel, checkoutAttribute); //define localized model configuration action localizedModelConfiguration = async(locale, languageId) => { locale.Name = await _localizationService.GetLocalizedAsync(checkoutAttribute, entity => entity.Name, languageId, false, false); locale.TextPrompt = await _localizationService.GetLocalizedAsync(checkoutAttribute, entity => entity.TextPrompt, languageId, false, false); locale.DefaultValue = await _localizationService.GetLocalizedAsync(checkoutAttribute, entity => entity.DefaultValue, languageId, false, false); }; //whether to fill in some of properties if (!excludeProperties) { model.TaxCategoryId = checkoutAttribute.TaxCategoryId; } //prepare condition attributes model await PrepareConditionAttributesModelAsync(model.ConditionModel, checkoutAttribute); } //currently any checkout attribute can have condition model.ConditionAllowed = true; //prepare localized models if (!excludeProperties) { model.Locales = await _localizedModelFactory.PrepareLocalizedModelsAsync(localizedModelConfiguration); } //prepare available tax categories await _baseAdminModelFactory.PrepareTaxCategoriesAsync(model.AvailableTaxCategories); //prepare model stores await _storeMappingSupportedModelFactory.PrepareModelStoresAsync(model, checkoutAttribute, excludeProperties); return(model); }
/// <summary> /// Prepare blog post model /// </summary> /// <param name="model">Blog post model</param> /// <param name="blogPost">Blog post</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the blog post model /// </returns> public virtual async Task <BlogPostModel> PrepareBlogPostModelAsync(BlogPostModel model, BlogPost blogPost, bool excludeProperties = false) { //fill in model values from the entity if (blogPost != null) { if (model == null) { model = blogPost.ToModel <BlogPostModel>(); model.SeName = await _urlRecordService.GetSeNameAsync(blogPost, blogPost.LanguageId, true, false); } model.StartDateUtc = blogPost.StartDateUtc; model.EndDateUtc = blogPost.EndDateUtc; } //set default values for the new model if (blogPost == null) { model.AllowComments = true; model.IncludeInSitemap = true; } var blogTags = await _blogService.GetAllBlogPostTagsAsync(0, 0, true); var blogTagsSb = new StringBuilder(); blogTagsSb.Append("var initialBlogTags = ["); for (var i = 0; i < blogTags.Count; i++) { var tag = blogTags[i]; blogTagsSb.Append("'"); blogTagsSb.Append(JavaScriptEncoder.Default.Encode(tag.Name)); blogTagsSb.Append("'"); if (i != blogTags.Count - 1) { blogTagsSb.Append(","); } } blogTagsSb.Append("]"); model.InitialBlogTags = blogTagsSb.ToString(); //prepare available languages await _baseAdminModelFactory.PrepareLanguagesAsync(model.AvailableLanguages, false); //prepare available stores await _storeMappingSupportedModelFactory.PrepareModelStoresAsync(model, blogPost, excludeProperties); return(model); }
/// <summary> /// Prepare country model /// </summary> /// <param name="model">Country model</param> /// <param name="country">Country</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the country model /// </returns> public virtual async Task <CountryModel> PrepareCountryModelAsync(CountryModel model, Country country, bool excludeProperties = false) { Func <CountryLocalizedModel, int, Task> localizedModelConfiguration = null; if (country != null) { //fill in model values from the entity if (model == null) { model = country.ToModel <CountryModel>(); model.NumberOfStates = (await _stateProvinceService.GetStateProvincesByCountryIdAsync(country.Id))?.Count ?? 0; } //prepare nested search model PrepareStateProvinceSearchModel(model.StateProvinceSearchModel, country); //define localized model configuration action localizedModelConfiguration = async(locale, languageId) => { locale.Name = await _localizationService.GetLocalizedAsync(country, entity => entity.Name, languageId, false, false); }; } //set default values for the new model if (country == null) { model.Published = true; model.AllowsBilling = true; model.AllowsShipping = true; } //prepare localized models if (!excludeProperties) { model.Locales = await _localizedModelFactory.PrepareLocalizedModelsAsync(localizedModelConfiguration); } //prepare available stores await _storeMappingSupportedModelFactory.PrepareModelStoresAsync(model, country, excludeProperties); return(model); }
/// <summary> /// Prepare plugin model /// </summary> /// <param name="model">Plugin model</param> /// <param name="pluginDescriptor">Plugin descriptor</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the plugin model /// </returns> public virtual async Task <PluginModel> PreparePluginModelAsync(PluginModel model, PluginDescriptor pluginDescriptor, bool excludeProperties = false) { Func <PluginLocalizedModel, int, Task> localizedModelConfiguration = null; if (pluginDescriptor != null) { //fill in model values from the entity model ??= pluginDescriptor.ToPluginModel(model); model.LogoUrl = await _pluginService.GetPluginLogoUrlAsync(pluginDescriptor); model.SelectedStoreIds = pluginDescriptor.LimitedToStores; model.SelectedCustomerRoleIds = pluginDescriptor.LimitedToCustomerRoles; var plugin = pluginDescriptor.Instance <IPlugin>(); if (pluginDescriptor.Installed) { PrepareInstalledPluginModel(model, plugin); } //define localized model configuration action localizedModelConfiguration = async(locale, languageId) => { locale.FriendlyName = await _localizationService.GetLocalizedFriendlyNameAsync(plugin, languageId, false); }; } //prepare localized models if (!excludeProperties) { model.Locales = await _localizedModelFactory.PrepareLocalizedModelsAsync(localizedModelConfiguration); } //prepare model customer roles await _aclSupportedModelFactory.PrepareModelCustomerRolesAsync(model); //prepare available stores await _storeMappingSupportedModelFactory.PrepareModelStoresAsync(model); return(model); }
/// <summary> /// Prepare currency model /// </summary> /// <param name="model">Currency model</param> /// <param name="currency">Currency</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns>Currency model</returns> public virtual async Task <CurrencyModel> PrepareCurrencyModelAsync(CurrencyModel model, Currency currency, bool excludeProperties = false) { Action <CurrencyLocalizedModel, int> localizedModelConfiguration = null; if (currency != null) { //fill in model values from the entity model ??= currency.ToModel <CurrencyModel>(); //convert dates to the user time model.CreatedOn = await _dateTimeHelper.ConvertToUserTimeAsync(currency.CreatedOnUtc, DateTimeKind.Utc); //define localized model configuration action localizedModelConfiguration = async(locale, languageId) => { locale.Name = await _localizationService.GetLocalizedAsync(currency, entity => entity.Name, languageId, false, false); }; } //set default values for the new model if (currency == null) { model.Published = true; model.Rate = 1; } //prepare localized models if (!excludeProperties) { model.Locales = await _localizedModelFactory.PrepareLocalizedModelsAsync(localizedModelConfiguration); } //prepare available stores await _storeMappingSupportedModelFactory.PrepareModelStoresAsync(model, currency, excludeProperties); return(model); }
/// <summary> /// Prepare manufacturer model /// </summary> /// <param name="model">Manufacturer model</param> /// <param name="manufacturer">Manufacturer</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns>Manufacturer model</returns> public virtual async Task <ManufacturerModel> PrepareManufacturerModelAsync(ManufacturerModel model, Manufacturer manufacturer, bool excludeProperties = false) { Action <ManufacturerLocalizedModel, int> localizedModelConfiguration = null; if (manufacturer != null) { //fill in model values from the entity if (model == null) { model = manufacturer.ToModel <ManufacturerModel>(); model.SeName = await _urlRecordService.GetSeNameAsync(manufacturer, 0, true, false); } //prepare nested search model PrepareManufacturerProductSearchModel(model.ManufacturerProductSearchModel, manufacturer); //define localized model configuration action localizedModelConfiguration = async(locale, languageId) => { locale.Name = await _localizationService.GetLocalizedAsync(manufacturer, entity => entity.Name, languageId, false, false); locale.Description = await _localizationService.GetLocalizedAsync(manufacturer, entity => entity.Description, languageId, false, false); locale.MetaKeywords = await _localizationService.GetLocalizedAsync(manufacturer, entity => entity.MetaKeywords, languageId, false, false); locale.MetaDescription = await _localizationService.GetLocalizedAsync(manufacturer, entity => entity.MetaDescription, languageId, false, false); locale.MetaTitle = await _localizationService.GetLocalizedAsync(manufacturer, entity => entity.MetaTitle, languageId, false, false); locale.SeName = await _urlRecordService.GetSeNameAsync(manufacturer, languageId, false, false); }; } //set default values for the new model if (manufacturer == null) { model.PageSize = _catalogSettings.DefaultManufacturerPageSize; model.PageSizeOptions = _catalogSettings.DefaultManufacturerPageSizeOptions; model.Published = true; model.AllowCustomersToSelectPageSize = true; } //prepare localized models if (!excludeProperties) { model.Locales = await _localizedModelFactory.PrepareLocalizedModelsAsync(localizedModelConfiguration); } //prepare available manufacturer templates await _baseAdminModelFactory.PrepareManufacturerTemplatesAsync(model.AvailableManufacturerTemplates, false); //prepare model discounts var availableDiscounts = await _discountService.GetAllDiscountsAsync(DiscountType.AssignedToManufacturers, showHidden : true); await _discountSupportedModelFactory.PrepareModelDiscountsAsync(model, manufacturer, availableDiscounts, excludeProperties); //prepare model customer roles await _aclSupportedModelFactory.PrepareModelCustomerRolesAsync(model, manufacturer, excludeProperties); //prepare model stores await _storeMappingSupportedModelFactory.PrepareModelStoresAsync(model, manufacturer, excludeProperties); return(model); }
/// <summary> /// Prepare category model /// </summary> /// <param name="model">Category model</param> /// <param name="category">Category</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the category model /// </returns> public virtual async Task <CategoryModel> PrepareCategoryModelAsync(CategoryModel model, Category category, bool excludeProperties = false) { Func <CategoryLocalizedModel, int, Task> localizedModelConfiguration = null; if (category != null) { //fill in model values from the entity if (model == null) { model = category.ToModel <CategoryModel>(); model.SeName = await _urlRecordService.GetSeNameAsync(category, 0, true, false); } //prepare nested search model PrepareCategoryProductSearchModel(model.CategoryProductSearchModel, category); //define localized model configuration action localizedModelConfiguration = async(locale, languageId) => { locale.Name = await _localizationService.GetLocalizedAsync(category, entity => entity.Name, languageId, false, false); locale.Description = await _localizationService.GetLocalizedAsync(category, entity => entity.Description, languageId, false, false); locale.MetaKeywords = await _localizationService.GetLocalizedAsync(category, entity => entity.MetaKeywords, languageId, false, false); locale.MetaDescription = await _localizationService.GetLocalizedAsync(category, entity => entity.MetaDescription, languageId, false, false); locale.MetaTitle = await _localizationService.GetLocalizedAsync(category, entity => entity.MetaTitle, languageId, false, false); locale.SeName = await _urlRecordService.GetSeNameAsync(category, languageId, false, false); }; } //set default values for the new model if (category == null) { model.PageSize = _catalogSettings.DefaultCategoryPageSize; model.PageSizeOptions = _catalogSettings.DefaultCategoryPageSizeOptions; model.Published = true; model.IncludeInTopMenu = true; model.AllowCustomersToSelectPageSize = true; model.PriceRangeFiltering = true; model.ManuallyPriceRange = true; model.PriceFrom = NopCatalogDefaults.DefaultPriceRangeFrom; model.PriceTo = NopCatalogDefaults.DefaultPriceRangeTo; } model.PrimaryStoreCurrencyCode = (await _currencyService.GetCurrencyByIdAsync(_currencySettings.PrimaryStoreCurrencyId)).CurrencyCode; //prepare localized models if (!excludeProperties) { model.Locales = await _localizedModelFactory.PrepareLocalizedModelsAsync(localizedModelConfiguration); } //prepare available category templates await _baseAdminModelFactory.PrepareCategoryTemplatesAsync(model.AvailableCategoryTemplates, false); //prepare available parent categories await _baseAdminModelFactory.PrepareCategoriesAsync(model.AvailableCategories, defaultItemText : await _localizationService.GetResourceAsync("Admin.Catalog.Categories.Fields.Parent.None")); //prepare model discounts var availableDiscounts = await _discountService.GetAllDiscountsAsync(DiscountType.AssignedToCategories, showHidden : true); await _discountSupportedModelFactory.PrepareModelDiscountsAsync(model, category, availableDiscounts, excludeProperties); //prepare model customer roles await _aclSupportedModelFactory.PrepareModelCustomerRolesAsync(model, category, excludeProperties); //prepare model stores await _storeMappingSupportedModelFactory.PrepareModelStoresAsync(model, category, excludeProperties); return(model); }