Kentico 8 Dataquery
var users = UserInfoProvider.GetUsers()
.Where(where)
.OrderBy(orderBy)
.TopN(topN)
.Columns(columns);
foreach (UserInfo user in users)
{
}
var documents = DocumentHelper.GetDocuments("CMS.News")
.OnSite("CorporateSite")
.Path("/pages/%")
.OrderBy("DocumentName");
// Go through the documents
foreach (var document in documents)
{
Response.Write(document.DocumentName);
}
//More example: http://devnet.kentico.com/articles/kentico-8-technology-documentquery-api
------------ Custom Table Insert item ------------
----Example 1 ------
// Create new item for custom table with "customtable.sample" code name
var item = CustomTableItem.New("customtable.sample");
item.SetValue("ItemText", "Sample text");
item.Insert();
-----Example 2 ------
private static ItemType NewInstance<ItemType>(string className)
where ItemType : CustomTableItem, new()
{
ItemType result = (typeof(ItemType) == typeof(CustomTableItem)) ? CustomTableItemGenerator.NewInstance<ItemType>(className) : new ItemType();
return result;
}
//Code needs the above NewInstance Method
SmilesGiftCardsItem item = NewInstance<SmilesGiftCardsItem>(SmilesGiftCardsItem.CLASS_NAME);
item.Name = "Name Example";
item.Insert();
------------ Get Custom Table Item ------------
//Get custom table items
var items = CustomTableItemProvider.GetItems<TaxCertificatesItem>();//this way
//OR
var items = CustomTableItemProvider.GetItems("customtable.sample")
.TopN(10)
.WhereEquals("ItemCreatedBy", 10)
.OrderBy("ItemCreatedWhen");
foreach (ClastomTableItemClassName item in items)
{
}
LoyaltySaleItemStatusItem item = CustomTableItemProvider.GetItems<LoyaltySaleItemStatusItem>()
.WhereEquals("ItemID", SalesStatusID)
.Columns("Name, Description")
.TopN(1);
------------ Custom Table Update Item ------------
// Get item with ID 1 of custom table with code name "customtable.sample"
var existing = CustomTableItemProvider.GetItem(1, "customtable.sample");
if (existing != null)
{
existing.SetValue("ItemText", "MODIFIED");
existing.Update();
}
var roles = RoleInfoProvider.GetRoles();
DataSet users = new DataQuery("cms.user.selectall")
.Columns("UserID", "UserName", "FullName")
.Where("UserName", QueryOperator.Like, "%admin%")
.OrderBy("FullName")
.Execute();
DataSet users = new DataQuery("NameOfYourCustomQuery").Execute();