public HttpResponseMessage GetCourseListByStuIdAndTerm([FromBody] JObject stuIdAndTerm) { List <Dictionary <string, string> > retData = new List <Dictionary <string, string> >(); Dictionary <string, string> courseInfo; try { string signature = HttpUtil.GetAuthorization(Request); if (signature == null || !redis.IsSet(signature)) { return(new Response(2001, "未登录账户").Convert()); } var jsonParams = Request.GetQueryNameValuePairs().ToDictionary(k => k.Key, v => v.Value); string term = jsonParams["term"]; bool isLogin = redis.IsSet(signature); if (!isLogin) { return(new Response(2001, "未登录账户").Convert()); } string targetId = redis.Get <string>(signature); int termId = CourseDao.GetTermByName(term).id; List <Course> courseList = CourseDao.GetCoursesByStuIdAndTermId(targetId, termId).ToList(); foreach (Course c in courseList) { courseInfo = new Dictionary <string, string> { { "id", c.id.ToString() }, { "name", c.name }, }; if (c.term_id == null) { courseInfo.Add("semester", ""); } else { courseInfo.Add("semester", CourseDao.GetTermById((int)c.term_id).name); } courseInfo.Add("teacher", UserDao.GetUserById(c.teacher_id).name); courseInfo.Add("department", CourseDao.GetDepartmentById(c.department_id).name); retData.Add(courseInfo); } return(new Response(1001, "获取成功", retData).Convert()); } catch (Exception e) { ErrorLogUtil.WriteLogToFile(e, Request); return(Response.Error()); } }
public HttpResponseMessage DeleteTerm([FromBody] JObject terminfo) { try { string signature = HttpUtil.GetAuthorization(Request); if (signature == null || !redis.IsSet(signature)) { return(new Response(2001, "未登录账户").Convert()); } var jsonParams = HttpUtil.Deserialize(terminfo); string termname = jsonParams.name; bool login = redis.IsSet(signature); if (!login) { return(new Response(2001, "未登录账户").Convert()); } string targetId = redis.Get <string>(signature); if (UserDao.GetUserById(targetId).role != 4) { return(new Response(2002, "无权限删除学期信息").Convert()); } else { Term t = CourseDao.GetTermByName(termname); if (t != null) { if (CourseDao.GetAllCourse().Where(c => c.term_id == t.id).Count() > 0) { return(new Response(1002, "该学期仍有课程,无法删除").Convert()); } int res = UserDao.DeleteTerm(t); if (res == 1) { LogUtil.Log(Request, "删除学期", t.id.ToString(), targetId, UserDao.GetUserById(targetId).role); return(new Response(1002, "删除学期成功").Convert()); } } return(new Response(1002, "删除学期失败").Convert()); } } catch (Exception e) { ErrorLogUtil.WriteLogToFile(e, Request); return(new Response(4001).Convert());; } }
public HttpResponseMessage AddTerm([FromBody] JObject newTerm) { try { string signature = HttpUtil.GetAuthorization(Request); if (signature == null || !redis.IsSet(signature)) { return(new Response(2001, "未登录账户").Convert()); } Term term = new Term(); QuickCopy.Copy <Term>(newTerm, ref term); bool login = redis.IsSet(signature); if (!login) { return(new Response(2001, "未登录账户").Convert()); } string targetId = redis.Get <string>(signature); if (UserDao.GetUserById(targetId).role != 4) { return(new Response(2002, "无权限添加学期信息").Convert()); } else { Term temp = CourseDao.GetTermByName(term.name); if (temp != null) { return(new Response(1002, "添加学期失败").Convert()); } int res = UserDao.AddTerm(term); if (res == 1) { Term t = CourseDao.GetTermByName(term.name); LogUtil.Log(Request, "添加学期", t.id.ToString(), targetId, UserDao.GetUserById(targetId).role); return(new Response(1001, "添加学期成功").Convert()); } return(new Response(1001, "添加学期失败").Convert()); } } catch (Exception e) { ErrorLogUtil.WriteLogToFile(e, Request); return(new Response(4001).Convert());; } }