/// <summary> /// Prepare store model /// </summary> /// <param name="model">Store model</param> /// <param name="store">Store</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 store model /// </returns> public virtual async Task <StoreModel> PrepareStoreModelAsync(StoreModel model, Store store, bool excludeProperties = false) { Action <StoreLocalizedModel, int> localizedModelConfiguration = null; if (store != null) { //fill in model values from the entity model ??= store.ToModel <StoreModel>(); //define localized model configuration action localizedModelConfiguration = async(locale, languageId) => { locale.Name = await _localizationService.GetLocalizedAsync(store, entity => entity.Name, languageId, false, false); }; } //prepare available languages await _baseAdminModelFactory.PrepareLanguagesAsync(model.AvailableLanguages, defaultItemText : await _localizationService.GetResourceAsync("Admin.Common.EmptyItemText")); //prepare localized models if (!excludeProperties) { model.Locales = await _localizedModelFactory.PrepareLocalizedModelsAsync(localizedModelConfiguration); } 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 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 URL record search model /// </summary> /// <param name="searchModel">URL record search model</param> /// <returns>URL record search model</returns> public virtual async Task <UrlRecordSearchModel> PrepareUrlRecordSearchModelAsync(UrlRecordSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //prepare available languages //we insert 0 as 'Standard' language. //let's insert -1 for 'All' language selection. await _baseAdminModelFactory.PrepareLanguagesAsync(searchModel.AvailableLanguages, defaultItemText : await _localizationService.GetResourceAsync("Admin.System.SeNames.List.Language.Standard")); searchModel.AvailableLanguages.Insert(0, new SelectListItem { Text = await _localizationService.GetResourceAsync("Admin.Common.All"), Value = "-1" }); searchModel.LanguageId = -1; //prepare "is active" filter (0 - all; 1 - active only; 2 - inactive only) searchModel.AvailableActiveOptions.Add(new SelectListItem { Value = "0", Text = await _localizationService.GetResourceAsync("Admin.System.SeNames.List.IsActive.All") }); searchModel.AvailableActiveOptions.Add(new SelectListItem { Value = "1", Text = await _localizationService.GetResourceAsync("Admin.System.SeNames.List.IsActive.ActiveOnly") }); searchModel.AvailableActiveOptions.Add(new SelectListItem { Value = "2", Text = await _localizationService.GetResourceAsync("Admin.System.SeNames.List.IsActive.InactiveOnly") }); //prepare page parameters searchModel.SetGridPageSize(); return(searchModel); }