Implementing the view model
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 Services » Data, click Add » Class...
-
Name the class file JobApplicationViewModel.cs and click Add.
-
Open the file JobApplicationViewModel.cs.
-
Add the following using statements:
using Jobs.Model;
using Telerik.Sitefinity.GenericContent.Model;
using Telerik.Sitefinity.Modules;
using Telerik.Sitefinity.Modules.GenericContent;
-
Make the JobApplicationViewModel class inherit the ContentViewModelBase class:
public class JobApplicationViewModel : ContentViewModelBase
{
}
-
Create the following constructors:
public JobApplicationViewModel()
: base()
{
}
public JobApplicationViewModel(JobApplication contentItem, ContentDataProviderBase provider)
: base(contentItem, provider)
{
this.Phone = contentItem.Phone;
this.FirstName = contentItem.FirstName;
this.LastName = contentItem.LastName;
this.Text = contentItem.Text;
this.Referral = contentItem.Referral;
}
-
Define properties that match the properties in the JobApplication class. Follows the code for the Phone, FirstName, LastName, Text, and Referral properties:
public string Phone
{
get;
set;
}
public string FirstName
{
get;
set;
}
public string LastName
{
get;
set;
}
public string Text
{
get;
set;
}
public string Referral
{
get;
set;
}
-
Implement the abstract members of the ContentViewModelBase class in the following way:
protected override Content GetLive()
{
return this.provider.GetLiveBase<JobApplication>((JobApplication)this.ContentItem);
}
protected override Content GetTemp()
{
return this.provider.GetTempBase<JobApplication>((JobApplication)this.ContentItem);
}