Adding Course Model to our Project
In this lesson, we'll add a course model to our project
Get the project source code below, and follow along with the lesson material.
Download Project Source CodeTo set up the project on your local machine, please follow the directions provided in the README.md
file. If you run into any issues with running the project source code, then feel free to reach out to the author in the course's Discord channel.
This lesson preview is part of the The newline Guide to Fullstack ASP.NET Core and React course and can be unlocked immediately with a single-time purchase. Already have access to this course? Log in here.
Get unlimited access to The newline Guide to Fullstack ASP.NET Core and React with a single-time purchase.

[00:00 - 00:10] In the weather forecast controller, we saw few properties such as temperature, date and summary. In this lecture, we will create our own properties.
[00:11 - 00:25] When you go to an e-learning application, which properties do you see in a course? There is an image, name of the course, price, duration, name of the instructor, maybe rating.
[00:26 - 00:31] Now let's implement these properties first. Now, right click on the entity folder.
[00:32 - 00:40] You will see an option to create a new class. You are able to see this because of the C# extension we installed.
[00:41 - 00:51] Press right click, click on create a new class. Give this file a name of course, because this is our course model.
[00:52 - 01:01] As you can see, namespace is entity because it's the name of our project. Underneath that is public class entity.
[01:02 - 01:11] Now we can start writing our properties. Let's start with the ID property, because every course will have a unique ID.
[01:12 - 01:22] It starts with public as we want to access it from any project. Followed by the data type, which is quit, it stands for global unique identifier.
[01:23 - 01:33] It is a 128 bit integer used as a unique identifier. Earlier, it was called UUID, which is universally unique identifier.
[01:34 - 01:45] But now it's quit because it has very low probability of being replicated because it's a 128 bit integer. Now the name is going to be ID.
[01:46 - 01:56] You can call it anything you want, but it's conventional to call it ID. Finally, it has a getter and a setter, we discussed why it's represented the way it is.
[01:57 - 02:13] Now you must see a red underline under the GUID, which means it's not available in our environment. What we can do is click on GUID and press command and dot if you're on Mac or control and a dot if you're on Windows.
[02:14 - 02:18] It will show you some options. What we want is system.
[02:19 - 02:31] As it belongs to system, so click on systems and you will see an import system again, so many systems and the error will go away. Now let's move on to the next property, which is title.
[02:32 - 02:36] Now let me tell you the shortcut. Type prop and press tab.
[02:37 - 02:44] You will see it creates the entire property by itself. Now you can edit it as per your preference.
[02:45 - 02:53] In the title property, data type is a string and the name is title, getter and setter will stay the same. Now let's create rest of the properties.
[02:54 - 03:03] We need price and for price, data type is going to be a float. Float contains value till two decimal place and that's what we want.
[03:04 - 03:11] Next property we need is the name of the instructor. Data type will be a string and name is instructor.
[03:12 - 03:19] Next one is going to be the rating. Data type will be a decimal and name is rating.
[03:20 - 03:28] Finally the image property where the data type is going to be a string and name is image. Getter and setter will be the same for now.
[03:29 - 03:34] That was it for now. In the next lecture, I will introduce you guys to the entity framework core.
[03:35 - 03:39] I want you guys to know it before we start implementing it in our project. So that was it.
[03:40 - 03:40] I will see you in the next one.