Hi all, I've decided to start another thread for my old health app https://www.daniweb.com/web-development/aspnet/threads/496278/building-first-mvc-application as the old thread was pretty confusing and didn't lead me anywhere. With the knowlegde coming from developing the previous simple book review app here https://www.daniweb.com/web-development/aspnet/threads/497464/much-simpler-first-mvc-application I've also decided to take a different approach: I'll build the app as I go along, meaning, I'll start very simple (two classes minimum) and then I'll continue to update the app and develop the other classes as needed (thanks to @djjeavons now I know I to do successful migrations so databases shouldn't be a problem!).
So, I said I'll start simple. Here is the first two classes of the app, Patient.cs and Jab.cs.
Patient:
public class Patient
{
public int PatientID { get; set; }//primary key
public string Name { get; set; }
public string Surname { get; set; }
public DateTime DOB { get; set; }
public string Sex { get; set; }
public double Height { get; set; }
//public double Weight { get; set; } //this will have its own class
public virtual ICollection<Jab> Jabs { get; set; }
}
Jab:
public class Jab
{
public int JabID { get; set; }//primary key
public int PatientID { get; set; }//foreign key
public string Name { get; set; }
public DateTime Date { get; set; }
public int ShotNumber { get; set; }//which shot is that?
public string Note { get; set; }//in case I need to add some notes to the jab
public virtual ICollection<Patient> Patients { get; set; }
}
A few things to note:
-From research and (small) practice, I now know that I don't need to use [key] or [foreignKey] tokens as MVC is smart enough to determine those on its own.
-A patient can have multiple jabs (one-to-many) and a jab can be done for multiple patients (one-to-many), so both classes keep track of this by using ICollection:public virtual ICollection<Patient> Patients { get; set; }
public virtual ICollection<Jab> Jabs { get; set; }
Next step will be for me to create the db class, add the below to it:
public DbSet<Patient> Patients { get; set; }
public DbSet<Jab> Jabs { get; set; }
Then I have a question about controllers: what I'd do, is to add two controllers with EF, (the Patient and the Jabs ones), but do you think that is a good approach considering that my model will expand to include other classes (meaning that presumably I will have to have extra controllers as the model grows)?
Before going ahead, I was wondering, is there anything else anybody thinks it is a good idea/practice to add?
thanks