/// <summary> /// Executes the specified request. /// </summary> /// <param name="pageContentId">The page content id.</param> /// <returns></returns> public ContentOptionValuesViewModel Execute(Guid pageContentId) { var model = new ContentOptionValuesViewModel { OptionValuesContainerId = pageContentId }; if (!pageContentId.HasDefaultValue()) { var contentQuery = Repository.AsQueryable <PageContent>() .Where(f => f.Id == pageContentId && !f.IsDeleted && !f.Content.IsDeleted); IEnumerable <AccessRule> accessRules = new List <AccessRule>(); if (CmsConfiguration.Security.AccessControlEnabled) { accessRules = contentQuery.SelectMany(t => t.Page.AccessRules).ToFuture(); } var contentHistory = contentQuery.SelectMany(t => t.Content.History).ToFuture(); var contentOptions = contentQuery.SelectMany(t => t.Content.ContentOptions).ToFuture(); var pageOptions = contentQuery.SelectMany(t => t.Options).ToFuture(); contentQuery = contentQuery.Fetch(t => t.Content).FetchMany(t => t.Options).ThenFetch(t => t.CustomOption); var pageContent = contentQuery.ToFuture().FirstOrDefault(); if (pageContent != null) { pageContent.Content.History = contentHistory.ToList(); pageContent.Content.ContentOptions = contentOptions.ToList(); pageContent.Options = pageOptions.ToList(); var contentToProject = pageContent.Content; if (contentToProject.Status != ContentStatus.Draft) { var draftContent = contentToProject.History.FirstOrDefault(c => c.Status == ContentStatus.Draft); if (draftContent != null) { contentToProject = draftContent; } } model.OptionValues = OptionService.GetMergedOptionValuesForEdit(contentToProject.ContentOptions, pageContent.Options); model.CustomOptions = OptionService.GetCustomOptions(); if (CmsConfiguration.Security.AccessControlEnabled) { SetIsReadOnly(model, accessRules.Cast <IAccessRule>().ToList()); } if (CmsConfiguration.EnableMultilanguage) { var pageLanguage = Repository.AsQueryable <Root.Models.Page>().Where(p => p.Id == pageContent.Page.Id).Select(x => x.Language).FirstOrDefault(); if (pageLanguage != null) { SetTranslatedDefaultOptionValues(model.OptionValues, pageLanguage.Id); } } } } return(model); }
/// <summary> /// Executes the specified request. /// </summary> /// <param name="pageContentId">The page content id.</param> /// <returns></returns> public ContentOptionValuesViewModel Execute(Guid pageContentId) { var model = new ContentOptionValuesViewModel { OptionValuesContainerId = pageContentId }; if (!pageContentId.HasDefaultValue()) { var contentQuery = Repository.AsQueryable <PageContent>() .Where(f => f.Id == pageContentId && !f.IsDeleted && !f.Content.IsDeleted) .Fetch(f => f.Content).ThenFetchMany(f => f.ContentOptions).ThenFetch(f => f.CustomOption) .Fetch(f => f.Content).ThenFetchMany(f => f.History).ThenFetchMany(f => f.ContentOptions).ThenFetch(f => f.CustomOption) .FetchMany(f => f.Options).ThenFetch(f => f.CustomOption) .AsQueryable(); if (CmsConfiguration.Security.AccessControlEnabled) { contentQuery = contentQuery.Fetch(f => f.Page).ThenFetchMany(f => f.AccessRules); } var pageContent = contentQuery.ToList().FirstOrDefault(); if (pageContent != null) { var contentToProject = pageContent.Content; if (contentToProject.Status != ContentStatus.Draft) { var draftContent = contentToProject.History.FirstOrDefault(c => c.Status == ContentStatus.Draft); if (draftContent != null) { contentToProject = draftContent; } } model.OptionValues = OptionService.GetMergedOptionValuesForEdit(contentToProject.ContentOptions, pageContent.Options); model.CustomOptions = OptionService.GetCustomOptions(); if (CmsConfiguration.Security.AccessControlEnabled) { SetIsReadOnly(model, pageContent.Page.AccessRules.Cast <IAccessRule>().ToList()); } } } return(model); }
/// <summary> /// Executes the specified request. /// </summary> /// <param name="pageContentId">The page content id.</param> /// <returns></returns> public PageContentOptionsViewModel Execute(Guid pageContentId) { var model = new PageContentOptionsViewModel { PageContentId = pageContentId }; if (!pageContentId.HasDefaultValue()) { var contentQuery = Repository.AsQueryable<PageContent>() .Where(f => f.Id == pageContentId && !f.IsDeleted && !f.Content.IsDeleted) .Fetch(f => f.Content).ThenFetchMany(f => f.ContentOptions).ThenFetch(f => f.CustomOption) .FetchMany(f => f.Options).ThenFetch(f => f.CustomOption) .AsQueryable(); if (CmsConfiguration.Security.AccessControlEnabled) { contentQuery = contentQuery.Fetch(f => f.Page).ThenFetchMany(f => f.AccessRules); } var pageContent = contentQuery.ToList().FirstOrDefault(); if (pageContent != null) { model.OptionValues = OptionService.GetMergedOptionValuesForEdit(pageContent.Content.ContentOptions, pageContent.Options); model.CustomOptions = OptionService.GetCustomOptions(); if (CmsConfiguration.Security.AccessControlEnabled) { SetIsReadOnly(model, pageContent.Page.AccessRules.Cast<IAccessRule>().ToList()); } } } return model; }
/// <summary> /// Executes the specified request. /// </summary> /// <param name="request">The request.</param> /// <returns></returns> public ContentOptionValuesViewModel Execute(GetChildContentOptionsCommandRequest request) { if (request.WidgetId.HasDefaultValue() && request.AssignmentIdentifier.HasDefaultValue()) { var message = "WidgetId and AssignmentId should be set"; throw new ValidationException(() => message, message); } var model = new ContentOptionValuesViewModel(); var optionsLoaded = false; var languagesFuture = CmsConfiguration.EnableMultilanguage ? LanguageService.GetLanguagesLookupValues() : new List <LookupKeyValue>(); if (request.LoadOptions) { if (!request.AssignmentIdentifier.HasDefaultValue()) { // Try get draft var draftQuery = Repository.AsQueryable <ChildContent>() .Where(f => f.Parent.Original.Id == request.ContentId && !f.Parent.Original.IsDeleted && f.Parent.Original.Status == ContentStatus.Published && f.Parent.Status == ContentStatus.Draft && !f.Parent.IsDeleted && f.AssignmentIdentifier == request.AssignmentIdentifier && !f.IsDeleted && !f.Child.IsDeleted); var childContent = draftQuery.FirstOrDefault(); // If draft not found, load content if (childContent == null) { var query = Repository.AsQueryable <ChildContent>().Where( f => f.Parent.Id == request.ContentId && f.AssignmentIdentifier == request.AssignmentIdentifier && !f.IsDeleted && !f.Child.IsDeleted); childContent = query.FirstOrDefault(); FetchCollections(childContent); } else { FetchCollections(childContent); } if (childContent != null) { var content = GetDraftIfExists(childContent.Child); model.OptionValuesContainerId = childContent.Id; model.OptionValues = OptionService.GetMergedOptionValuesForEdit(content.ContentOptions, childContent.Options); optionsLoaded = true; } } if (!optionsLoaded) { var content = Repository.AsQueryable <Root.Models.Content>() .Where(c => c.Id == request.WidgetId) .FetchMany(c => c.ContentOptions) .ThenFetch(c => c.CustomOption) .FetchMany(f => f.History).ThenFetchMany(f => f.ContentOptions).ThenFetch(f => f.CustomOption) .ToList() .FirstOne(); content = GetDraftIfExists(content); model.OptionValues = OptionService.GetMergedOptionValuesForEdit(content.ContentOptions, null); } } model.CustomOptions = OptionService.GetCustomOptions(); var languages = CmsConfiguration.EnableMultilanguage ? languagesFuture.ToList() : new List <LookupKeyValue>(); model.Languages = languages; model.ShowLanguages = CmsConfiguration.EnableMultilanguage && languages.Any(); return(model); }