本文整理汇总了C#中WebPage.Populate方法的典型用法代码示例。如果您正苦于以下问题:C# WebPage.Populate方法的具体用法?C# WebPage.Populate怎么用?C# WebPage.Populate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WebPage
的用法示例。
在下文中一共展示了WebPage.Populate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Clone
/// <summary>
/// Copy current page as a new page instance.
/// </summary>
/// <param name="targetCulture"></param>
/// <returns></returns>
public WebPageDecorator Clone(string targetCulture = "")
{
var locale = string.IsNullOrEmpty(targetCulture) ? this.Locale : targetCulture;
var web = Context.Find<Web>(WebID);
var newPage = new WebPage();
newPage.Populate(this.Model);
newPage.WebID = web.Id;
newPage.ParentID = this.ParentID;
newPage.Owner = this.Owner;
if (!string.IsNullOrEmpty(locale))
newPage.Locale = locale;
var slugs = Context.WebPages.Filter(p => p.Locale.Equals(newPage.Locale, StringComparison.OrdinalIgnoreCase) &&
//p.ID != this.ID &&
p.WebID.Equals(newPage.WebID)).Select(p => p.Slug).ToArray();
var slug = TextUtility.Slug(newPage.Title);
newPage.Slug = slug;
var i = 0;
while (slugs.Contains(newPage.Slug))
newPage.Slug = slug + "-" + (i++).ToString();
Context.WebPages.Create(newPage);
Context.SaveChanges();
//Generate path
if (this.ParentID == 0)
newPage.Path = "0/" + newPage.ID;
else
{
newPage.Path = this.Parent.Path + "/" + newPage.ID;
}
Context.SaveChanges();
//Copy roles
if (Model.Roles != null && Model.Roles.Count() > 0)
Context.WebPages.AddRoles(newPage.ID, this.Roles);
//Copy widgets
if (Model.Widgets != null && Model.Widgets.Count() > 0)
{
foreach (var w in Model.Widgets)
{
if (w.ShowMode > 0) continue;
var nw = w.Clone(locale);
nw.PageID = newPage.ID;
Context.Widgets.Create(nw);
if (w.Roles != null && w.Roles.Count > 0)
{
var widgetWrapper = new WidgetInstanceDecorator(nw, Context.Widgets);
var _roles = w.Roles.Select(r => r.Name).ToArray();
widgetWrapper.AddRoles(_roles);
}
}
Context.SaveChanges();
}
var newresult = new WebPageDecorator(newPage, Context);
newresult.UpdatePositions();
return newresult;
}