Products

Solutions

Resources

Partners

Community

About

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

The Community Blog is a personal opinion of community members and by no means the official standpoint of DNN Corp or DNN Platform. This is a place to express personal thoughts about DNNPlatform, the community and its ecosystem. Do you have useful information that you would like to share with the DNN Community in a featured article or blog? If so, please contact .

The use of the Community Blog is covered by our Community Blog Guidelines - please read before commenting or posting.


Creating the Task Class

In the previous blog entry we went into our SQL Database and created a table to hold our tasks data. Now we need to move back into Visual Studio so that we can create a “class” within our module project. This “class” will serve as a definition for the objects that will represent tasks within our module’s code. You could also think of each task object correlating with one row (a task) in our “Tasks” table in our SQL Server database.

If you’ve got knowledge of OOP (Object Oriented Programming) this information is probably not new to you. Though, if you don’t have a background in OOP hopefully this blog will help you understand some of the concepts and I’ll provide some helpful links to OOP resources at the bottom. Also, as you get more into code you will pick it up faster than you think so stick with it even if things get a little fuzzy!

So we’re storing tasks in the database and we need to represent these tasks as “objects” before we send them to the database to get stored.

Task Objects

Classes & Objects
To actually create the class in code isn’t that difficult, but to understand what’s going on is the main point here. Classes provide the definition of our objects. That is a class defines the properties & functions that our objects have. In our case, the same data points that we hope to capture and save to SQL will be properties of the objects that will exist in memory before being sent to the database. Likewise when we retrieve data from the database we will create new objects and populate their properties with the data that comes back from SQL. So, to be repetitive for good measure, the term “class” is the definition or blue print for our objects. Whenever we create a new task object it will be created with the properties and functions that the object’s blue print (its class) has defined.

Creating the Task Class
To create a new class in Visual Studio we simply right click on our module project and select “Add” then “Class”. Side note: there are classes for nearly everything so get comfortable with these concepts and don’t worry if your module has dozens of classes.

Let’s create the “Tasks” class in Visual Studio. If you take a step back and think about organization, since there are (or can be) lots of classes, we should probably create a folder to store these files. So before we even create a class let’s create a new folder so that we can store these classes in an organized manner and keep things tidy. To do this just right click on the project and choose “Add” then “New Folder”. Now we need to name the folder and in other tutorials online I’ve seen them named a lot of different things like “ojbects”, “models”, “classes”, ”repository”, etc.  You can name the folder whatever you like I’m just giving you this information in case you download a module from the forge and see various folder names that hold all these class files.

Create a folder in Visual Studio

I’m going to name the folder “models”, but you can name it whatever you would like. Create a folder and once you create the folder then right click on the folder and click “Add” then “Class”. Then give the class name the name of “Task.cs”. Congratulations, you’ve just created your first class! Now the class currently doesn’t have any functionality, but nevertheless it is a class. As you would imagine we now need to add in the properties of our task class. So we need to add the same data points that we are capturing in SQL to our class as properties. Your class should look similar to the following:

The Task Class definition

Public & Get; Set;
As I’ve mentioned in the video below the class consists of a few items that may look odd to you if you don’t have a strong OOP background. The terms “public” and then that “get; set;” thing may throw you for a loop. I’ve included some specific links below about class modifiers, properties, accessors, and auto-implemented accessors that will help you understand more.

Now that we’ve created our class we are ready to create task objects for use in our module and we are getting close to being able to actually retrieve some tasks from the database and show them through our module, but we have a few more steps left. So hang in there because we are indeed making progress.

OOP Helpful Links:

Go to the Next Blog Entry: Creating the GetTasks Stored Procedure

Comments

mohammad azarbara
Like
mohammad azarbara Monday, November 3, 2014 7:03 AM (link)
James Brown
Link to the series introduction
http://www.dnnsoftware.com/community-blog/cid/155064/module-development-for-non-developers-skinners-dnn-beginners--blog-series-intro

Link to the previous Blog Entry:http://www.dnnsoftware.com/community-blog/cid/155078/creating-the-tasks-table
James Brown Monday, June 15, 2015 11:40 AM (link)

Comment Form

Only registered users may post comments.

NewsArchives


Aderson Oliveira (22)
Alec Whittington (11)
Alessandra Daniels (3)
Alex Shirley (10)
Andrew Hoefling (3)
Andrew Nurse (30)
Andy Tryba (1)
Anthony Glenwright (5)
Antonio Chagoury (28)
Ash Prasad (37)
Ben Schmidt (1)
Benjamin Hermann (25)
Benoit Sarton (9)
Beth Firebaugh (12)
Bill Walker (36)
Bob Kruger (5)
Bogdan Litescu (1)
Brian Dukes (2)
Brice Snow (1)
Bruce Chapman (20)
Bryan Andrews (1)
cathal connolly (55)
Charles Nurse (163)
Chris Hammond (213)
Chris Paterra (55)
Clint Patterson (108)
Cuong Dang (21)
Daniel Bartholomew (2)
Daniel Mettler (181)
Daniel Valadas (48)
Dave Buckner (2)
David Poindexter (12)
David Rodriguez (3)
Dennis Shiao (1)
Doug Howell (11)
Erik van Ballegoij (30)
Ernst Peter Tamminga (80)
Francisco Perez Andres (17)
Geoff Barlow (12)
George Alatrash (12)
Gifford Watkins (3)
Gilles Le Pigocher (3)
Ian Robinson (7)
Israel Martinez (17)
Jan Blomquist (2)
Jan Jonas (3)
Jaspreet Bhatia (1)
Jenni Merrifield (6)
Joe Brinkman (274)
John Mitchell (1)
Jon Henning (14)
Jonathan Sheely (4)
Jordan Coopersmith (1)
Joseph Craig (2)
Kan Ma (1)
Keivan Beigi (3)
Kelly Ford (4)
Ken Grierson (10)
Kevin Schreiner (6)
Leigh Pointer (31)
Lorraine Young (60)
Malik Khan (1)
Matt Rutledge (2)
Matthias Schlomann (16)
Mauricio Márquez (5)
Michael Doxsey (7)
Michael Tobisch (3)
Michael Washington (202)
Miguel Gatmaytan (3)
Mike Horton (19)
Mitchel Sellers (40)
Nathan Rover (3)
Navin V Nagiah (14)
Néstor Sánchez (31)
Nik Kalyani (14)
Oliver Hine (1)
Patricio F. Salinas (1)
Patrick Ryan (1)
Peter Donker (54)
Philip Beadle (135)
Philipp Becker (4)
Richard Dumas (22)
Robert J Collins (5)
Roger Selwyn (8)
Ruben Lopez (1)
Ryan Martinez (1)
Sacha Trauwaen (1)
Salar Golestanian (4)
Sanjay Mehrotra (9)
Scott McCulloch (1)
Scott Schlesier (11)
Scott Wilkinson (3)
Scott Willhite (97)
Sebastian Leupold (80)
Shaun Walker (237)
Shawn Mehaffie (17)
Stefan Cullmann (12)
Stefan Kamphuis (12)
Steve Fabian (31)
Steven Fisher (1)
Tony Henrich (3)
Torsten Weggen (3)
Tycho de Waard (4)
Vicenç Masanas (27)
Vincent Nguyen (3)
Vitaly Kozadayev (6)
Will Morgenweck (40)
Will Strohl (180)
William Severance (5)
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out