private StudentAttendance GetStudentAttendance(int student_id, string date) { var school_id = SessionHandler.GetSchoolID(); var std = new StudentDetails().FindSingle(student_id, school_id); string startDate = "", endDate = ""; date.makeDateString(ref startDate, ref endDate); int daysInMonth = date.GetDaysInMonth(); var stdAtnd = _ad.GetAll(school_id, std.class_id, student_id, startDate, endDate); StudentAttendance _sd = new StudentAttendance(); _sd.student_id = std.user_id; _sd.student_name = std.first_name + " " + std.last_name; for (int i = 0; i < daysInMonth; i++) { var reqDate = ""; var dayName = ""; startDate.getDayAndDate(ref dayName, ref reqDate, i); PresentStatus _ps = new PresentStatus(); _ps.status = -1; _ps.date = reqDate; _ps.dayName = dayName; foreach (var attnd in stdAtnd) { if (attnd.date.ComapareDate(reqDate)) { _ps.status = attnd.status; break; } } _sd.AttendanceDays.Add(_ps); } return _sd; }
public ActionResult ViewClass(int class_id = 0, string date = "") { ClassDetails _cd = new ClassDetails(); int school_id = SessionHandler.GetSchoolID(); ViewBag.classes = _cd.GetAll(school_id); ViewBag.Days = 0; ViewBag.class_id = class_id; ViewBag.date = date; if (class_id != 0 && date != "") { string startDate = ""; string endDate = ""; date.makeDateString(ref startDate, ref endDate); int daysInMonth = date.GetDaysInMonth(); var result = _ad.GetAll(school_id, class_id, startDate, endDate).ToList(); var _sd = new StudentDetails(); var stds = _sd.GetAll(school_id, class_id); ViewBag.Days = daysInMonth; List<StudentAttendance> attendance = new List<StudentAttendance>(); foreach (var std in stds) { StudentAttendance stdAttnd = new StudentAttendance() { student_name = std.first_name + " " + std.last_name, student_id = std.user_id }; for (int x = 1; x <= daysInMonth; x++) { PresentStatus _ps = new PresentStatus() { dayOfMonth = x, status = -1 }; foreach (var atnd in result) { int dayInAtnd = atnd.date.GetDayOfMonth(); if (atnd.student_id == std.user_id && x == dayInAtnd) { _ps.status = atnd.status; break; } } stdAttnd.AttendanceDays.Add(_ps); } attendance.Add(stdAttnd); } return View(attendance); } return View(); }