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)); }
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)); }