public ApiBaseResult LeaveLesson([FromBody] LeaveClassModel data) { ApiBaseResult result; if (data != null) { if (data.Check()) { result = Check(data.access_token); if (result == null) { return(leaveClass(data)); } else { return(result); } } else { result = new ApiBaseResult(); result.result = "error"; result.messages = "参数格式错误或缺少参数!"; return(result); } } else { result = new ApiBaseResult(); result.result = "error"; result.messages = "参数错误!"; return(result); } }
private ApiBaseResult leaveClass(LeaveClassModel data) { ApiBaseResult result = new ApiBaseResult(); try { #region 请假操作 string access_token = data.access_token; string ST_Num = access_token.Substring(0, access_token.IndexOf("_")); string LL_Type = "上课请假备案(" + data.leave_child_type + ")"; string leaveDate = data.leave_date; string leaveTime = ""; string backDate = data.leave_date; string backTime = ""; string leaveReason = data.leave_reason; string lesson = data.lesson; if (lesson == "1") { leaveTime = "08:00"; backTime = "09:40"; } if (lesson == "2") { leaveTime = "10:10"; backTime = "11:50"; } if (lesson == "3") { leaveTime = "14:00"; backTime = "15:40"; } if (lesson == "4") { leaveTime = "16:00"; backTime = "17:40"; } if (lesson == "5") { leaveTime = "18:30"; backTime = "21:00"; } string teacher = data.teacher_name; string LV_NUM = DateTime.Now.ToString("yyMMdd");//流水号生成 //DateTime time_go = Convert.ToDateTime(leaveDate + " " + leaveTime + ":00"); //DateTime time_back = Convert.ToDateTime(backDate + " " + backTime + ":00"); DateTime time_go = Convert.ToDateTime(leaveDate + " " + leaveTime); DateTime time_back = Convert.ToDateTime(backDate + " " + backTime); var exist = from T_LeaveList in db.T_LeaveList where ((T_LeaveList.StudentID == ST_Num) && (T_LeaveList.Lesson == lesson) && (T_LeaveList.TypeID == 3) && (T_LeaveList.TimeLeave == time_go)) select T_LeaveList; if (exist.Any()) { bool flag = true; foreach (qingjia_MVC.Models.T_LeaveList leaveList in exist.ToList()) { if (leaveList.StateBack == "0") { flag = false; break; } } if (flag) { //插入数据库操作 if (Insert_LeaveList(LV_NUM, ST_Num, LL_Type, time_go, time_back, leaveReason, null, null, null, null, null, lesson, teacher) == 1) { result.result = "success"; result.messages = "请假申请成功!"; } else { result.result = "error"; result.messages = "数据库提交失败,请重新尝试!"; } } else { result.result = "error"; result.messages = "您已提交过此时间段的请假申请,请不要重复提交!"; } } else { //插入数据库操作 if (Insert_LeaveList(LV_NUM, ST_Num, LL_Type, time_go, time_back, leaveReason, null, null, null, null, null, lesson, teacher) == 1) { result.result = "success"; result.messages = "请假申请成功"; } else { result.result = "error"; result.messages = "数据库提交失败,请重新尝试!"; } } #endregion } catch { result.result = "error"; result.messages = "请假失败,请检查参数格式"; } return(result); }