Implementing the backend service

To create the backend service, you must perform the following:

  1. From the context menu of the folder Web » Services in the ProductsModule project, click Add » Class.
  2. Name the class file ProductsBackendService.cs and click Add.
  3. Open the file ProductsBackendService.cs.
  4. Add the following using statements:

    using ProductCatalogSample.Data;
    using ProductCatalogSample.Model;
    using ProductCatalogSample.Web.Services.Data;
    using Telerik.Sitefinity.Lifecycle;
    using Telerik.Sitefinity.Modules;
    using Telerik.Sitefinity.Modules.GenericContent;

  5. Make the ProductsBackendService class inherit the ContentServiceBase<ProductItem, ProductItemViewModel, ProductsManager> class:

    public class ProductsBackendService : ContentServiceBase<ProductItem, ProductItemViewModel, LifecycleDecoratorWrapper<ProductItem, ProductsManager, ProductsDataProvider>>
    {
    }
  6. Implement the abstract members of ContentServiceBase in the following way:

    public override IQueryable<ProductItem> GetChildContentItems(Guid parentId, string providerName)
    {
        throw new NotSupportedException();
    }
     
    public override ProductItem GetContentItem(Guid id, string providerName)
    {
        return ProductsManager.GetManager(providerName).GetProduct(id);
    }
     
    public override IQueryable<ProductItem> GetContentItems(string providerName)
    {
        return ProductsManager.GetManager(providerName).GetProducts();
    }
     
    public override ProductItem GetParentContentItem(Guid id, string providerName)
    {
        throw new NotSupportedException();
    }
     
    public override IEnumerable<ProductItemViewModel> GetViewModelList(IEnumerable<ProductItem> contentList, ContentDataProviderBase dataProvider)
    {
        var viewModelList = new List<ProductItemViewModel>();
        foreach (var product in contentList)
            viewModelList.Add(new ProductItemViewModel(product, dataProvider));
        return viewModelList;
    }
     
    public override LifecycleDecoratorWrapper<ProductItem, ProductsManager, ProductsDataProvider> GetManager(string providerName)
    {
        return new LifecycleDecoratorWrapper<ProductItem, ProductsManager, ProductsDataProvider>(providerName);
    }

Next steps

+1-888-365-2779
sales@sitefinity.com

Related topics:

Feedback

How useful is this article?

Tell us more

Submit
Your message was successfully sent.

We appreciate your feedback.

Your message could not be sent.

OK