예제 #1
0
        public ActionResult ViewAttendance(string eventId)
        {
            _viewModel = new EventViewModel();
            try
            {
                if (!string.IsNullOrEmpty(eventId))
                {
                    long myEventId = Convert.ToInt64(Utility.Decrypt(eventId));

                    AttendanceLogic attendanceLogic = new AttendanceLogic();
                    AbsentLogLogic  absentLogLogic  = new AbsentLogLogic();

                    _viewModel.AttendanceList = attendanceLogic.GetEntitiesBy(s => s.Event_Id == myEventId);

                    _viewModel.AttendanceList.ForEach(e =>
                    {
                        if (e.Attendance_Status_Id == (int)AttendanceStatuses.Excused)
                        {
                            e.ATTENDANCE_STATUS.Name = absentLogLogic.GetAbsenceRequestStatus(e);
                        }
                    });

                    _viewModel.EventId = myEventId;
                }
            }
            catch (Exception ex)
            {
                SetMessage("Error! " + ex.Message, Message.Category.Error);
            }

            return(View(_viewModel));
        }
예제 #2
0
        public ActionResult DownloadAttendance(string eventId)
        {
            _viewModel = new EventViewModel();
            try
            {
                if (!string.IsNullOrEmpty(eventId))
                {
                    long myEventId = Convert.ToInt64(Utility.Decrypt(eventId));

                    AttendanceLogic attendanceLogic = new AttendanceLogic();
                    AbsentLogLogic  absentLogLogic  = new AbsentLogLogic();

                    _viewModel.AttendanceList = attendanceLogic.GetEntitiesBy(s => s.Event_Id == myEventId);

                    _viewModel.AttendanceList.ForEach(e =>
                    {
                        if (e.Attendance_Status_Id == (int)AttendanceStatuses.Excused)
                        {
                            e.ATTENDANCE_STATUS.Name = absentLogLogic.GetAbsenceRequestStatus(e);
                        }
                    });

                    GridView  gv = new GridView();
                    DataTable ds = new DataTable();
                    if (_viewModel.AttendanceList.Count > 0)
                    {
                        List <ATTENDANCE>      list = _viewModel.AttendanceList.OrderBy(p => p.STUDENT.Matric_Number).ToList();
                        List <AttendanceModel> sort = new List <AttendanceModel>();
                        for (int i = 0; i < list.Count; i++)
                        {
                            AttendanceModel attendance = new AttendanceModel();
                            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.Location   = list[i].EVENT.LOCATION.Name;
                            attendance.Date       = list[i].EVENT.Date.ToLongDateString();
                            attendance.Time_Taken = list[i].Time_Taken.ToLongTimeString();
                            attendance.Status     = list[i].ATTENDANCE_STATUS.Name;

                            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("ViewAttendance", "Event", new { Area = "Admin", eventId = eventId }));
        }