-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathPersonPart.cs
43 lines (36 loc) · 2.09 KB
/
PersonPart.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
* Now let's see what practices Orchard Core provides when it stores data. Here you can see a content part. Each
* content part can be attached to one or more content types. From the content type you can create content items (so
* you kind of "instantiate" content types as content items). This is the most important part of the Orchard Core's
* content management.
*
* Here is a PersonPart containing some properties of a person. We are planning to attach this content part to a Person
* content type so when you create a Person content item it will have a PersonPart attached to it. You also need to
* register this class with the service provider (see: Startup.cs).
*/
using OrchardCore.ContentFields.Fields;
using OrchardCore.ContentManagement;
using System;
namespace Lombiq.TrainingDemo.Models;
public class PersonPart : ContentPart
{
// A ContentPart is serialized as a JSON object so you need to keep this in mind when creating properties. For
// further information check the Json.NET documentation: https://www.newtonsoft.com/json/help/html/Introduction.htm
public string Name { get; set; }
public Handedness Handedness { get; set; }
public DateTime? BirthDateUtc { get; set; }
// This is a content field. Content fields are similar to content parts, however, fields are a bit smaller
// components encapsulating a simple editor and display for a single piece of data. Content parts could provide more
// complex functionality and also can contain a set of fields. TextField is one of Orchard's many built-in fields.
// To utilize it you don't need to add a property for it to the part (you just need to attach it to the content
// type, what we're doing from migrations) but having such a property is a nice shortcut to it. You don't need to
// instantiate it either, why we do it here is to avoid null checks when working with the content item even without
// initializing it with IContentManager.LoadAsync().
public TextField Biography { get; set; } = new();
}
public enum Handedness
{
Right,
Left,
}
// NEXT STATION: Migrations/PersonMigrations