public string GetListItemURLById(Guid _id) { ListsManager listsManager = ListsManager.GetManager(); ListItem listItem = listsManager.GetListItems().Where(i => (i.Id == _id)) .FirstOrDefault(); if (listItem != null && listItem.Urls != null && listItem.Parent != null) { var clService = SystemManager.GetContentLocationService(); var allLocations = clService.GetItemLocations(listItem); string firstUrl = string.Empty; foreach (var location in allLocations) { if (firstUrl == string.Empty && location != null) { firstUrl = location.ItemAbsoluteUrl; } } if (firstUrl != null) { return(firstUrl); } else { return("/"); } } else { return("/"); } }
/// <summary> /// Deletes list item by given id /// </summary> /// <param name="masterListItemId">list item id</param> public void DeleteListItem(Guid masterListItemId) { ListsManager listsManager = ListsManager.GetManager(); ListItem listItem = listsManager.GetListItems().Where(i => i.Id == masterListItemId).FirstOrDefault(); if (listItem != null) { listsManager.DeleteListItem(listItem); listsManager.SaveChanges(); } }
/// <summary> /// Publish list item with specific date. /// </summary> /// <param name="listItemId">The list item id.</param> /// <param name="publicationDate">Publication datetime.</param> public void PublishListItemWithSpecificDate(Guid listItemId, DateTime publicationDate) { ListsManager listManager = ListsManager.GetManager(); ListItem listItemMaster = listManager.GetListItems().Where(i => i.Id == listItemId).FirstOrDefault(); if (listItemMaster == null) { throw new ItemNotFoundException(string.Format(CultureInfo.CurrentCulture, "List item with id {0} was not found.", listItemId)); } listManager.Lifecycle.PublishWithSpecificDate(listItemMaster, publicationDate); listManager.SaveChanges(); }
public void AddTaxonomiesToListItem(Guid listItemId, IEnumerable <string> categories, IEnumerable <string> tags) { string transactionName = "AddTaxonomiesToListItem"; ListsManager listManager = ListsManager.GetManager(string.Empty, transactionName); ListItem listItemMaster = listManager.GetListItems().Where(i => i.Id == listItemId).FirstOrDefault(); if (listItemMaster == null) { throw new ItemNotFoundException(string.Format(CultureInfo.CurrentCulture, "List item with id {0} was not found.", listItemId)); } ListItem listItemTemp = listManager.Lifecycle.CheckOut(listItemMaster) as ListItem; var taxonomyManager = TaxonomyManager.GetManager(); if (categories != null) { if (categories.Count() > 0) { HierarchicalTaxon category = null; foreach (var c in categories) { category = taxonomyManager.GetTaxa <HierarchicalTaxon>().Single(t => t.Title == c); listItemTemp.Organizer.AddTaxa("Category", category.Id); } } } if (tags != null) { if (tags.Count() > 0) { FlatTaxon tag = null; foreach (var tg in tags) { tag = taxonomyManager.GetTaxa <FlatTaxon>().Single(t => t.Title == tg); listItemTemp.Organizer.AddTaxa("Tags", tag.Id); } } } listItemMaster = listManager.Lifecycle.CheckIn(listItemTemp) as ListItem; listManager.Lifecycle.Publish(listItemMaster); TransactionManager.CommitTransaction(transactionName); }
/// <summary> /// Edit title and content of list item. /// </summary> /// <param name="listItemId">The list item id.</param> /// <param name="newTitle">The list item title.</param> /// <param name="newContent">The list item content.</param> public void EditListItem(Guid listItemId, string newTitle, string newContent) { ListsManager listManager = ListsManager.GetManager(); ListItem listItemMaster = listManager.GetListItems().Where(i => i.Id == listItemId).FirstOrDefault(); if (listItemMaster == null) { throw new ItemNotFoundException(string.Format(CultureInfo.CurrentCulture, "List item with id {0} was not found.", listItemId)); } ListItem listItemTemp = listManager.Lifecycle.CheckOut(listItemMaster) as ListItem; listItemTemp.Title = newTitle; listItemTemp.Content = newContent; listItemMaster = listManager.Lifecycle.CheckIn(listItemTemp) as ListItem; listManager.Lifecycle.Publish(listItemMaster); listManager.SaveChanges(); }