private static Dictionary <string, ContentItemModel> Initialize() { var predefinedDictionary = predefined.ToDictionary(item => item.Link, item => item, StringComparer.OrdinalIgnoreCase); string path = Path.Combine(Directory.GetCurrentDirectory(), "ClientApp", "build", "static", "images"); DirectoryInfo dir = new DirectoryInfo(path); if (dir.Exists == false) { dir.Create(); } foreach (FileInfo file in dir.EnumerateFiles()) { string link = GetLinkFromFileName(file.Name); predefinedDictionary[link] = new ContentItemModel { Id = Guid.NewGuid().ToString(), Link = link, Type = "image" }; } return(predefinedDictionary); }
public async Task <bool> FindAndUpdateAsync(ContentItemModel contentItemModel, Uri url) { _ = contentItemModel ?? throw new ArgumentNullException(nameof(contentItemModel)); var cmsApiModel = await cmsApiService.GetContentItemAsync <T>(url).ConfigureAwait(false); if (cmsApiModel != null) { switch (contentItemModel.ContentType.ToLower()) { case Constants.ContentTypeHtml: if (cmsApiModel is CmsApiHtmlModel cmsApiHtmlModel) { contentItemModel.Title = cmsApiHtmlModel.Title; contentItemModel.Content = cmsApiHtmlModel.Content; contentItemModel.HtmlBody = cmsApiHtmlModel.HtmlBody; } break; case Constants.ContentTypeHtmlShared: if (cmsApiModel is CmsApiHtmlSharedModel cmsApiHtmlSharedModel) { contentItemModel.Title = cmsApiHtmlSharedModel.Title; contentItemModel.Content = cmsApiHtmlSharedModel.Content; contentItemModel.HtmlBody = cmsApiHtmlSharedModel.HtmlBody; } break; case Constants.ContentTypeSharedContent: if (cmsApiModel is CmsApiSharedContentModel cmsApiSharedContentModel) { contentItemModel.Title = cmsApiSharedContentModel.Title; contentItemModel.Content = cmsApiSharedContentModel.Content; contentItemModel.HtmlBody = cmsApiSharedContentModel.HtmlBody; } break; case Constants.ContentTypeForm: if (cmsApiModel is CmsApiFormModel cmsApiFormModel) { contentItemModel.Action = cmsApiFormModel.Action; contentItemModel.EnableAntiForgeryToken = cmsApiFormModel.EnableAntiForgeryToken; contentItemModel.Method = cmsApiFormModel.Method; contentItemModel.EncType = cmsApiFormModel.EncType; } break; } contentItemModel.LastCached = DateTime.UtcNow; return(true); } return(false); }
public ActionResult Create() { ContentItemModel itemModel = new ContentItemModel() { IsActive = true, Mode = ViewModelMode.Creation }; return base.View("CreateOrUpdate", itemModel); }
// pass in a list of strings representing an item's filter properties // return true if the checkbox matching those filter properties is checked // return false is none of the checkboxes for that item's properties are checked public bool FilterContent(ContentItemModel item) { if (!item.FilterProperties.ContainsKey(ID)) { return(false); } return(Options .Where(o => item.FilterProperties[ID].Contains(o.Filter, StringComparer.OrdinalIgnoreCase)) .Any(o => o.IsChecked)); }
protected static ContentItemModel BuildValidContentItemModel(Guid contentItemId, string?contentType = null) { var model = new ContentItemModel() { ItemId = contentItemId, LastReviewed = DateTime.Now, ContentType = contentType, }; return(model); }
private async Task <ContentItemModel> CreateUserItem(string name, string id) { var item = new ContentItemCreateModel { Name = name, Type = ContentTypeIdentifier.ByCodename("user"), ExternalId = id }; ContentItemModel responseItem = await managementClient.CreateContentItemAsync(item); return(responseItem); }
public ContentItem CreateContentItem(ContentItemModel itemModel) { var catalog = DomainRepositories.Catalog.FindByCode("c.languages"); var ci = new ContentItem() { Description = itemModel.Description, Keywords = itemModel.Keywords, IsActive = itemModel.IsActive, Name = itemModel.Name, Language = catalog.GetLineByCode(itemModel.Language), }; ci.AddLogCreation(); return ci; }
public ActionResult Create(ContentItemModel itemModel, FormCollection collection) { if (base.ModelState.IsValid) { var contentItem = this.contentModelsService.CreateContentItem(itemModel); bool result = this.contentItemRepository.Save(contentItem); if (result) { this.contentBonusService.CalculateTotalPoints(DomainSessionContext.Instance.CurrentUser); string id = contentItem.Id.ToString(); return base.RedirectToAction(ControllerAssistant.GetActionName(() => this.CreatePart(id)), ControllerAssistant.BuildRouteValues(id)); } } return base.View("CreateOrUpdate", itemModel); }
public async Task <bool> FindAndUpdateAsync(ContentItemModel contentItemModel, Uri url) { _ = contentItemModel ?? throw new ArgumentNullException(nameof(contentItemModel)); var cmsApiHtmlModel = await cmsApiService.GetContentItemAsync <T>(url).ConfigureAwait(false); if (cmsApiHtmlModel != null) { contentItemModel.Title = cmsApiHtmlModel.Title; contentItemModel.Content = cmsApiHtmlModel.Content; contentItemModel.HtmlBody = cmsApiHtmlModel.HtmlBody; contentItemModel.LastCached = DateTime.UtcNow; return(true); } return(false); }
public void Add(Dictionary <string, object> body) { string url = body["url"].ToString(); if (Items.ContainsKey(url)) { return; } Uri uri = new Uri(url); ContentItemModel itemModel = new ContentItemModel { Id = Guid.NewGuid().ToString(), Link = url, }; string host = uri.Host.Replace("www.", "").Replace("clips.", ""); string itemType; switch (host) { case "youtube.com": itemType = "youtube"; break; case "coub.com": itemType = "coub"; break; case "tiktok.com": itemType = "tiktok"; break; case "twitch.tv": itemType = "twitch"; break; default: itemType = "unsupported"; break; } itemModel.Type = itemType; Items[itemModel.Link] = itemModel; }
public void WebhooksServiceRemoveContentItemTestsReturnsSuccess() { // Arrange var contentItemId = Guid.NewGuid(); var expectedContentItemModel = new ContentItemModel { ItemId = contentItemId, }; var items = BuildContentItemSet(); var service = BuildWebhookContentProcessor(); items.First().ContentItems.First().ContentItems !.Add(expectedContentItemModel); // Act var result = service.RemoveContentItem(contentItemId, items); // Assert Assert.True(result); }
internal async Task <(ContentItemVariantModel <ConversationModel> variant, bool success)> SyncSingle(Conversation intercomConversation, ContentItemVariantModel <ConversationModel> conversationVariant, List <ContentItemVariantModel <UserModel> > conversationUserVariants) { currentConversationId = intercomConversation.id; currentConversationUsers = new List <UserModel>() { }; currentConversationUsers.AddRange(conversationUserVariants.Select(x => x.Elements)); ContentItemModel conversationItem = null; Guid itemIdentifier = Guid.Empty; // If conversation doesn't exist, create item for it if (conversationVariant == null) { try { logger.Debug("Creating item for conversation: " + currentConversationId); conversationItem = await CreateConversationItem(currentConversationId); itemIdentifier = conversationItem.Id; } catch (ContentManagementException e) { logger.Error(e, "Unable to create item for conversation: " + currentConversationId); return(null, false); } } else { itemIdentifier = conversationVariant.Item.Id; } // Fill model with data var model = CreateConversationModel(intercomConversation); logger.Debug("Creating item variant for conversation: " + currentConversationId); var variant = await UpsertConversationVariant(model, ContentItemIdentifier.ById(itemIdentifier)); var publishConversation = await PublishItemVariant(itemIdentifier.ToString()); return(variant, true); }
public async Task ContentItemUpdaterFindAndUpdateAsyncForFormReturnsSuccess() { // Arrange const bool expectedResult = true; var dummyCmsApiFormModel = A.Dummy <CmsApiFormModel>(); var contentItemModel = new ContentItemModel { ContentType = Constants.ContentTypeForm }; var url = new Uri("https://www.somewhere.com", UriKind.Absolute); var service = new MarkupContentItemUpdater <CmsApiFormModel>(fakeCmsApiService); A.CallTo(() => fakeCmsApiService.GetContentItemAsync <CmsApiFormModel>(A <Uri> .Ignored)).Returns(dummyCmsApiFormModel); // Act var result = await service.FindAndUpdateAsync(contentItemModel, url).ConfigureAwait(false); // Assert A.CallTo(() => fakeCmsApiService.GetContentItemAsync <CmsApiFormModel>(A <Uri> .Ignored)).MustHaveHappenedOnceExactly(); Assert.Equal(expectedResult, result !); }
public void AddImage([FromForm] IFormFile file) { string path = Path.Combine(Directory.GetCurrentDirectory(), "ClientApp", "build", "images", file.FileName); if (System.IO.File.Exists(path)) { return; } FileStream createStream = System.IO.File.Create(path); file.CopyTo(createStream); createStream.Close(); ContentItemModel itemModel = new ContentItemModel { Id = Guid.NewGuid().ToString(), Link = $"https://{this.Request.Host.Value}/images/{file.FileName}", Type = "image" }; Items[itemModel.Link] = itemModel; }
public ContentItemModel GetContentItemModel(ContentItem contentItem, bool filterActiveOnly) { var model = new ContentItemModel(); model.Initialize(contentItem, filterActiveOnly); return model; }
internal static async Task <ContentItemVariantModel> PrepareTestVariant(ContentManagementClient client, string languageCodename, object elements, ContentItemModel item) { var addedItemIdentifier = ContentItemIdentifier.ByCodename(item.CodeName); var addedLanguageIdentifier = LanguageIdentifier.ByCodename(languageCodename); var addedContentItemLanguageIdentifier = new ContentItemVariantIdentifier(addedItemIdentifier, addedLanguageIdentifier); var variantUpdateModel = new ContentItemVariantUpsertModel() { Elements = elements }; return(await client.UpsertContentItemVariantAsync(addedContentItemLanguageIdentifier, variantUpdateModel)); }
/// <summary> /// </summary> /// <param name="elements">The Elements property of the content item to be updated</param> /// <param name="codename">If set, the item with the specified code name will be upserted</param> static void UpsertSingleItem(Dictionary <string, object> elements, string codename, ContentType type, bool update) { ContentItemModel contentItem = null; ContentItem existingItem = null; Guid itemid; // Try to get existing content item for updating if (update && existingItem == null) { existingItem = GetExistingContentItem(codename, type.System.Codename); } // If not updating, create content item first if (!update) { contentItem = CreateNewContentItem(codename, type.System.Codename); if (contentItem.Id != null) { itemid = contentItem.Id; } else { throw new Exception("Error creating new item."); } } else { // We are updating existing if (existingItem != null) { itemid = new Guid(existingItem.System.Id); } else { // Existing item wasn't found, create it contentItem = CreateNewContentItem(codename, type.System.Codename); if (contentItem.Id != null) { itemid = contentItem.Id; } else { throw new Exception("Error creating new item."); } } } // After item is created (or skipped for updateExisting), upsert content try { // Get item variant to upsert ContentItemIdentifier itemIdentifier = ContentItemIdentifier.ById(itemid); LanguageIdentifier languageIdentifier = LanguageIdentifier.ById(new Guid("00000000-0000-0000-0000-000000000000")); ContentItemVariantIdentifier identifier = new ContentItemVariantIdentifier(itemIdentifier, languageIdentifier); elements = ValidateContentTypeFields(elements, type); // Set target element value ContentItemVariantUpsertModel model = new ContentItemVariantUpsertModel() { Elements = elements }; // Upsert item var upsertTask = clientCM.UpsertContentItemVariantAsync(identifier, model); var response = upsertTask.GetAwaiter().GetResult(); } catch (ContentManagementException e) { if (e.Message.ToLower().Contains("cannot update published")) { throw new Exception("This tool cannot currently update published content. If you wish to update a published item, you will first need to unpublish it within Kentico Kontent."); } } }
/// <summary> /// Updates the given content item. /// </summary> /// <param name="client">Content management client instance.</param> /// <param name="identifier">Identifies which content item will be updated. </param> /// <param name="contentItem">Specifies data for updated content item.</param> /// <returns>The <see cref="ContentItemModel"/> instance that represents updated content item.</returns> public async static Task <ContentItemModel> UpsertContentItemAsync(this IManagementClient client, Reference identifier, ContentItemModel contentItem) { if (identifier == null) { throw new ArgumentNullException(nameof(identifier)); } if (contentItem == null) { throw new ArgumentNullException(nameof(contentItem)); } var contentItemUpdateModel = new ContentItemUpsertModel { Name = contentItem.Name, Codename = contentItem.Codename, Collection = contentItem.Collection, ExternalId = contentItem.ExternalId, SitemapLocations = contentItem.SitemapLocations, Type = contentItem.Type }; return(await client.UpsertContentItemAsync(identifier, contentItemUpdateModel)); }
public ContentItemViewModel(ContentItemModel model, SelectionModel <ContentItemModel> selection) { _Model = model; _Selection = selection; }
private ContentPageModel LoadSpellInfo(string dataDir, Index_Json index) { var spells = JsonConvert.DeserializeObject <Spells_Json>( ReadFileFromIndex(Path.Combine(dataDir, index.spells))); var components = JsonConvert.DeserializeObject <Components_Json>( ReadFileFromIndex(Path.Combine(dataDir, index.spellComponents))); var classSpells = JsonConvert.DeserializeObject <ClassSpellListCollection_Json>( ReadFileFromIndex(Path.Combine(dataDir, index.classSpells))); ContentPageModel cpm = new ContentPageModel(_Compendium) { Header = "Spells" }; cpm.AddFilterGroup("level", "Filter by Level"); cpm.AddFilterGroup("class", "Filter by Class"); cpm.AddFilterGroup("school", "Filter by School"); cpm.AddFilterGroup("components", "Filter by Components"); cpm.AddFilterGroup("other", "Other Filters"); // Create all spells (and initialize with basic filter properties) foreach (var spell in spells.spells) { ContentItemModel spellModel = new ContentItemModel() { Name = spell.name, ID = spell.id, Markdown = GetSpellMarkdownFromJson(spell) }; spellModel.AddFilterProperty("level", spell.level.ToString()); spellModel.AddFilterProperty("school", spell.school); // If the current spell's school is not in the filter list, add it if (!cpm.FilterGroups.Any(g => string.Equals(g.Header, spell.school))) { cpm.AddOptionToFilterGroup("school", spell.school, spell.school.ToLower().Replace(' ', '_')); } foreach (var comp in spell.components) { spellModel.AddFilterProperty("components", comp); } // ADD SINGLE TRUE/FALSE FILTER PROPERTIES //spellModel.AddFilterProperty("ritual", spell.isRitual ? "true" : "false"); //spellModel.AddFilterProperty("concentration", spell.concentration ? "true" : "false"); cpm.AddContentItem(spellModel); } // Add class filter properties for all spells foreach (var charClass in classSpells.classes) { AddClassFiltersToSpell(cpm, charClass); } // Add filter options to the filter groups cpm.AddOptionToFilterGroup("level", "Cantrips", "0"); cpm.AddOptionToFilterGroup("level", "1st-level", "1"); cpm.AddOptionToFilterGroup("level", "2nd-level", "2"); cpm.AddOptionToFilterGroup("level", "3rd-level", "3"); cpm.AddOptionToFilterGroup("level", "4th-level", "4"); cpm.AddOptionToFilterGroup("level", "5th-level", "5"); cpm.AddOptionToFilterGroup("level", "6th-level", "6"); cpm.AddOptionToFilterGroup("level", "7th-level", "7"); cpm.AddOptionToFilterGroup("level", "8th-level", "8"); cpm.AddOptionToFilterGroup("level", "9th-level", "9"); foreach (var comp in components.components) { cpm.AddOptionToFilterGroup("components", comp.name, comp.initial); } cpm.AddOptionToFilterGroup("other", "Show only ritual spells", "ritual"); cpm.AddOptionToFilterGroup("other", "Show only concentration spells", "conc"); return(cpm); }
public void UpdateContentItem(ContentItem contentItem, ContentItemModel contentModel) { contentItem.Name = contentModel.Name; contentItem.Description = contentModel.Description; contentItem.Keywords = contentModel.Keywords; contentItem.IsActive = contentModel.IsActive; contentItem.AddLog("Update content", string.Empty); }
/// <summary> /// Updates the given content item. /// </summary> /// <param name="client">Content management client instance.</param> /// <param name="identifier">Identifies which content item will be updated. </param> /// <param name="contentItem">Specifies data for updated content item.</param> /// <returns>The <see cref="ContentItemModel"/> instance that represents updated content item.</returns> public static async Task <ContentItemModel> UpdateContentItemAsync(this ContentManagementClient client, ContentItemIdentifier identifier, ContentItemModel contentItem) { if (identifier == null) { throw new ArgumentNullException(nameof(identifier)); } if (contentItem == null) { throw new ArgumentNullException(nameof(contentItem)); } var contentItemUpdateModel = new ContentItemUpdateModel(contentItem); return(await client.UpdateContentItemAsync(identifier, contentItemUpdateModel)); }
public ActionResult Edit(string id, ContentItemModel contentModel, FormCollection collection) { if (base.ModelState.IsValid) { var contentItem = this.contentItemRepository.GetById(new Guid(id)); if (contentItem != null) { this.contentModelsService.UpdateContentItem(contentItem, contentModel); this.contentBonusService.CalculateTotalPoints(DomainSessionContext.Instance.CurrentUser); return base.RedirectToAction(ControllerAssistant.GetActionName(() => this.Details(id)), new { id = id }); } } return base.View("CreateOrUpdate", contentModel); }