コード例 #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));
        }
コード例 #2
0
        public JsonResult UpdateAbsentlog(string updateArray)
        {
            JsonResponseModel model = new JsonResponseModel();

            try
            {
                int modifiedCount = 0;
                if (string.IsNullOrEmpty(updateArray))
                {
                    return(null);
                }
                List <AbsentLogModel> absentLogModels = JsonConvert.DeserializeObject <List <AbsentLogModel> >(updateArray);
                AbsentLogLogic        absentLogLogic  = new AbsentLogLogic();
                UserLogic             userLogic       = new UserLogic();

                USER user = userLogic.GetEntityBy(u => u.Username == User.Identity.Name);

                for (int i = 0; i < absentLogModels.Count; i++)
                {
                    long       id        = absentLogModels[i].Id;
                    ABSENT_LOG absentLog = absentLogLogic.GetEntityBy(a => a.Id == id);

                    if (absentLog != null)
                    {
                        if (absentLogModels[i].Accept)
                        {
                            absentLog.Approved = absentLogModels[i].Accept;
                        }
                        if (absentLogModels[i].Decline)
                        {
                            absentLog.Approved      = !absentLogModels[i].Decline;
                            absentLog.Reject_Reason = absentLogModels[i].RejectReason;
                            absentLog.Remark        = absentLogModels[i].Remark;
                        }

                        absentLog.User_Id = user.Id;

                        var modified = absentLogLogic.Modify(absentLog);
                        if (modified)
                        {
                            modifiedCount += 1;
                        }
                    }
                }
                if (modifiedCount > 0)
                {
                    model.IsError = false;
                    model.Message = "Operation Successful";
                }
                else
                {
                    model.IsError = true;
                    model.Message = "Nothing found to be Updated";
                }
            }
            catch (Exception ex)
            {
                model.IsError = true;
                model.Message = ex.Message + "Operation Failed";
            }
            return(Json(model, JsonRequestBehavior.AllowGet));
        }
コード例 #3
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));
        }