Tutorial 6 – Service classes and Saving Items

The EntityService class allows you to get entities out of DP CMS.
The EntityModelService class allows you to get strongly typed models out of DP CMS.
In this tutorial we will use EntityModelServise to create a form that allows a site user to create a request that is saved to a DP CMS database. First lets request class that will be saved back to DP CMS:


using System.ComponentModel.DataAnnotations;
using DevPartner.Nop.Plugin.Core.Attributes;
using DevPartner.Nop.Plugin.Core.Models.CMS;

namespace DevPartner.Nop.Plugin.Misc.StartedKit.Models
{
    [SystemName("Request")]
    [Parent("Content Management/Request")]
    public class RequestModel : DPModel
    {
        [Required]
        public string Phone { get; set; }
        [Required]
        public string Email { get; set; }
    }
Notice that on the Request class we have  added the SystemName attribute and defined a Name, this is essential because DP CMS plugin needs to understand which entity type to use when create the request entity. Your model must also inherit from DPModel.
Now that we have our model lets create form for this model:
todo view
The save action for our request form looks like this:
todo action
It is important to note that the Name property will be used by DP CMS plugin as the enity name so we need to ensure that name is something User friendly(unequal).
>