0

I have models for Students, Courses, Enrollment, and Attendance. Each course has a different number of days of attendance and I need to be able to edit attendance for those days.

I use the following models:

public class Student
{
    public int StudentID { get; set; }
    public string LastName { get; set; }
    public string FirstMidName { get; set; }
    public virtual ICollection<Enrollment> Enrollments { get; set; } // To keep track of what classes in which the student is enrolled
}

public class Course
{
    public int CourseID { get; set; }
    public string Title { get; set; }
    public int InstructorID { get; set; }
    public virtual Instructor Instructor { get; set; }
    public int AttendingDays { get; set; } // Total number of days for attendance
    public virtual ICollection<Enrollment> Enrollments { get; set; }
}

public class Enrollment
{
    public int EnrollmentID { get; set; }
    public int CourseID { get; set; }
    public int StudentID { get; set; }
    public virtual Course Course { get; set; }
    public virtual Student Student { get; set; }
}

public class Attendance
{
    public int AttendanceID { get; set; }
    public int CourseID { get; set; }
    public int StudentID { get; set; }
    public int AttendanceDay { get; set; }
    public bool Present { get; set; }
    public virtual Course Course { get; set; }
    public virtual Student Student { get; set; }
}

How would I go about building a ViewModel that would let me edit the Attendance Table appropriately adjusting the number of days of attendance for the specified class depending on the AttendingDays int from the Course class.

i.e. If Class X has an AttendingDays value of 10, I need 10 rows of attendance dates that I can go down and fill a checkox for present/absent for each student - while Class Y only has 3 AttendingDays, etc. . .

So a sample row from the attendance table would read something like: ID 25: For Course X, Student X on day 3 was present. ID26: For Course X, Student X on day 4 was absent, etc. . .

What is the most efficient way to approach this?

UPDATE:

Now I create Attendance database entries where the student is marked as Present = false for every possible day of attendance once they are added to a class.

How would my ViewModel work now that I know I will always have the appropriate attendance days already in creation for each student?

I would need to generate a page that displays a row for every Student contained within a Course (this information is contained within the Enrollment table). Each Student's row would contain checkboxes for each day of attendance (so there would be a grid of checkboxes going across the screen with student names listed on the left and the number representing the day of attendance across the top).

edit:

Would this be something jqGrid would be useful?

Ecnalyr
  • 5,792
  • 5
  • 43
  • 89
  • Would the `Attendance` entries already be populated in the database, and thus need to be fetched based on the `Course`, or would you be creating at the time of editing the Course's attendance? – Brad Christie Apr 25 '12 at 13:51
  • I would be creating it at the time of editing the course's attendance. Unless some of the attendance fields had been previously edited - in which case I would want to pull those and then be able to edit them. – Ecnalyr Apr 25 '12 at 14:03
  • I am now thinking it would probably be easier to generate the attendance entries when a student is added to a class - instead of present or absent, the entries would be null - and then be populated via the check-box attendance page. Does this sound like an appropriate way to approach this problem? – Ecnalyr Apr 26 '12 at 11:50
  • Yes, that sounds like a better solution to me, yes. – Brad Christie Apr 26 '12 at 12:40

0 Answers0