• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 363
  • Last Modified:

Create a class for registrations or not? asp.net

I'm still struggling with understanding OOP so this is a pretty basic question.

I'm not sure if building a custom class for this is necessary or possible. I have a friend that told me, "If you do something over and over, build a class." But I'm not sure in this case if the system.net.mail and database stuff is as good as it gets.

The company I work for does a lot of events. The way I handle it now is to build a registration page that has the form, inserts the registration to the database and then build a report page.

But I have to do this every time there's an event.

The form has name, title, address, etc. Just basic information. There is only one field that comes and goes, the rest of the fields are the same on every registration page. I use code behind to do the parameterized inserts.

So my question is, should I build a class or not? Or does this have to be done for each and every page the way I'm doing it now?

Thanks,
mh
0
MHenry
Asked:
MHenry
  • 2
  • 2
1 Solution
 
PaulHewsCommented:
Personally, I think that if the events have more in common with each other than not, then you need to create generic ways to deal them.  That would include Event class, Registration class, and probably a generic registration form to handle individual registrations for all events.

Coming up with methods to deal with the ways that events are different from one another is the really challenging part of this.
0
 
MHenryAuthor Commented:
PaulHews,

That makes sense.

The main difference between events is date, time, vendors involved and description.

And the people involved always want to see a list of registrations and get an email notification when someone does register.

Any ideas to give me a head start?

Thanks,
mh
0
 
PaulHewsCommented:
The main difference between events is date, time, vendors involved and description.
Sounds to me like you are describing fields.

So lets say you have an event class, with fields:

Event:
ID
Title (or Name)
EventDateTime
Vendors  (Note that this may require more classes and links)
Description

This could map to a database table.

Now each event has multiple registrations:

Registration:
ID
EventID (This links to the unique ID in the event table)
Email
FirstName
LastName

This also maps to a database table.  

Your generic sign up form would be populated by pulling the event record from the database and displaying it with areas where you can enter your information if you wish to register.

Of course the model gets more complicated if people sign up for multiple events, in which case you might have another table/class mapping.

You can use tools like Entity Framework or NHibernate or other ORMs to map back and forth from database to classes.  There are lots of tutorials on this.  
eg
http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application

Properly modeling your data is important.
0
 
MHenryAuthor Commented:
PaulHews,

This ought to be carved in stone rather than buried at the end of your post:
"Properly modeling your data is important." Gave me a good chuckle to see that. When you've been doing it for years, it may seem like that. To me, it's scary as hell. I've been putting this off for months because I was afraid to even start.

This was exactly the kind of thing I was looking for. I couldn't see how making it one class would work. And when you said, "This looks like fields," it was like a light came on.

Well done sir. And my thanks!
mh
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now