views:

109

answers:

2

I have a school assignment: a Dog Show.

My assignment is to create a website, where vistors can display results, and where Judges and Secretary can admin and CRUD.

I have a small problem, one part of the assignment: the result should be based on two decisions from different judges, and after that checked by the secretary, before the result is displayed for the user.

I have to say I'm fairly new to programming, and so I need some smart suggestions on how to design and implement this. The assignment should cover both a DB and C# (.NET MVC).

Q1: How do i create a object (result) that depends on two other objects (judge's decisions)? Is that even needed?

Q2: How to solve this in a relational db?

A: 

I don't think this would be hard to solve using a relational DB. I'd suggest that you consider each table in the database as representing an entity (class) in your object model. Some entities that you might want to consider Dog Show, Dog, Entry, Judgement, Result, Judge, Secretary (Judge/Secretary might both be an Official). According to your definition, each Entry would have 2 Judgements (thus you should have a 1-to-Many relationship there), but each Entry only has 1 Result. You might use code or a database constraint (or both) to ensure that a Result for an Entry isn't created until there are two Judgements for that Entry. Likewise, you might use code/constraint to ensure that no more than two Judgements are entered for each Entry.

Hope this helps get you started.

tvanfosson
Thank's it will help. Any tip or example on how to implement this constraint (or code)?"You might use code or a database constraint (or both) to ensure that a Result for an Entry isn't created until there are two Judgements for that Entry. Likewise, you might use code/constraint to ensure that no more than two Judgements are entered for each Entry."
loddn
Count the number of Judgements before you allow a Result to be entered? You could do this in the DB with a trigger or check constraint. Pretty easy to do in code, though you want to make sure it's in a transaction.
tvanfosson
A: 

How do i create a object (result) that depends on two other objects (judge's decisions)? Is that even needed?

I suggest that you create the result object, when you create the 2nd decision object.

The pseudocode might be something like, when the judge tries to create a new decision, then see how many other decisions already exist:

  • case 0: this is the first decision; just create the new decision and return

  • case 1: this will be the second decision; create the new decision, and then create the result based on the two decisions

  • case 2 or more: two decisions already exist, so don't allow this further decision to be created.

Another (perhaps not so good) possibility is to have a separate "create results" process, which runs continually (not continuously: e.g., once every minute), looking for any already-created decision-pairs for which there's no corresponding result, and creating the corresponding result.

ChrisW