Exemplo n.º 1
0
        public JsonResult MarkAttendance(long eventId, decimal latitude, decimal longitude)
        {
            JsonResponseModel result = new JsonResponseModel();

            try
            {
                EVENT currentEvent = _eventLogic.GetEntityBy(e => e.Id == eventId);

                bool eventStatus = _eventLogic.GetEventStatus(currentEvent);
                if (eventStatus)
                {
                    bool inLocation = _eventLogic.InLocation(currentEvent, latitude, longitude);

                    if (inLocation)
                    {
                        _student = _studentLogic.GetEntityBy(s => s.Matric_Number == User.Identity.Name);

                        if (IsCorrectDevice(_student))
                        {
                            //check if attendance record exist
                            ATTENDANCE attendance = _attendanceLogic.GetEntitiesBy(a => a.Event_Id == eventId && a.Student_Id == _student.Person_Id).LastOrDefault();
                            if (attendance == null)
                            {
                                _attendanceLogic.PopulateAttendanceForEvent(currentEvent);
                            }

                            _attendanceLogic.MarkAttendance(_student, currentEvent, AttendanceStatuses.Present);

                            result.IsError = false;
                            result.Message = "Attendance Marked";
                        }
                        else
                        {
                            result.IsError = true;
                            result.Message = "Kindly login with your own device to take this attendnace.";
                        }
                    }
                    else
                    {
                        result.IsError = true;
                        result.Message = "You are not currently at the venue of this event.";
                    }
                }
                else
                {
                    result.IsError = true;
                    result.Message = "Event is not ongoing";
                }
            }
            catch (Exception ex)
            {
                result.IsError = true;
                result.Message = ex.Message;
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
0
        private ATTENDANCE ProcessHallAttendance(HALL hall, STUDENT student)
        {
            ATTENDANCE attendance = null;

            try
            {
                AttendanceLogic attendanceLogic = new AttendanceLogic();
                EventLogic      eventLogic      = new EventLogic();

                int numberOfTimesPresent = attendanceLogic.GetEntitiesBy(s => s.EVENT.Hall_Id == hall.Id && s.Student_Id == student.Person_Id &&
                                                                         s.Attendance_Status_Id == (int)AttendanceStatuses.Present).Count();
                int numberOfLectures = eventLogic.GetEntitiesBy(s => s.Hall_Id == hall.Id && (s.Active == true || s.Active == null)).Count();
                int numberOfAbsence  = attendanceLogic.GetEntitiesBy(s => s.EVENT.Hall_Id == hall.Id && s.Student_Id == student.Person_Id &&
                                                                     s.Attendance_Status_Id == (int)AttendanceStatuses.Excused).Count();
                int numberOfLecturesHeld = numberOfLectures - numberOfAbsence;

                double eligibilityPercentage = (Convert.ToDouble(numberOfTimesPresent) / Convert.ToDouble(numberOfLecturesHeld)) * 100.0;

                attendance            = new ATTENDANCE();
                attendance.Percentage = eligibilityPercentage;

                //result.ApproximateNumberOfLectures = numberOfLecturesHeld;
                //result.EligibilityPercentage = eligibilityPercentage;
                //result.NumberOfAbsent = numberOfAbsence;
                //result.NumberOfPresent = numberOfTimesPresent;
                //result.TotalNumberOfLectures = numberOfLectures;

                if (eligibilityPercentage > 75)
                {
                    attendance.IsEligible = true;
                }
                else
                {
                    attendance.IsEligible = false;
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(attendance);
        }
Exemplo n.º 4
0
        public JsonResult DeleteEvent(long eventId)
        {
            JsonResponseModel result = new JsonResponseModel();

            try
            {
                if (eventId > 0)
                {
                    AbsentLogLogic  logLogic        = new AbsentLogLogic();
                    EventLogic      eventLogic      = new EventLogic();
                    AttendanceLogic attendanceLogic = new AttendanceLogic();

                    ABSENT_LOG eventLog        = logLogic.GetEntitiesBy(e => e.Event_Id == eventId).LastOrDefault();
                    ATTENDANCE eventAttendance = attendanceLogic.GetEntitiesBy(e => e.Event_Id == eventId).LastOrDefault();

                    if (eventLog == null && eventAttendance == null)
                    {
                        eventLogic.Delete(c => c.Id == eventId);

                        result.IsError = false;
                        result.Message = "Operation Successful!";
                    }
                    else
                    {
                        result.IsError = true;
                        result.Message = "Event is already attached to an attendance / absent log";
                    }
                }
                else
                {
                    result.IsError = true;
                    result.Message = "Invalid parameter";
                }
            }
            catch (Exception ex)
            {
                result.IsError = true;
                result.Message = ex.Message;
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 5
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 }));
        }