本文整理汇总了C#中umbraco.cms.businesslogic.web.Document.Save方法的典型用法代码示例。如果您正苦于以下问题:C# Document.Save方法的具体用法?C# Document.Save怎么用?C# Document.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类umbraco.cms.businesslogic.web.Document
的用法示例。
在下文中一共展示了Document.Save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Save
/// <summary>
/// Saveses this instance.
/// </summary>
public void Save()
{
// get the data
Document document = new Document(NodeId.Value);
Property editProperty = document.getProperty(Field);
IDataType editDataType = null;
if (editProperty != null)
{
// save the property
PropertyType editPropertyType = editProperty.PropertyType;
editDataType = editPropertyType.DataTypeDefinition.DataType;
editDataType.Data.PropertyId = editProperty.Id;
editDataType.Data.Value = Data;
}
else
{
if (Field == "pageName")
{
document.Text = Data.ToString();
}
}
document.Save();
}
示例2: Document_BeforePublish
void Document_BeforePublish(Document sender, umbraco.cms.businesslogic.PublishEventArgs e)
{
if (sender.ContentType.Alias == "Project")
{
//ensure that packages have a guid
if (sender.getProperty("packageGuid") != null && String.IsNullOrEmpty(sender.getProperty("packageGuid").Value.ToString()))
{
sender.getProperty("packageGuid").Value = Guid.NewGuid().ToString();
sender.Save();
}
//if the score is above the minimum, set the approved variable
int score = Xslt.Score(sender.Id, "powersProject");
if (score >= 15)
{
sender.getProperty("approved").Value = true;
sender.Save();
}
//this ensures the package stores it's compatible versions on the node itself, so we save a ton of sql calls
if (sender.getProperty("compatibleVersions") != null)
{
List<string> compatibleVersions = new List<string>();
foreach (WikiFile wf in WikiFile.CurrentFiles(sender.Id))
{
if (wf.FileType == "package")
{
foreach (var ver in wf.Versions)
{
if (!compatibleVersions.Contains(ver.Version))
{
compatibleVersions.Add(ver.Version);
}
}
}
}
string _compatibleVersions = string.Join(",", compatibleVersions.ToArray());
sender.getProperty("compatibleVersions").Value = "saved," + _compatibleVersions;
}
}
}
示例3: Action_AfterPerform
void Action_AfterPerform(object sender, ActionEventArgs e)
{
uPowers.BusinessLogic.Action a = (uPowers.BusinessLogic.Action)sender;
if (a.Alias == "ProjectUp")
{
Document d = new Document(e.ItemId);
if (d.getProperty("approved").Value != null &&
d.getProperty("approved").Value.ToString() != "1" &&
uPowers.Library.Xslt.Score(d.Id, "powersProject") >= 15)
{
//set approved flag
d.getProperty("approved").Value = true;
d.Save();
d.Publish(new umbraco.BusinessLogic.User(0));
umbraco.library.UpdateDocumentCache(d.Id);
umbraco.library.RefreshContent();
}
}
}
示例4: Move
public string Move(int wikiId, int target)
{
var currentMemberId = Members.GetCurrentMember().Id;
if (Xslt.IsMemberInGroup("admin", currentMemberId) || Xslt.IsMemberInGroup("wiki editor", currentMemberId))
{
Document document = new Document(wikiId);
Document documentTarget = new Document(target);
if (documentTarget.ContentType.Alias == "WikiPage")
{
Document o = new Document(document.Parent.Id);
document.Move(documentTarget.Id);
document.Save();
document.Publish(new umbraco.BusinessLogic.User(0));
documentTarget.Publish(new umbraco.BusinessLogic.User(0));
o.Publish(new umbraco.BusinessLogic.User(0));
umbraco.library.UpdateDocumentCache(document.Id);
umbraco.library.UpdateDocumentCache(documentTarget.Id);
umbraco.library.UpdateDocumentCache(o.Id);
umbraco.library.RefreshContent();
return umbraco.library.NiceUrl(document.Id);
}
}
return "";
}
示例5: InstallStore
/// <summary>
/// Install a new uWebshop store
/// </summary>
/// <param name="storeAlias">the store alias to use</param>
/// <param name="storeDocument">the document of the store</param>
/// <param name="cultureCode"> </param>
/// <param name="preFillRequiredItems"></param>
internal static void InstallStore(string storeAlias, Document storeDocument, string cultureCode = null, bool preFillRequiredItems = false)
{
var reg = new Regex(@"\s*");
storeAlias = reg.Replace(storeAlias, "");
if (cultureCode == null)
{
var languages = Language.GetAllAsList();
var firstOrDefaultlanguage = languages.FirstOrDefault();
if (firstOrDefaultlanguage == null)
return;
cultureCode = firstOrDefaultlanguage.CultureAlias;
}
var installStoreSpecificPropertiesOnDocumentTypes = WebConfigurationManager.AppSettings["InstallStoreDocumentTypes"];
if (installStoreSpecificPropertiesOnDocumentTypes == null || installStoreSpecificPropertiesOnDocumentTypes != "false")
{
if (DocumentType.GetAllAsList().Where(x => x.Alias.StartsWith(Store.NodeAlias)).All(x => x.Text.ToLower() != storeAlias.ToLower()))
{
IO.Container.Resolve<IUmbracoDocumentTypeInstaller>().InstallStore(storeAlias);
}
else
{
// todo: return message that store already existed?
return;
}
}
var admin = new User(0);
var uwbsStoreDt = DocumentType.GetByAlias(Store.NodeAlias);
var uwbsStoreRepositoryDt = DocumentType.GetByAlias(Store.StoreRepositoryNodeAlias);
var uwbsStoreRepository = Document.GetDocumentsOfDocumentType(uwbsStoreRepositoryDt.Id).FirstOrDefault(x => !x.IsTrashed);
if (storeDocument == null)
{
if (uwbsStoreRepository != null)
if (uwbsStoreDt != null)
{
storeDocument = Document.MakeNew(storeAlias, uwbsStoreDt, admin, uwbsStoreRepository.Id);
if (storeDocument != null && preFillRequiredItems)
{
storeDocument.SetProperty("orderNumberPrefix", storeAlias);
storeDocument.SetProperty("globalVat", "0");
storeDocument.SetProperty("countryCode", "DK");
storeDocument.SetProperty("storeEmailFrom", string.Format("[email protected]{0}.com", storeAlias));
storeDocument.SetProperty("storeEmailTo", string.Format("[email protected]{0}.com", storeAlias));
storeDocument.SetProperty("storeEmailFromName", storeAlias);
storeDocument.Save();
storeDocument.Publish(new User(0));
}
}
}
var language = Language.GetByCultureCode(cultureCode);
if (storeDocument == null)
{
return;
}
if (language != null) storeDocument.SetProperty("currencyCulture", language.id.ToString());
storeDocument.Save();
//InstallProductUrlRewritingRules(storeAlias);
}
示例6: MakeNew
public static Document MakeNew(string Name, DocumentType dct, User u, int ParentId)
{
//allows you to cancel a document before anything goes to the DB
var newingArgs = new DocumentNewingEventArgs()
{
Text = Name,
DocumentType = dct,
User = u,
ParentId = ParentId
};
Document.OnNewing(newingArgs);
if (newingArgs.Cancel)
{
return null;
}
//Create a new IContent object based on the passed in DocumentType's alias, set the name and save it
IContent content = ApplicationContext.Current.Services.ContentService.CreateContentWithIdentity(Name, ParentId, dct.Alias, u.Id);
//The content object will only have the 'WasCancelled' flag set to 'True' if the 'Creating' event has been cancelled, so we return null.
if (((Entity)content).WasCancelled)
return null;
//read the whole object from the db
Document d = new Document(content);
//event
NewEventArgs e = new NewEventArgs();
d.OnNew(e);
// Log
LogHelper.Info<Document>(string.Format("New document {0}", d.Id));
// Run Handler
BusinessLogic.Actions.Action.RunActionHandlers(d, ActionNew.Instance);
// Save doc
d.Save();
return d;
}
示例7: Copy
public Document Copy(int CopyTo, User u, bool RelateToOrignal)
{
var e = new CopyEventArgs();
e.CopyTo = CopyTo;
FireBeforeCopy(e);
Document newDoc = null;
if (!e.Cancel)
{
// Make the new document
var content = ApplicationContext.Current.Services.ContentService.Copy(Content, CopyTo, RelateToOrignal, u.Id);
newDoc = new Document(content);
// Have to run the ActionNew handler to do umbEnsureUniqueName (for example)
BusinessLogic.Actions.Action.RunActionHandlers(newDoc, ActionNew.Instance);
// Then save to preserve any changes made by action handlers
newDoc.Save();
e.NewDocument = newDoc;
FireAfterCopy(e);
}
return newDoc;
}
示例8: Copy
public Document Copy(int CopyTo, User u, bool RelateToOrignal)
{
var e = new CopyEventArgs();
e.CopyTo = CopyTo;
FireBeforeCopy(e);
Document newDoc = null;
if (!e.Cancel)
{
// Make the new document
var content = ApplicationContext.Current.Services.ContentService.Copy(Content, CopyTo, RelateToOrignal, u.Id);
newDoc = new Document(content);
// Then save to preserve any changes made by action handlers
newDoc.Save();
e.NewDocument = newDoc;
FireAfterCopy(e);
}
return newDoc;
}
示例9: DocumentAfterPublish
protected void DocumentAfterPublish(Document sender, PublishEventArgs e)
{
// when thinking about adding something here, consider ContentOnAfterUpdateDocumentCache!
if (sender.Level > 2)
{
if (sender.ContentType.Alias == Order.NodeAlias || sender.Parent != null && (OrderedProduct.IsAlias(sender.ContentType.Alias) || sender.Parent.Parent != null && OrderedProductVariant.IsAlias(sender.ContentType.Alias)))
{
var orderDoc = sender.ContentType.Alias == Order.NodeAlias ? sender : (OrderedProduct.IsAlias(sender.ContentType.Alias) && !OrderedProductVariant.IsAlias(sender.ContentType.Alias) ? new Document(sender.Parent.Id) : new Document(sender.Parent.Parent.Id));
if (orderDoc.ContentType.Alias != Order.NodeAlias)
throw new Exception("There was an error in the structure of the order documents");
// load existing orderInfo (why..? => possibly to preserve information not represented in the umbraco documents)
if (string.IsNullOrEmpty(orderDoc.getProperty("orderGuid").Value.ToString()))
{
Store store = null;
var storeDoc = sender.GetAncestorDocuments().FirstOrDefault(x => x.ContentType.Alias == OrderStoreFolder.NodeAlias);
if (storeDoc != null)
{
store = StoreHelper.GetAllStores().FirstOrDefault(x => x.Name == storeDoc.Text);
}
if (store == null)
{
store = StoreHelper.GetAllStores().FirstOrDefault();
}
var orderInfo = OrderHelper.CreateOrder(store);
IO.Container.Resolve<IOrderNumberService>().GenerateAndPersistOrderNumber(orderInfo);
orderInfo.Status = OrderStatus.Confirmed;
orderInfo.Save();
sender.SetProperty("orderGuid", orderInfo.UniqueOrderId.ToString());
sender.Save();
}
else
{
var orderGuid = Guid.Parse(orderDoc.getProperty("orderGuid").Value.ToString());
var orderInfo = OrderHelper.GetOrderInfo(orderGuid);
var order = new Order(orderDoc.Id);
orderInfo.CustomerEmail = order.CustomerEmail;
orderInfo.CustomerFirstName = order.CustomerFirstName;
orderInfo.CustomerLastName = order.CustomerLastName;
var dictionaryCustomer = orderDoc.GenericProperties.Where(x => x.PropertyType.Alias.StartsWith("customer")).ToDictionary(customerProperty => customerProperty.PropertyType.Alias, customerProperty => customerProperty.Value.ToString());
orderInfo.AddCustomerFields(dictionaryCustomer, CustomerDatatypes.Customer);
var dictionaryShipping = orderDoc.GenericProperties.Where(x => x.PropertyType.Alias.StartsWith("shipping")).ToDictionary(property => property.PropertyType.Alias, property => property.Value.ToString());
orderInfo.AddCustomerFields(dictionaryShipping, CustomerDatatypes.Shipping);
var dictionarExtra = orderDoc.GenericProperties.Where(x => x.PropertyType.Alias.StartsWith("extra")).ToDictionary(property => property.PropertyType.Alias, property => property.Value.ToString());
orderInfo.AddCustomerFields(dictionarExtra, CustomerDatatypes.Extra);
//orderInfo.SetVATNumber(order.CustomerVATNumber); happens in AddCustomerFields
var orderPaidProperty = order.Document.getProperty("orderPaid");
if (orderPaidProperty != null && orderPaidProperty.Value != null)
orderInfo.Paid = orderPaidProperty.Value == "1";
// load data recursively from umbraco documents into order tree
orderInfo.OrderLines = orderDoc.Children.Select(d =>
{
var fields = d.GenericProperties.Where(x => !OrderedProduct.DefaultProperties.Contains(x.PropertyType.Alias)).ToDictionary(s => s.PropertyType.Alias, s => d.GetProperty<string>(s.PropertyType.Alias));
var xDoc = new XDocument(new XElement("Fields"));
OrderUpdatingService.AddFieldsToXDocumentBasedOnCMSDocumentType(xDoc, fields, d.ContentType.Alias);
var orderedProduct = new OrderedProduct(d.Id);
var productInfo = new ProductInfo(orderedProduct, orderInfo);
productInfo.ProductVariants = d.Children.Select(cd => new ProductVariantInfo(new OrderedProductVariant(cd.Id), productInfo, productInfo.Vat)).ToList();
return new OrderLine(productInfo, orderInfo) {_customData = xDoc};
}).ToList();
// store order
IO.Container.Resolve<IOrderRepository>().SaveOrderInfo(orderInfo);
}
// cancel does give a warning message balloon in Umbraco.
//e.Cancel = true;
//if (sender.ContentType.Alias != Order.NodeAlias)
//{
// orderDoc.Publish(new User(0));
//}
//if (orderDoc.ParentId != 0)
//{
BasePage.Current.ClientTools.SyncTree(sender.Parent.Path, false);
BasePage.Current.ClientTools.ChangeContentFrameUrl(string.Concat("editContent.aspx?id=", sender.Id));
//}
//orderDoc.delete();
BasePage.Current.ClientTools.ShowSpeechBubble(BasePage.speechBubbleIcon.success, "Order Updated!", "This order has been updated!");
}
}
}
示例10: Move
public static string Move(int ID, int target)
{
int _currentMember = HttpContext.Current.User.Identity.IsAuthenticated ? (int)Membership.GetUser().ProviderUserKey : 0;
if (Xslt.IsMemberInGroup("admin", _currentMember) || Xslt.IsMemberInGroup("wiki editor", _currentMember))
{
Document d = new Document(ID);
Document t = new Document(target);
if(t.ContentType.Alias == "WikiPage"){
Document o = new Document(d.Parent.Id);
d.Move(t.Id);
d.Save();
d.Publish(new umbraco.BusinessLogic.User(0));
t.Publish(new umbraco.BusinessLogic.User(0));
o.Publish(new umbraco.BusinessLogic.User(0));
umbraco.library.UpdateDocumentCache(d.Id);
umbraco.library.UpdateDocumentCache(t.Id);
umbraco.library.UpdateDocumentCache(o.Id);
umbraco.library.RefreshContent();
return umbraco.library.NiceUrl(d.Id);
}
}
return "";
}
示例11: SaveDoc
private void SaveDoc(Document doc)
{
doc.Save();
doc.Publish(User.GetCurrent());
umbraco.library.UpdateDocumentCache(doc.Id);
}
示例12: MakeNew
/// <summary>
/// Creates a new document
/// </summary>
/// <param name="Name">The name (.Text property) of the document</param>
/// <param name="dct">The documenttype</param>
/// <param name="u">The usercontext under which the action are performed</param>
/// <param name="ParentId">The id of the parent to the document</param>
/// <returns>The newly created document</returns>
public static Document MakeNew(string Name, DocumentType dct, User u, int ParentId)
{
//allows you to cancel a document before anything goes to the DB
var newingArgs = new DocumentNewingEventArgs()
{
Text = Name,
DocumentType = dct,
User = u,
ParentId = ParentId
};
Document.OnNewing(newingArgs);
if (newingArgs.Cancel)
{
return null;
}
Guid newId = Guid.NewGuid();
// Updated to match level from base node
CMSNode n = new CMSNode(ParentId);
int newLevel = n.Level;
newLevel++;
//create the cms node first
CMSNode newNode = MakeNew(ParentId, _objectType, u.Id, newLevel, Name, newId);
//we need to create an empty document and set the underlying text property
Document tmp = new Document(newId, true);
tmp.SetText(Name);
//create the content data for the new document
tmp.CreateContent(dct);
//now create the document data
SqlHelper.ExecuteNonQuery("insert into cmsDocument (newest, nodeId, published, documentUser, versionId, Text) values (1, " +
tmp.Id + ", 0, " +
u.Id + ", @versionId, @text)",
SqlHelper.CreateParameter("@versionId", tmp.Version),
SqlHelper.CreateParameter("@text", tmp.Text));
// Update the sortOrder if the parent was the root!
if (ParentId == -1)
{
newNode.sortOrder = CountLeafNodes(-1, Document._objectType) + 1;
}
//read the whole object from the db
Document d = new Document(newId);
//event
NewEventArgs e = new NewEventArgs();
d.OnNew(e);
// Log
Log.Add(LogTypes.New, u, d.Id, "");
// Run Handler
umbraco.BusinessLogic.Actions.Action.RunActionHandlers(d, ActionNew.Instance);
// Save doc
d.Save();
return d;
}
示例13: createEvent
protected void createEvent(object sender, EventArgs e)
{
var hasAnchors = false;
var hasLowKarma = false;
var documentId = 0;
var karma = int.Parse(_member.getProperty("reputationTotal").Value.ToString());
if (karma < 50)
{
hasLowKarma = true;
}
//edit?
if (string.IsNullOrEmpty(Request.QueryString["id"]) == false)
{
var document = new Document(int.Parse(Request.QueryString["id"]));
documentId = document.Id;
//allowed?
if (document.ContentType.Alias == "Event" && int.Parse(document.getProperty("owner").Value.ToString()) == _member.Id)
{
SetDescription(document, hasLowKarma, ref hasAnchors);
document.Text = tb_name.Text;
document.getProperty("venue").Value = tb_venue.Text;
document.getProperty("latitude").Value = tb_lat.Value;
document.getProperty("longitude").Value = tb_lng.Value;
var sync = tb_capacity.Text != document.getProperty("capacity").Value.ToString();
document.getProperty("capacity").Value = tb_capacity.Text;
document.getProperty("start").Value = DateTime.Parse(dp_startdate.Text);
document.getProperty("end").Value = DateTime.Parse(dp_enddate.Text);
document.Save();
document.Publish(new User(0));
umbraco.library.UpdateDocumentCache(document.Id);
if (sync)
{
var ev = new uEvents.Event(document);
ev.syncCapacity();
}
}
}
else
{
Document document = Document.MakeNew(tb_name.Text, DocumentType.GetByAlias("Event"), new User(0), EventsRoot);
documentId = document.Id;
SetDescription(document, hasLowKarma, ref hasAnchors);
document.getProperty("venue").Value = tb_venue.Text;
document.getProperty("latitude").Value = tb_lat.Value;
document.getProperty("longitude").Value = tb_lng.Value;
document.getProperty("capacity").Value = tb_capacity.Text;
document.getProperty("signedup").Value = 0;
document.getProperty("start").Value = DateTime.Parse(dp_startdate.Text);
document.getProperty("end").Value = DateTime.Parse(dp_enddate.Text);
document.getProperty("owner").Value = _member.Id;
document.Save();
document.Publish(new User(0));
umbraco.library.UpdateDocumentCache(document.Id);
}
var redirectUrl = umbraco.library.NiceUrl(documentId);
if (hasLowKarma && hasAnchors)
SendPotentialSpamNotification(tb_name.Text, redirectUrl, _member.Id);
Response.Redirect(redirectUrl);
}
示例14: UpdateSortOrder
public void UpdateSortOrder(int ParentId, string SortOrder)
{
//TODO: The amount of processing this method takes is HUGE. We should look at
// refactoring this to use purely the new APIs and see how much faster we can make it!
try
{
if (AuthorizeRequest() == false) return;
if (SortOrder.Trim().Length <= 0) return;
var ids = SortOrder.Split(',');
var isContent = helper.Request("app") == "content" | helper.Request("app") == "";
var isMedia = helper.Request("app") == "media";
//ensure user is authorized for the app requested
if (isContent && AuthorizeRequest(DefaultApps.content.ToString()) == false) return;
if (isMedia && AuthorizeRequest(DefaultApps.media.ToString()) == false) return;
for (var i = 0; i < ids.Length; i++)
{
if (ids[i] == "" || ids[i].Trim() == "") continue;
if (isContent)
{
var document = new Document(int.Parse(ids[i]))
{
sortOrder = i
};
if (document.Published)
{
document.Publish(BusinessLogic.User.GetCurrent());
//TODO: WE don't want to have to republish the entire document !!!!
library.UpdateDocumentCache(document);
}
else
{
//we need to save it if it is not published to persist the sort order value
document.Save();
}
}
// to update the sortorder of the media node in the XML, re-save the node....
else if (isMedia)
{
var media = new cms.businesslogic.media.Media(int.Parse(ids[i]))
{
sortOrder = i
};
media.Save();
}
// Refresh sort order on cached xml
if (isContent)
{
XmlNode parentNode = ParentId == -1
? content.Instance.XmlContent.DocumentElement
: content.Instance.XmlContent.GetElementById(ParentId.ToString());
//only try to do the content sort if the the parent node is available...
if (parentNode != null)
content.SortNodes(ref parentNode);
// Load balancing - then refresh entire cache
if (UmbracoSettings.UseDistributedCalls)
library.RefreshContent();
// fire actionhandler, check for content
BusinessLogic.Actions.Action.RunActionHandlers(new Document(ParentId), ActionSort.Instance);
}
}
}
catch (Exception ex)
{
LogHelper.Error<nodeSorter>("Could not update sort order", ex);
}
}
示例15: SaveDoc
private INode SaveDoc(Document doc)
{
doc.Save();
doc.Publish(User.GetAllByLoginName("visitor", false).FirstOrDefault());
umbraco.library.UpdateDocumentCache(doc.Id);
return new Node(doc.Id);
}