Skip to content

Instantly share code, notes, and snippets.

@gabesumner
Created December 29, 2010 20:28
Show Gist options
  • Save gabesumner/759025 to your computer and use it in GitHub Desktop.
Save gabesumner/759025 to your computer and use it in GitHub Desktop.
Exploring blog posts using Sitefinity's Fluent API
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CustomWidget.ascx.cs" Inherits="SitefinityWebApp.Custom.CustomWidget" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<div class="customwidget">
<div><asp:Button ID="CreateBlog" runat="server" Text="Create Blog"
onclick="CreateBlog_Click" /></div>
<div><asp:Button ID="CreatePosts" runat="server" Text="Create Posts"
onclick="CreatePosts_Click" /></div>
<div><asp:Button ID="DisplayPosts" runat="server" Text="Display Posts"
onclick="DisplayPosts_Click" /></div>
<div>
<telerik:RadGrid ID="RadGrid1" Width="100%" runat="server">
<MasterTableView AutoGenerateColumns="False">
<Columns>
<telerik:GridBoundColumn DataField="Title" HeaderText="Title" />
<telerik:GridBoundColumn DataField="Parent.Title" HeaderText="Blog" />
<telerik:GridDateTimeColumn DataField="DateCreated" HeaderText="Date Created" />
<telerik:GridBoundColumn DataField="Comments.Count" HeaderText="Comments" />
</Columns>
</MasterTableView>
</telerik:RadGrid>
</div>
</div>
using System;
using Telerik.Sitefinity;
namespace SitefinityWebApp.Custom
{
public partial class CustomWidget : System.Web.UI.UserControl
{
protected void CreateBlog_Click(object sender, EventArgs e)
{
App.WorkWith().Blog().CreateNew().Do(b => b.Title = "My New Blog").SaveChanges();
}
protected void CreatePosts_Click(object sender, EventArgs e)
{
using (var fluent = App.WorkWith())
{
var blog = (from b in fluent.Blogs()
where b.Title == "My New Blog"
select b).First();
for (int i = 0; i < 10; i++)
{
blog.CreateBlogPost().Do(p => p.Title = "Blog Post " + i).SaveChanges();
}
}
}
protected void DisplayPosts_Click(object sender, EventArgs e)
{
var posts = from p in App.WorkWith().BlogPosts()
where p.Parent.Title == "My New Blog"
orderby p.Title
select p;
RadGrid1.DataSource = posts.Get();
RadGrid1.DataBind();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment