Creating Custom Content via the Fluent API
I did some research around reading content from an RSS feed and importing it into the system using the Fluent API. This works great for out of the box type of content (I was able to successfully add a news item utilizing this method). However, I want to accomplish the same thing but using a custom content type that we've created in code. I looked at the Products sample that is in the SDK and actually added that project as a reference to my web project. However, I can't figure out how to access this custom content type via the Fluent API to work with the solution I've come up.
Here's the code that handles submitting RSS content as a NewsItem.
protected
void
btnNews_Click(
object
sender, EventArgs e)
// Get the RSS feed from Sitefinity Watch
var newsRSS = XDocument.Load(
"https://spreadsheets.google.com/feeds/list/0ApjyJpMAI_HsdHQ0S202RXdlbmRGV1l4TWxRS1FPZEE/od6/public/basic?hl=en_US&alt=rss"
);
// Get the RSS items from the feed
var rssItems = from item
in
newsRSS.Descendants(
"item"
)
select item;
// Loop through each RSS item
foreach
(var item
in
rssItems.ToList())
//get the dictionary of items
Dictionary<
string
,
string
> content = ParseRSS(item.Element(
"description"
).Value);
// Add the news content via the RSS feed
using
(var fluent = App.WorkWith())
var news = fluent.NewsItem().CreateNew()
.Do(b =>
b.Title = content[
"title"
];
b.Content = content[
"body"
];
b.Author = content[
"author"
];
b.SourceSite = content[
"source"
];
)
.Get();
Hi Shane,
The fluent API is a wrapper of the normal API (managers and providers) and is implemented specifically for each module(News ,blogs ...). If you want to use Fluent API for a custom module( the products module is not built in so it is counted as cutom), you need to implement it yourself which is a hard task. As a different option is to convert the Products Item information to Rss with a third party service like for example web2rss, feedfire or similar.
So my problem isn't converting the information into RSS; rather its taking an external RSS feed and pull that into a custom content type. Is there a way that I can do this without using the Fluent API but rather just sitefinity's standard API to instantiate a new instance of the ProductItem, set its properties, and then add it to the system so I can load custom content from an external source?
Thanks
Shane
Hello Shane,
You can not use API to query a custom module yet. We will provide an new functionality to the API in Q2 release .
All the best,
Stanislav Velikov
the Telerik team
Was this ever answered? The last post was from July 2011.
Is there any documentation on how to access custom content types in the Fluent or regular APIs?
Thanks
Hi,
The Q2 release have passed and custom modules can be queried using the native API
The API of custom modules is like the API for the built in modules, just change the name of the managers you are working with, as they represend the manager classes of the ProductCatalogSample.
using
ProductCatalogSample.Data;
using
ProductCatalogSample.Model;
using
Telerik.Sitefinity.GenericContent.Model;
ProductsManager manager = ProductsManager.GetManager();
//create a query for type ProductItem
ProductItem item = manager.GetProducts()
.Where(t => t.Title ==
"Test"
&& t.Status == ContentLifecycleStatus.Live).Single();
item.UrlName =
"changedURL"
;
manager.SaveChanges();