Creating the model

To create a custom content-based model, perform the following procedure:

  1. From the context menu of folder Model, click Add » New Item...

  2. In the left pane, select Visual C# » Code.

  3. Click Class and in the Name input field, enter JobApplication.

  4. Open the file JobApplication.cs and add the following namespaces:

    using Telerik.OpenAccess;
    using Telerik.Sitefinity;
    using Telerik.Sitefinity.GenericContent.Model;

  5. Change the class definition to:

    [DataContract(Namespace = "http://sitefinity.com/samples/jobsmodule", Name = "JobApplication")]
    [ManagerType("Jobs.JobsManager, Jobs")]
    [Persistent(IdentityField = "contentId")]
    public class JobApplication : Content
    {
     
    }
  6. Override the SupportsContentLifecycle method by pasting the following code:

    public override bool SupportsContentLifecycle
    {
        get
        {
            return false;
        }
    }
  7. Define private fields for the properties:

    private string referral;
    private string text;
    private string phone;
    private string firstName;
    private string lastName;
  8. Define the job application properties by pasting the following code:

    [DataMember]
    [FieldAlias("phone")]
    public string Phone
    {
        get
        {
            return this.phone;
        }
        set
        {
            this.phone = value;
        }
    }
     
    [DataMember]
    [FieldAlias("firstName")]
    public string FirstName
    {
        get
        {
            return this.firstName;
        }
        set
        {
            this.firstName = value;
        }
    }
     
    [DataMember]
    [FieldAlias("lastName")]
    public string LastName
    {
        get
        {
            return this.lastName;
        }
        set
        {
            this.lastName = value;
        }
    }
     
    [DataMember]
    [FieldAlias("text")]
    public string Text
    {
        get
        {
            return this.text;
        }
        set
        {
            this.text = value;
        }
    }
     
    [DataMember]
    [FieldAlias("referral")]
    public string Referral
    {
        get
        {
            return this.referral;
        }
        set
        {
            this.referral = value;
        }
    }

JobApplication is the name of your model. First, you mark your custom model as Persistent and specify the manager which is used to operate on this model. You will implement the manager in Creating the manager. By choosing Content as the parent class, your custom model automatically inherits a ready-to-use functionality (IDynamicFieldsContainer, ICommentable, IExtensibleDataObject, IOrganizable,IVersionSerializable, IInstanceCallbacks, IContentLifecycle, ILocalizable). Because for this task, Content Lifecycle is not required you explicitly disable Content Lifecycle by setting SupportsContentLifecycle to false.

Next, you must define the abstract data provider. For more information, see Defining the abstract data provider.

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