Implementing the view model class

Because the web services in Sitefinity follow the MVVM pattern, you must implement a view model class by performing the following:

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

    • using Telerik.Sitefinity.Modules;
    • using Telerik.Sitefinity.GenericContent.Model;
    • using LocationsModule.Model;
    • using Telerik.Sitefinity.Modules.GenericContent;
  5. Make the LocationItemViewModel class inherit the ContentViewModelBase class:

    public class LocationItemViewModel : ContentViewModelBase
    {
    }
  6. Create the following constructors:

    public LocationItemViewModel()
        : base()
    {
    }
     
    public LocationItemViewModel(LocationItem location, ContentDataProviderBase provider)
        : base(location, provider)
    {
        this.Address = location.Address;
        this.City = location.City;
        this.Region = location.Region;
        this.PostalCode = location.PostalCode;
    }
  7. Define properties that match the properties in the LocationItem class. Following is the code for the Address, City, Region and PostalCode properties:

    public string Address { get; set; }
    public string City { get; set; }
    public string Region { get; set; }
    public string PostalCode { get; set; }
  8. Implement the abstract members of the ContentViewModelBase class in the following way:

    protected override Content GetLive()
    {
        return this.provider.GetLiveBase<LocationItem>((LocationItem)this.ContentItem);
    }
     
    protected override Content GetTemp()
    {
        return this.provider.GetTempBase<LocationItem>((LocationItem)this.ContentItem);
    }

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