private HtmlContentWidget GetHtmlContentWidgetFromRequest(EditHtmlContentWidgetViewModel request) { HtmlContentWidget content = new HtmlContentWidget(); content.Id = request.Id; if (request.CategoryId.HasValue && !request.CategoryId.Value.HasDefaultValue()) { content.Category = Repository.AsProxy <CategoryEntity>(request.CategoryId.Value); } else { content.Category = null; } if (request.Options != null) { content.ContentOptions = new List <ContentOption>(); // NOTE: Loading custom options before saving. // In other case, when loading custom options from option service, nHibernate updates version number (nHibernate bug) var customOptionsIdentifiers = request.Options .Where(o => o.Type == OptionType.Custom) .Select(o => o.CustomOption.Identifier) .Distinct() .ToArray(); var customOptions = OptionService.GetCustomOptionsById(customOptionsIdentifiers); foreach (var requestContentOption in request.Options) { var contentOption = new ContentOption { Content = content, Key = requestContentOption.OptionKey, DefaultValue = OptionService.ClearFixValueForSave(requestContentOption.OptionKey, requestContentOption.Type, requestContentOption.OptionDefaultValue), Type = requestContentOption.Type, CustomOption = requestContentOption.Type == OptionType.Custom ? customOptions.First(o => o.Identifier == requestContentOption.CustomOption.Identifier) : null }; OptionService.ValidateOptionValue(contentOption); content.ContentOptions.Add(contentOption); } } content.Name = request.Name; content.Html = request.PageContent ?? string.Empty; content.UseHtml = request.EnableCustomHtml; content.UseCustomCss = request.EnableCustomCSS; content.CustomCss = request.CustomCSS; content.UseCustomJs = request.EnableCustomJS; content.CustomJs = request.CustomJS; content.Version = request.Version; content.EditInSourceMode = request.EditInSourceMode; return(content); }
private void SetWidgetOptions(EditWidgetViewModel model, Widget content, bool treatNullsAsLists, bool isNew) { if (model.Options != null) { content.ContentOptions = new List <ContentOption>(); // NOTE: Loading custom options before saving. // In other case, when loading custom options from option service, nHibernate updates version number (nHibernate bug) var customOptionsIdentifiers = model.Options.Where(o => o.Type == OptionType.Custom).Select(o => o.CustomOption.Identifier).Distinct().ToArray(); var customOptions = optionService.GetCustomOptionsById(customOptionsIdentifiers); foreach (var requestContentOption in model.Options) { var contentOption = new ContentOption { Content = content, Key = requestContentOption.OptionKey, DefaultValue = optionService.ClearFixValueForSave( requestContentOption.OptionKey, requestContentOption.Type, requestContentOption.OptionDefaultValue), Type = requestContentOption.Type, CustomOption = requestContentOption.Type == OptionType.Custom ? repository.AsProxy <CustomOption>(customOptions.First(o => o.Identifier == requestContentOption.CustomOption.Identifier).Id) : null }; optionService.ValidateOptionValue(contentOption); if (cmsConfiguration.EnableMultilanguage && requestContentOption.Translations != null) { var translations = requestContentOption.Translations.Select(x => new ContentOptionTranslation { ContentOption = contentOption, Language = repository.AsProxy <Language>(x.LanguageId.ToGuidOrDefault()), Value = optionService.ClearFixValueForSave(requestContentOption.OptionKey, requestContentOption.Type, x.OptionValue) }).ToList(); foreach (var translation in translations) { optionService.ValidateOptionValue(contentOption.Key, translation.Value, contentOption.Type, contentOption.CustomOption); } contentOption.Translations = translations; } content.ContentOptions.Add(contentOption); } } else if (!treatNullsAsLists) { // When calling from API with null list, options should be loaded before process // Null from API means, that list should be kept unchanged content.ContentOptions = repository .AsQueryable <ContentOption>(pco => pco.Content.Id == model.Id) .Fetch(pco => pco.CustomOption) .ToList(); } }
protected override SavePageContentModel GetCreateModel(ISession session) { var content = TestDataProvider.CreateNewHtmlContent(20); var region = TestDataProvider.CreateNewRegion(); var contentOption = new ContentOption { Content = content, DefaultValue = TestDataProvider.ProvideRandomString(100), Key = TestDataProvider.ProvideRandomString(100), Type = BetterCms.Core.DataContracts.Enums.OptionType.Text }; session.SaveOrUpdate(content); session.SaveOrUpdate(region); session.SaveOrUpdate(contentOption); var model = new SavePageContentModel { Order = 100, ContentId = content.Id, RegionId = region.Id, }; if (setOptions) { model.Options = new List <OptionValueModel> { new OptionValueModel { DefaultValue = TestDataProvider.ProvideRandomString(100), Value = TestDataProvider.ProvideRandomString(100), Key = TestDataProvider.ProvideRandomString(100), Type = OptionType.Text, UseDefaultValue = false }, new OptionValueModel { DefaultValue = Guid.NewGuid().ToString(), Value = Guid.NewGuid().ToString(), Key = TestDataProvider.ProvideRandomString(100), Type = OptionType.Custom, CustomTypeIdentifier = MediaManagerFolderOptionProvider.Identifier, UseDefaultValue = false }, new OptionValueModel { DefaultValue = contentOption.DefaultValue, Value = TestDataProvider.ProvideRandomString(100), Key = contentOption.Key, Type = (OptionType)(int)contentOption.Type, UseDefaultValue = true }, }; } return(model); }
private ServerControlWidget GetServerControlWidgetFromRequest(EditServerControlWidgetViewModel request) { ServerControlWidget widget = new ServerControlWidget(); widget.Id = request.Id; if (request.CategoryId.HasValue && !request.CategoryId.Value.HasDefaultValue()) { widget.Category = Repository.AsProxy <CategoryEntity>(request.CategoryId.Value); } else { widget.Category = null; } widget.Name = request.Name; widget.Url = request.Url; widget.Version = request.Version; widget.PreviewUrl = request.PreviewImageUrl; if (request.Options != null) { widget.ContentOptions = new List <ContentOption>(); // NOTE: Loading custom options before saving. // In other case, when loading custom options from option service, nHibernate updates version number (nHibernate bug) var customOptionsIdentifiers = request.Options .Where(o => o.Type == OptionType.Custom) .Select(o => o.CustomOption.Identifier) .Distinct() .ToArray(); var customOptions = OptionService.GetCustomOptionsById(customOptionsIdentifiers); foreach (var requestContentOption in request.Options) { var contentOption = new ContentOption { Content = widget, Key = requestContentOption.OptionKey, DefaultValue = OptionService.ClearFixValueForSave(requestContentOption.OptionKey, requestContentOption.Type, requestContentOption.OptionDefaultValue), Type = requestContentOption.Type, CustomOption = requestContentOption.Type == OptionType.Custom ? customOptions.First(o => o.Identifier == requestContentOption.CustomOption.Identifier) : null }; OptionService.ValidateOptionValue(contentOption); widget.ContentOptions.Add(contentOption); } } return(widget); }
public ContentOption CreateNewContentOption(Content content = null) { var entity = new ContentOption(); PopulateBaseFields(entity); entity.Key = ProvideRandomString(MaxLength.Name); entity.Content = content ?? CreateNewContent(); entity.Type = ProvideRandomEnumValue <OptionType>(); entity.DefaultValue = ProvideRandomString(100); return(entity); }
private IList <ChildContent> GetChildContents(Guid[] ids, bool canManageContent) { ChildContent ccAlias = null; ChildContentOption ccOptionAlias = null; Models.Content childAlias = null; ContentOption cOptionAlias = null; ContentRegion cRegionAlias = null; Region regionAlias = null; ChildContent ccAlias1 = null; Models.Content ccChildAlias = null; Models.Content historyAlias = null; ChildContent historyCcAlias = null; Models.Content historyChildAlias = null; var query = repository .AsQueryOver(() => ccAlias) .Where(Restrictions.In(NHibernate.Criterion.Projections.Property(() => ccAlias.Parent.Id), ids)) .And(() => !ccAlias.IsDeleted) .Inner.JoinAlias(() => ccAlias.Child, () => childAlias) .Where(() => !childAlias.IsDeleted) .Left.JoinAlias(() => childAlias.ContentOptions, () => cOptionAlias) .Left.JoinAlias(() => ccAlias.Options, () => ccOptionAlias) .Left.JoinAlias(() => childAlias.ContentRegions, () => cRegionAlias) .Left.JoinAlias(() => cRegionAlias.Region, () => regionAlias) .Left.JoinAlias(() => childAlias.ChildContents, () => ccAlias1) .Left.JoinAlias(() => ccAlias1.Child, () => ccChildAlias); if (canManageContent) { query = query .Left.JoinAlias(() => childAlias.History, () => historyAlias) .Left.JoinAlias(() => historyAlias.ChildContents, () => historyCcAlias) .Left.JoinAlias(() => historyCcAlias.Child, () => historyChildAlias); } return(query.List <ChildContent>()); }
/// <summary> /// Saves the server widget options. /// </summary> /// <param name="widget">The widget.</param> /// <param name="requestOptions">The request options.</param> /// <returns> List of saved widget options </returns> private IList <ContentOption> SaveServerWidgetOptions(ServerControlWidget widget, IList <ContentOptionDto> requestOptions) { var options = new List <ContentOption>(); if (requestOptions != null && requestOptions.Count > 0) { foreach (var requestOption in requestOptions) { var option = new ContentOption { Key = requestOption.Key, DefaultValue = requestOption.DefaultValue, Type = requestOption.Type, Content = widget }; options.Add(option); Repository.Save(option); } } return(options); }
private ServerControlWidget GetServerControlWidgetFromRequest(EditServerControlWidgetViewModel request) { ServerControlWidget widget = new ServerControlWidget(); widget.Id = request.Id; if (request.CategoryId.HasValue && !request.CategoryId.Value.HasDefaultValue()) { widget.Category = Repository.AsProxy <CategoryEntity>(request.CategoryId.Value); } else { widget.Category = null; } widget.Name = request.Name; widget.Url = request.Url; widget.Version = request.Version; widget.PreviewUrl = request.PreviewImageUrl; if (request.Options != null) { widget.ContentOptions = new List <ContentOption>(); foreach (var requestContentOption in request.Options) { var contentOption = new ContentOption { Content = widget, Key = requestContentOption.OptionKey, DefaultValue = requestContentOption.OptionDefaultValue, Type = requestContentOption.Type }; OptionService.ValidateOptionValue(contentOption); widget.ContentOptions.Add(contentOption); } } return(widget); }
/// <summary> /// Executes the specified request. /// </summary> /// <param name="pageContentId">The page content id.</param> /// <returns></returns> public PageContentOptionsViewModel Execute(Guid pageContentId) { IList <PageContentOptionViewModel> options = null; if (!pageContentId.HasDefaultValue()) { var pageContent = Repository.AsQueryable <PageContent>() .Where(f => f.Id == pageContentId && !f.IsDeleted && !f.Content.IsDeleted) .Fetch(f => f.Content).ThenFetchMany(f => f.ContentOptions) .FetchMany(f => f.Options) .ToList() .FirstOrDefault(); if (pageContent != null) { options = new List <PageContentOptionViewModel>(); if (pageContent.Options != null) { foreach (var pageContentOption in pageContent.Options.Distinct()) { ContentOption contentOption = null; if (pageContent.Content.ContentOptions != null) { contentOption = pageContent.Content.ContentOptions.FirstOrDefault(f => f.Key.Trim().Equals(pageContentOption.Key.Trim(), StringComparison.OrdinalIgnoreCase)); } options.Add(new PageContentOptionViewModel { Type = pageContentOption.Type, OptionKey = pageContentOption.Key.Trim(), OptionValue = pageContentOption.Value, OptionDefaultValue = contentOption != null ? contentOption.DefaultValue : null }); } } if (pageContent.Content.ContentOptions != null) { foreach (var contentOption in pageContent.Content.ContentOptions.Distinct()) { if (!options.Any(f => f.OptionKey.Equals(contentOption.Key.Trim(), StringComparison.OrdinalIgnoreCase))) { options.Add(new PageContentOptionViewModel { Type = contentOption.Type, OptionKey = contentOption.Key.Trim(), OptionValue = null, OptionDefaultValue = contentOption.DefaultValue }); } } } } } if (options == null) { options = new List <PageContentOptionViewModel>(); } return(new PageContentOptionsViewModel { WidgetOptions = options.OrderBy(o => o.OptionKey).ToList(), PageContentId = pageContentId }); }
/// <summary> /// Saves the server widget options. /// </summary> /// <param name="widget">The widget.</param> /// <param name="requestOptions">The request options.</param> /// <returns> List of saved widget options </returns> private IList<ContentOption> SaveServerWidgetOptions(ServerControlWidget widget, IList<ContentOptionDto> requestOptions) { var options = new List<ContentOption>(); if (requestOptions != null && requestOptions.Count > 0) { foreach (var requestOption in requestOptions) { var option = new ContentOption { Key = requestOption.Key, DefaultValue = requestOption.DefaultValue, Type = requestOption.Type, Content = widget }; options.Add(option); Repository.Save(option); } } return options; }