Ejemplo n.º 1
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));
        }
Ejemplo n.º 2
0
        public JsonResult SaveAbsenceRequest(long eventId, int absentType, string dateRange, string remark)
        {
            JsonResponseModel result = new JsonResponseModel();

            try
            {
                string[] dateRangeSplit = dateRange.Split('-');
                DateTime dateFrom       = DateTime.Now;
                DateTime dateTo         = DateTime.Now;

                if (!DateTime.TryParse(dateRangeSplit[0].Trim(), out dateFrom))
                {
                    dateFrom = new DateTime(1900, 1, 1);
                }
                if (!DateTime.TryParse(dateRangeSplit[1].Trim(), out dateTo))
                {
                    dateTo = new DateTime(1900, 1, 1);
                }

                if (dateFrom == new DateTime(1900, 1, 1) || dateTo == new DateTime(1900, 1, 1) || dateTo < dateFrom)
                {
                    result.IsError = true;
                    result.Message = "Invalid date range";
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }

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

                ABSENT_LOG absenceLog = _absentLogLogic.GetEntitiesBy(a => a.Event_Id == eventId && a.Student_Id == _student.Person_Id).LastOrDefault();
                if (absenceLog == null)
                {
                    absenceLog = new ABSENT_LOG();
                    absenceLog.Absent_Type_Id = absentType;
                    absenceLog.End_Date       = dateTo;
                    absenceLog.Start_Date     = dateFrom;
                    absenceLog.Event_Id       = eventId;
                    absenceLog.Remark         = remark;
                    absenceLog.Student_Id     = _student.Person_Id;

                    absenceLog = _absentLogLogic.Create(absenceLog);

                    result.IsError = false;
                    result.Message = "Absence request logged.";
                }
                else
                {
                    absenceLog.Absent_Type_Id = absentType;
                    absenceLog.End_Date       = dateTo;
                    absenceLog.Start_Date     = dateFrom;
                    absenceLog.Remark         = remark;

                    _absentLogLogic.Modify(absenceLog);

                    result.IsError = false;
                    result.Message = "Absence request modified.";
                }
            }
            catch (Exception ex)
            {
                result.IsError = true;
                result.Message = ex.Message;
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }