//Add
 public void SaveAttendance(Attendance attendance)
 {
     if (attendance.id == 0)
     {
         context.Attendances.Add(attendance);
     }
     else
     {
         context.Entry(attendance).State = System.Data.EntityState.Modified;
     }
     context.SaveChanges();
 }
 public Boolean Present(int id)
 {
     var myAttendance = new Attendance();
     var classID = (int)Session["RosterID"];
     var ClassHours = repository.GetClassHoursList(classID);
     var curDay = Convert.ToString(DateTime.Now.DayOfWeek);
     try
     {
         var classHoursForDay = ClassHours.Where(d => d.day == curDay);
         var curClassHour = classHoursForDay.FirstOrDefault(t => t.startTime.Hours == DateTime.Now.Hour);
         myAttendance.StudentId = id;
         myAttendance.AttendTime = DateTime.Now;
         myAttendance.ClassHourId = curClassHour.id;
         repository.SaveAttendance(myAttendance);
         TempData["message"] = string.Format("Student {0} marked as present for session {1}!", id, curClassHour.id);
     }
     catch
     {
         TempData["message"] = string.Format("Student {0} is not enrolled in this session of the class!", id);
         return false;
     }
     return true;
 }
 //Delete
 public void DeleteAttendance(Attendance attendance)
 {
     context.Attendances.Remove(attendance);
     context.SaveChanges();
 }