public void PopulateAttendanceForEvent(EVENT currentEvent) { try { StudentLevelLogic studentLevelLogic = new StudentLevelLogic(); List <STUDENT_LEVEL> studentsInLevel = studentLevelLogic.GetEntitiesBy(s => s.Department_Id == currentEvent.Department_Id && s.Level_Id == currentEvent.Level_Id && s.Programme_Id == currentEvent.Programme_Id && s.Session_Id == currentEvent.Session_Id); studentsInLevel.ForEach(s => { if (base.GetEntitiesBy(a => a.Event_Id == currentEvent.Id && a.Student_Id == s.Student_Id).LastOrDefault() == null) { ATTENDANCE attendance = new ATTENDANCE(); attendance.Attendance_Status_Id = (int)AttendanceStatuses.Absent; attendance.Cancelled = false; attendance.Event_Id = currentEvent.Id; attendance.Student_Id = s.Student_Id; attendance.Time_Taken = currentEvent.Event_Start; base.Create(attendance); } }); } catch (Exception) { throw; } }
public List <EVENT> GetEventsForStudent(STUDENT student) { List <EVENT> events = null; try { DateTime todayStartTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0); DateTime todayEndTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59); events = base.GetEntitiesBy(e => e.Date >= todayStartTime && e.Date <= todayEndTime && (e.Active == true || e.Active == null)); StudentLevelLogic studentLevelLogic = new StudentLevelLogic(); STUDENT_LEVEL studentLevel = studentLevelLogic.GetEntitiesBy(s => s.Student_Id == student.Person_Id).LastOrDefault(); if (studentLevel != null) { events = events.Where(e => e.Programme_Id == studentLevel.Programme_Id && e.Department_Id == studentLevel.Department_Id && e.Level_Id == studentLevel.Level_Id).ToList(); } } catch (Exception ex) { throw ex; } return(events); }
public List <COURSE> GetCoursesForStudent(STUDENT student) { List <COURSE> courses = null; try { StudentLevelLogic studentLevelLogic = new StudentLevelLogic(); STUDENT_LEVEL studentLevel = studentLevelLogic.GetEntitiesBy(s => s.Student_Id == student.Person_Id).LastOrDefault(); if (studentLevel != null) { courses = base.GetEntitiesBy(c => c.Active && c.Department_Id == studentLevel.Department_Id && c.Level_Id == studentLevel.Level_Id && c.Programme_Id == studentLevel.Programme_Id); } } catch (Exception) { throw; } return(courses); }
public ActionResult DownloadSemesterAttendance(string attendanceId) { EventViewModel viewModel = (EventViewModel)TempData["ViewModel"]; if (viewModel == null) { return(null); } try { if (!string.IsNullOrEmpty(attendanceId)) { long myAttendnaceId = Convert.ToInt64(Utility.Decrypt(attendanceId)); EventLogic eventLogic = new EventLogic(); StudentLevelLogic studentLevelLogic = new StudentLevelLogic(); AttendanceLogic attendanceLogic = new AttendanceLogic(); //ATTENDANCE myAttendnace = attendanceLogic.GetEntitiesBy(s => s.Event_Id == myAttendnaceId).LastOrDefault(); //if (myAttendnace == null) //{ // return null; //} List <STUDENT_LEVEL> studentLevels = new List <STUDENT_LEVEL>(); studentLevels = studentLevelLogic.GetEntitiesBy(s => s.Department_Id == viewModel.Department.Id && s.Level_Id == viewModel.Level.Id && s.Programme_Id == viewModel.Programme.Id && s.Session_Id == viewModel.Session.Id); List <ATTENDANCE> masterAttendance = new List <ATTENDANCE>(); for (int i = 0; i < studentLevels.Count; i++) { if (viewModel.EventType.Id == (int)EventTypes.Lecture && viewModel.Course != null && viewModel.Course.Id > 0) { ATTENDANCE attendance = ProcessCourseAttendance(viewModel.Course, studentLevels[i].STUDENT); if (attendance != null) { attendance.STUDENT = studentLevels[i].STUDENT; attendance.EVENT = eventLogic.GetEntitiesBy(e => e.Course_Id == viewModel.Course.Id).LastOrDefault(); masterAttendance.Add(attendance); } } else if (viewModel.EventType.Id == (int)EventTypes.HallAttendance && viewModel.Hall != null && viewModel.Hall.Id > 0) { ATTENDANCE attendance = ProcessHallAttendance(viewModel.Hall, studentLevels[i].STUDENT); if (attendance != null) { attendance.STUDENT = studentLevels[i].STUDENT; attendance.EVENT = eventLogic.GetEntitiesBy(e => e.Hall_Id == viewModel.Hall.Id).LastOrDefault(); masterAttendance.Add(attendance); } } else { ATTENDANCE attendance = ProcessOtherAttendance(viewModel.EventType, studentLevels[i].STUDENT); if (attendance != null) { attendance.STUDENT = studentLevels[i].STUDENT; attendance.EVENT = eventLogic.GetEntitiesBy(e => e.Event_Type_Id == viewModel.EventType.Id).LastOrDefault(); masterAttendance.Add(attendance); } } } GridView gv = new GridView(); DataTable ds = new DataTable(); if (masterAttendance.Count > 0) { List <ATTENDANCE> list = masterAttendance.OrderBy(p => p.STUDENT.Matric_Number).ToList(); List <SemesterAttendanceModel> sort = new List <SemesterAttendanceModel>(); for (int i = 0; i < list.Count; i++) { SemesterAttendanceModel attendance = new SemesterAttendanceModel(); attendance.SN = (i + 1); attendance.Name = list[i].STUDENT.PERSON.Last_Name + " " + list[i].STUDENT.PERSON.First_Name + " " + list[i].STUDENT.PERSON.Other_Name; attendance.Registration_Number = list[i].STUDENT.Matric_Number; attendance.Event_Type = list[i].EVENT.EVENT_TYPE.Name; if (list[i].EVENT.COURSE != null) { attendance.Course_Hall = list[i].EVENT.COURSE.Name; } else if (list[i].EVENT.HALL != null) { attendance.Course_Hall = list[i].EVENT.HALL.Name; } else { attendance.Course_Hall = ""; } attendance.Percentage = list[i].Percentage.ToString() + "%"; attendance.Status = list[i].IsEligible ? "Eligible" : "Not Eligible"; sort.Add(attendance); } gv.DataSource = sort; string caption = "Attendnace Report"; if (list != null && list.Count > 0) { caption = "Attendnace Report for " + list.FirstOrDefault().EVENT.DEPARTMENT.Name + ". " + list.FirstOrDefault().EVENT.LEVEL.Name + ". Session: " + list.FirstOrDefault().EVENT.SESSION.Name; } gv.Caption = caption.ToUpper(); gv.DataBind(); string filename = caption.Replace("\\", "") + ".xls"; return(new DownloadFileActionResult(gv, filename)); } else { Response.Write("No data available for download"); Response.End(); return(new JavaScriptResult()); } } } catch (Exception ex) { SetMessage("Error! " + ex.Message, Message.Category.Error); } return(RedirectToAction("SemesterAttendance", "Event", new { Area = "Admin" })); }
public ActionResult SemesterAttendance(EventViewModel viewModel) { try { if (viewModel.Session != null && viewModel.Programme != null && viewModel.Department != null && viewModel.Level != null && viewModel.EventType != null) { EventLogic eventLogic = new EventLogic(); StudentLevelLogic studentLevelLogic = new StudentLevelLogic(); List <STUDENT_LEVEL> studentLevels = new List <STUDENT_LEVEL>(); studentLevels = studentLevelLogic.GetEntitiesBy(s => s.Department_Id == viewModel.Department.Id && s.Level_Id == viewModel.Level.Id && s.Programme_Id == viewModel.Programme.Id && s.Session_Id == viewModel.Session.Id); List <ATTENDANCE> masterAttendance = new List <ATTENDANCE>(); for (int i = 0; i < studentLevels.Count; i++) { if (viewModel.EventType.Id == (int)EventTypes.Lecture && viewModel.Course != null && viewModel.Course.Id > 0) { ATTENDANCE attendance = ProcessCourseAttendance(viewModel.Course, studentLevels[i].STUDENT); if (attendance != null) { attendance.STUDENT = studentLevels[i].STUDENT; attendance.EVENT = eventLogic.GetEntitiesBy(e => e.Course_Id == viewModel.Course.Id).LastOrDefault(); masterAttendance.Add(attendance); } } else if (viewModel.EventType.Id == (int)EventTypes.HallAttendance && viewModel.Hall != null && viewModel.Hall.Id > 0) { ATTENDANCE attendance = ProcessHallAttendance(viewModel.Hall, studentLevels[i].STUDENT); if (attendance != null) { attendance.STUDENT = studentLevels[i].STUDENT; attendance.EVENT = eventLogic.GetEntitiesBy(e => e.Hall_Id == viewModel.Hall.Id).LastOrDefault(); masterAttendance.Add(attendance); } } else { ATTENDANCE attendance = ProcessOtherAttendance(viewModel.EventType, studentLevels[i].STUDENT); if (attendance != null) { attendance.STUDENT = studentLevels[i].STUDENT; attendance.EVENT = eventLogic.GetEntitiesBy(e => e.Event_Type_Id == viewModel.EventType.Id).LastOrDefault(); masterAttendance.Add(attendance); } } } viewModel.AttendanceList = masterAttendance; } } catch (Exception ex) { SetMessage("Error! " + ex.Message, Message.Category.Error); } TempData["ViewModel"] = viewModel; ViewBag.Programmes = viewModel.ProgrammeSelectList; ViewBag.Departments = viewModel.DepartmentSelectList; ViewBag.Levels = viewModel.LevelSelectList; ViewBag.Sessions = viewModel.SessionSelectList; ViewBag.Locations = viewModel.LocationSelectList; ViewBag.Courses = new SelectList(new List <SelectListItem>(), "Value", "Text");; ViewBag.Halls = viewModel.HallSelectList; ViewBag.EventTypes = viewModel.EventTypeSelectList; return(View(viewModel)); }