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:
- From the context menu of the folder Web » Services » Data in the LocationsModule project, click Add » Class.
- Name the class file LocationItemViewModel.cs and click Add.
- Open the file LocationItemViewModel.cs.
-
Add the following using statements:
- using Telerik.Sitefinity.Modules;
- using Telerik.Sitefinity.GenericContent.Model;
- using LocationsModule.Model;
- using Telerik.Sitefinity.Modules.GenericContent;
-
Make the LocationItemViewModel class inherit the ContentViewModelBase class:
public class LocationItemViewModel : ContentViewModelBase
{
}
-
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;
}
-
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; }
-
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);
}
