public static bool writeToStudentLog(string[] username, string Comment, string Type, string Section) { List<Student_Log> log = new List<Student_Log>(); foreach (string s in username) { Student_Log l = new Student_Log(); l.Comment = Comment; l.Type = Type; l.Section = Section; l.DateTime = DateTime.Now; l.Deleted = false; l.UserName = s; l.Author = CookieHelper.Username; log.Add(l); } return saveStudentLog(log); }
private static bool saveStudentLog(Student_Log log) { try { db.Student_Log.AddObject(log); db.SaveChanges(); } catch (Exception e) { Debug.WriteLine(e.Message); return false; } return true; }
// Write a new log with supplied information /// <summary> /// Writes an entry to the log table /// </summary> /// <param name="CaseID">Student_Log's Case ID</param> /// <param name="Comment">Informative comment e.g. "Profile Update by xxx" or "Application deleted by xxx"</param> /// <param name="Type"> See LogHelper.LOG_* for list of type </param> /// <param name="Section"> See LogHelper.SECTION_* for list of sections </param> /// <returns>True if successful log write </returns> public static bool writeToStudentLog(int CaseID, string Comment, string Type, string Section) { List<Student_Log> log = new List<Student_Log>(); string studentUsername = db.Cases.SingleOrDefault(x => x.Case_Id == CaseID).Student.UserName; Student_Log l = new Student_Log(); l.UserName = studentUsername; l.Comment = Comment; l.Type = Type; l.Section = Section; l.DateTime = DateTime.Now; l.Deleted = false; log.Add(l); foreach (Case_Staff s in db.Case_Staff.Where(x => x.Case_Id == CaseID).ToList()) { l = new Student_Log(); l.UserName = s.Staff.UserName; l.Comment = Comment; l.Type = Type; l.Section = Section; l.DateTime = DateTime.Now; l.Deleted = false; l.Author = CookieHelper.Username; log.Add(l); } return saveStudentLog(log); }