Implementing the view model

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 Services » Data, click Add » Class...

  2. Name the class file JobApplicationViewModel.cs and click Add.

  3. Open the file JobApplicationViewModel.cs.

  4. Add the following using statements:

    using Jobs.Model;
    using Telerik.Sitefinity.GenericContent.Model;
    using Telerik.Sitefinity.Modules;
    using Telerik.Sitefinity.Modules.GenericContent;

  5. Make the JobApplicationViewModel class inherit the ContentViewModelBase class:

    public class JobApplicationViewModel : ContentViewModelBase
    {
    }

  6. 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;
    }

  7. 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;
    }

  8. 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);
    }

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