public ActionResult Edit(int id) { var courses = new CourseDao().ViewDeatil(id); SetViewBag(); return(View(courses)); }
public void OnGet(string courseId) { var id = int.Parse(courseId); var courseDao = new CourseDao(); Course = courseDao.GetById(id); var commentDao = new CommentDao(); Comments = commentDao.GetByCourseId(id); var usersId = HttpContext.Session.GetInt32("users_id"); if (usersId == null && HttpContext.Request.Cookies.ContainsKey("users_id")) { usersId = int.Parse(HttpContext.Request.Cookies["users_id"]); var usersName = HttpContext.Request.Cookies["users_name"]; HttpContext.Session.SetInt32("users_id", (int)usersId); HttpContext.Session.SetString("users_name", usersName); } UserIsAuthorized = usersId != null; if (UserIsAuthorized) { var usersCourses = new UsersDao().GetCourses((int)usersId); UserHasThisCourse = usersCourses.Select(c => c.Id).Contains(id); } }
public ActionResult UpdateCourses(COURSE course, HttpPostedFileBase postedFile) { if (ModelState.IsValid) { if (SaveImage(postedFile)) { if (postedFile != null) { course.Images = "images/" + postedFile.FileName; } var cou = new CourseDao(); var result = cou.Update(course); if (result) { return(Content("Update Success")); } else { return(Content("Update course unsuccessful")); } } else { return(Content("Update course unsuccessful")); } } return(Content("Update course unsuccessful")); }
// GET: Admins/Course public ActionResult Index(int PageNum = 1, int PageSize = 3, string search = null) { CourseDao CouDao = new CourseDao(); var listCou = CouDao.GetAllSearch(PageNum, PageSize, search); return(View(listCou)); }
public HttpResponseMessage EndCourse([FromBody] JObject Newcourse) { try { string signature = HttpUtil.GetAuthorization(Request); if (signature == null || !redis.IsSet(signature)) { return(new Response(2001, "未登录账户").Convert()); } Course course = new Course(); QuickCopy.Copy <Course>(Newcourse, ref course); bool login = redis.IsSet(signature); if (!login) { return(new Response(2001, "未登录账户").Convert()); } string targetId = redis.Get <string>(signature); Course oldCourse = CourseDao.GetCourseInfoById(course.id); if (oldCourse == null || oldCourse.teacher_id != targetId) { return(new Response(2002, "无权限修改该课程的信息").Convert()); } CourseDao.ChangeCourseInfo(course); LogUtil.Log(Request, "修改课程", course.id.ToString(), targetId, UserDao.GetUserById(targetId).role); return(new Response(1001, "修改课程信息成功").Convert()); } catch (Exception e) { ErrorLogUtil.WriteLogToFile(e, Request); return(new Response(4001).Convert());; } }
public SubjectDetailsViewModel(string id, MainWindowViewModel mainWindowViewModel) { _mainWindowViewModel = mainWindowViewModel; _adding = false; Subject = SubjectDao.FindById(id); var softwareList = SoftwareDao.FindAll(); foreach (var software in softwareList) { var softwareViewModel = new SoftwareViewModel(software) { IsChecked = Subject.RequiredSoftware.FirstOrDefault(s => s.Id == software.Id) != null }; SoftwareList.Add(softwareViewModel); } var courses = CourseDao.FindAll(); courses.ForEach(c => Courses.Add(c)); foreach (var subject in SubjectDao.FindAll()) { _takenIds.Add(subject.Id); } }
public HttpResponseMessage GetCourse() { Console.WriteLine("11"); try { Console.WriteLine("22"); 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); int id = Convert.ToInt32(jsonParams["courseID"]); Console.WriteLine(id); bool isLogin = redis.IsSet(signature); if (!isLogin) { return(new Response(2001, "未登录账户").Convert()); } Course course = CourseDao.GetCourseInfoById(id); return(new Response(1001, "获取成功", course).Convert()); } catch (Exception e) { ErrorLogUtil.WriteLogToFile(e, Request); return(Response.Error()); } }
// GET: Admin/Course public ActionResult Index(string searchString, int page = 1, int pageSize = 5) { var dao = new CourseDao(); var model = dao.ListAllPaging(searchString, page, pageSize); ViewBag.SearchString = searchString; return(View(model)); }
public JsonResult ChangeStatusCourse(long id) { var result = new CourseDao().ChangeStatusCourse(id); return(Json(new { status = result })); }
public void OnGet() { var courseDao = new CourseDao(); Courses = courseDao.GetAll(); var subjectDao = new SubjectDao(); Subjects = subjectDao.GetAll(); }
public HttpResponseMessage dealAppeal([FromBody] JObject paInfo) { try { string signature = HttpUtil.GetAuthorization(Request); if (signature == null || !redis.IsSet(signature)) { return(new Response(2001, "未登录账户").Convert()); } bool isLogin = redis.IsSet(signature); if (!isLogin) { return(new Response(2001, "未登录账户").Convert()); } string id = redis.Get <string>(signature); var jsonParams = HttpUtil.Deserialize(paInfo); //string id = jsonParams.id; string student_id = jsonParams.student_id; string assessor_id = jsonParams.assessor_id; int experiment_id = jsonParams.experiment_id; float score = Convert.ToSingle(jsonParams.score); User user = UserDao.GetUserById(id); Experiment exp = ExperimentDao.GetExperimentById(experiment_id); Course course = CourseDao.GetCourseInfoById((int)exp.course_id); ///权限控制,该课程助教与老师可以访问 if (CourseDao.GetAssistantsByCourseId(course.id).Where(a => a.student_id == id).Count() == 1 || id == course.teacher_id) { Peer_assessment peer_Assessment = new Peer_assessment(); QuickCopy.Copy(paInfo, ref peer_Assessment); peer_Assessment.appeal_status = 2; Peer_assessment OldPa = PeerAssessmentDao.getPeerAssessment(student_id, assessor_id, experiment_id); if (OldPa == null) { return(new Response(3001, "参数无效").Convert()); } if (PeerAssessmentDao.ChangePeerAssessmentInfo(peer_Assessment) == 1) { return(new Response(1001, "Success").Convert()); } else { throw new Exception("数据库操作异常"); } } else { return(new Response(2002, "无权访问").Convert()); } } catch (Exception e) { ErrorLogUtil.WriteLogToFile(e, Request); return(Response.Error()); } }
public CourseDetailsViewModel(string id) { _adding = false; Course = CourseDao.FindById(id); foreach (var course in CourseDao.FindAll()) { _takenIds.Add(course.Id); } }
public ActionResult Edit(course cou, HttpPostedFileBase photo) { TeacherDao teDao = new TeacherDao(); CourseDao couDao = new CourseDao(); if (ModelState.IsValid) { try { if (photo != null && photo.ContentLength > 0) { course exists_cou = couDao.GetById(cou.co_id); string image = String.Concat(cou.co_name, photo.FileName); if (!image.Equals(exists_cou.co_image)) { var image_old = Path.Combine(Server.MapPath("~/Areas/Admins/Content/Photo/course/"), System.IO.Path.GetFileName(exists_cou.co_image)); if (System.IO.File.Exists(image_old)) { System.IO.File.Delete(image_old); } var image_new = Path.Combine(Server.MapPath("~/Areas/Admins/Content/Photo/course/"), System.IO.Path.GetFileName(image)); photo.SaveAs(image_new); } cou.co_image = image; cou.co_updated_at = DateTime.Now; couDao.Update(cou); } else { course exists_cou = couDao.GetById(cou.co_id); cou.co_image = exists_cou.co_image; couDao.Update(cou); } return(RedirectToAction("Index")); } catch (Exception ex) { Console.WriteLine(ex.Message); return(View("Error")); } } else { ViewBag.lst_te = teDao.GetAll(); var teacher = teDao.GetAll(); SelectList list_te = new SelectList(teacher, "te_id", "te_name"); ViewBag.list_te = list_te; return(View(cou)); } }
public ActionResult UpdateCourse(int id) { if (Session["user"] == null) { return(View("Login")); } var course = new CourseDao().ViewDetail(id); SetCourseViewBag(); return(View(course)); }
public HttpResponseMessage getStusWithoutVMByExpId([FromBody] JObject expInfo) { try { List <Dictionary <string, string> > retData = new List <Dictionary <string, string> >(); Dictionary <string, string> stuidInfo; 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); bool isLogin = redis.IsSet(signature); if (!isLogin) { return(new Response(2001, "未登录账户").Convert()); } string userid = redis.Get <string>(signature); int expid = Convert.ToInt32(jsonParams["expid"]); Experiment exp = ExperimentDao.GetExperimentById(expid); if (exp.course_id == null) { return(new Response(1001, "该实验没有所属课程").Convert()); } int courseId = (int)ExperimentDao.GetExperimentById(expid).course_id; User user = UserDao.GetUserById(userid); if ((user.role == 2 && CourseDao.GetCourseInfoById(courseId).teacher_id == user.id) || (user.role == 1 && CourseDao.GetAssistantsByCourseId(courseId).Where(a => a.student_id == user.id).Count() != 0)) { List <User> stulist = CourseDao.GetStudentsById(courseId); List <VMConfig> vmlist = VMDao.GetVMsByVmName(exp.vm_name); foreach (User stu in stulist) { if (vmlist.Find(vm => vm.student_id.Equals(stu.id)) == null) { stuidInfo = new Dictionary <string, string> { { "id", stu.id }, }; retData.Add(stuidInfo); } } return(new Response(1001, "Success", retData).Convert()); } else { return(new Response(2001, "没有权限获取信息").Convert()); } } catch (Exception e) { ErrorLogUtil.WriteLogToFile(e, Request); return(Response.Error()); } }
public HttpResponseMessage ExportPeerScore([FromBody] JObject expId) { try { string signature = HttpUtil.GetAuthorization(Request); if (signature == null || !redis.IsSet(signature)) { return(new Response(2001, "未登录账户").Convert()); } bool login = redis.IsSet(signature); if (!login) { return(new Response(2001, "未登录账户").Convert()); } string id = redis.Get <string>(signature); var jsonParams = HttpUtil.Deserialize(expId); //string id = "16211084"; int expid = Convert.ToInt32(jsonParams.expid); User user = UserDao.GetUserById(id); Experiment exp = ExperimentDao.GetExperimentById(expid); Course course = CourseDao.GetCourseInfoById((int)exp.course_id); ///权限控制,该课程助教与老师可以访问 if (CourseDao.GetAssistantsByCourseId(course.id).Where(a => a.student_id == id).Count() == 1 || id == course.teacher_id) { List <Assignment> assignments = AssignmentDao.GetAssignmentsByExpId(expid); List <PeerResult> prResults = new List <PeerResult>(); foreach (var hw in assignments) { PeerAssessmentDao.CorrectScore(hw.student_id, expid); PeerAssessmentDao.ComputeFinalScore(hw.student_id, expid); try { prResults.Add(new PeerResult { id = hw.student_id, name = UserDao.GetUserById(hw.student_id).name, score = hw.score }); }catch (Exception e) {} } return(new Response(1001, "导出成功", prResults).Convert()); } else { return(new Response(2002, "无权进行操作").Convert()); } } catch (Exception e) { ErrorLogUtil.WriteLogToFile(e, Request); return(Response.Error()); } }
public JsonResult ExsitsCourseName(string cou_Coursename, int?cou_id) { CourseDao dao = new CourseDao(); List <course> lts_cou = dao.GetAll(); if (cou_id != null) { lts_cou.Remove(dao.GetById(cou_id)); //////////////?????????????????????? } return(Json(!lts_cou.Any(x => x.co_name.Trim().ToLower() == cou_Coursename.Trim().ToLower()), JsonRequestBehavior.AllowGet)); }
public void SetCourseViewBag(long?selectedId = null) { var dao = new DepartmentDao(); ViewBag.DepartmentID = new SelectList(dao.ListAll(), "Id", "DepartmentName", selectedId); var fac = new FacultyDao(); ViewBag.FacultyID = new SelectList(fac.ListAll(), "Id", "FirstName", selectedId); var cou = new CourseDao(); ViewBag.ID = new SelectList(cou.ListAll(), "Id", "CourseName", selectedId); }
public HttpResponseMessage UploadAssignment([FromBody] JObject assignmentInfo) { try { string signature = HttpUtil.GetAuthorization(Request); if (signature == null || !redis.IsSet(signature)) { return(new Response(2001, "未登录账户").Convert()); } bool isLogin = redis.IsSet(signature); if (!isLogin) { return(new Response(2001, "未登录账户").Convert()); } string id = redis.Get <string>(signature); var jsonParams = HttpUtil.Deserialize(assignmentInfo); int expID = jsonParams.exp_id; string file = jsonParams.file; Experiment experiment = ExperimentDao.GetExperimentById(expID); List <Course_student_mapping> csm = CourseDao.GetMapByStudentId(id).Where(m => m.course_id == experiment.course_id).ToList(); if (csm.Count > 0) { Assignment assignment = new Assignment { experiment_id = experiment.id, student_id = id, submit_time = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), is_standard = 0, file = file }; Assignment oldAssignment = AssignmentDao.GetAssignmentsByStuIdAndExpId(id, expID); if (oldAssignment != null) { LogUtil.Log(Request, "重新提交作业", expID.ToString(), id, 1, "", "", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")); AssignmentDao.DeleteAssignment(oldAssignment.id); AssignmentDao.AddAssignment(assignment); return(new Response(1001, "重新提交作业成功").Convert()); } else { LogUtil.Log(Request, "提交作业", expID.ToString(), id, 1, "", "", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")); AssignmentDao.AddAssignment(assignment); return(new Response(1001, "提交作业成功").Convert()); } } return(new Response(2002).Convert()); } catch (Exception e) { ErrorLogUtil.WriteLogToFile(e, Request); return(Response.Error()); } }
public CourseDetailsViewModel() { _adding = true; Course = new Course { DateOpened = DateTime.Now }; foreach (var course in CourseDao.FindAll()) { _takenIds.Add(course.Id); } }
public void DoDemo() { Task.Factory.StartNew(() => { if (DemoStopped()) { return; } Application.Current.Dispatcher.Invoke( () => { _viewModel.Id = _viewModel.SubjectDao.FindAvailableDemoId("DemoSubject"); }); if (DemoStopped()) { return; } Application.Current.Dispatcher.Invoke(() => { _viewModel.Name = "DemoSubjectName"; }); if (DemoStopped()) { return; } Application.Current.Dispatcher.Invoke(() => { _viewModel.Description = "DemoSubjectDescription"; }); if (DemoStopped()) { return; } var course = new CourseDao().FindById(DemoStateHandler.Instance.DemoCourseId); Application.Current.Dispatcher.Invoke(() => { _viewModel.Course = course; var selectedCourse = _viewModel.Courses.FirstOrDefault(c => c.Id == _viewModel.Course.Id); CourseComboBox.SelectedIndex = _viewModel.Courses.IndexOf(selectedCourse); }); if (DemoStopped()) { return; } Application.Current.Dispatcher.Invoke(() => { _viewModel.RequiredPlatform = Constants.Platform.Any; }); if (DemoStopped()) { return; } Application.Current.Dispatcher.Invoke(() => { _viewModel.RequiredTerms = 2; }); if (DemoStopped()) { return; } Application.Current.Dispatcher.Invoke(() => { Save(); DemoStateHandler.Instance.DemoSubjectId = _viewModel.Id; }); }); }
public Course SaveCourse() { if (_adding) { CourseDao.Add(Course); } else { CourseDao.Update(Course); } return(Course); }
public HttpResponseMessage AdminGetAllExperiments() { 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); int termId = 0; int courseId = 0; if (jsonParams.ContainsKey("termId")) { termId = Convert.ToInt32(jsonParams["termId"]); } if (jsonParams.ContainsKey("courseId")) { courseId = Convert.ToInt32(jsonParams["courseId"]); } bool isLogin = redis.IsSet(signature); if (!isLogin) { return(new Response(2001, "未登录账户").Convert()); } string id = redis.Get <string>(signature); //string id = "admin"; User user = UserDao.GetUserById(id); if (user.role < 3) { return(new Response(2002, "权限不足").Convert()); } List <Experiment> experiments = ExperimentDao.GetExperimentByCourseIdAndTermId(courseId, termId); if (user.role == 3) { List <Course> courses = CourseDao.GetCourseByDepId(user.department_id); experiments = experiments.Where(e => courses.Exists(c => c.id == e.course_id)).ToList(); } return(new Response(1001, "获取成功", ExperimentDao.GetExpRet(experiments)).Convert()); } catch (Exception e) { ErrorLogUtil.WriteLogToFile(e, Request); return(Response.Error()); } }
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 ActionResult Delete(int id) { CourseDao dao = new CourseDao(); course exists_cou = dao.GetById(id); var image_old = Path.Combine(Server.MapPath("~/Areas/Admins/Content/Photo/course/"), System.IO.Path.GetFileName(exists_cou.co_image)); if (System.IO.File.Exists(image_old)) { System.IO.File.Delete(image_old); } dao.Delete(id); return(RedirectToAction("Index")); }
public HttpResponseMessage StartPeerAssessment([FromBody] JObject expId) { try { string signature = HttpUtil.GetAuthorization(Request); if (signature == null || !redis.IsSet(signature)) { return(new Response(2001, "未登录账户").Convert()); } bool login = redis.IsSet(signature); if (!login) { return(new Response(2001, "未登录账户").Convert()); } string id = redis.Get <string>(signature); var jsonParams = HttpUtil.Deserialize(expId); //string id = "16211084"; int expid = Convert.ToInt32(jsonParams.expid); User user = UserDao.GetUserById(id); Experiment exp = ExperimentDao.GetExperimentById(expid); Course course = CourseDao.GetCourseInfoById((int)exp.course_id); if (exp.peer_assessment_start == true) { return(new Response(3001, "互评已开启,请勿重复操作").Convert()); } ///权限控制,该课程助教与老师可以访问 if (CourseDao.GetAssistantsByCourseId(course.id).Where(a => a.student_id == id).Count() == 1 || id == course.teacher_id) { AssignmentDao.SetStandardAssignment(expid, 4); AssignmentDao.AssignPeerAsssessment(expid); exp.peer_assessment_start = true; ExperimentDao.ChangeExperimentInfo(exp); return(new Response(1001, "开启成功").Convert()); } else { return(new Response(2002, "无权开启互评").Convert()); } } catch (Exception e) { ErrorLogUtil.WriteLogToFile(e, Request); return(Response.Error()); } }
public ActionResult Create(course cou, HttpPostedFileBase photo) { TeacherDao teDao = new TeacherDao(); CourseDao dao = new CourseDao(); if (ModelState.IsValid) { try { if (photo != null && photo.ContentLength > 0) { string image = String.Concat(photo.FileName); var path = Path.Combine(Server.MapPath("~/Areas/Admins/Content/Photo/Course/"), System.IO.Path.GetFileName(image)); photo.SaveAs(path); cou.co_image = image; cou.co_created_at = DateTime.Now; //var filename = Path.GetFileName(photo.FileName); //var path = Path.Combine(Server.MapPath("~/Areas/Admins/Content/Photo/Course/"), filename); //photo.SaveAs(path); //// Add avatar reference to model and save //cou.co_image = string.Concat("~/Areas/Admins/Content/Photo/Course/", filename); dao.Create(cou); } return(RedirectToAction("Index")); } catch (Exception ex) { Console.WriteLine(ex.Message); return(View("Error")); } } else { ViewBag.lst_te = teDao.GetAll(); DBIeltsContext db = new DBIeltsContext(); var teacher = db.teachers.ToList(); SelectList listTe = new SelectList(teacher, "te_id", "te_name"); ViewBag.list_te = listTe; return(View(cou)); } }
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 GetAssignments() { try { var jsonParams = Request.GetQueryNameValuePairs().ToDictionary(k => k.Key, v => v.Value); int expid = Convert.ToInt32(jsonParams["experiment_id"]); string signature = HttpUtil.GetAuthorization(Request); if (signature == null || !redis.IsSet(signature)) { return(new Response(2001, "未登录账户").Convert()); } bool isLogin = redis.IsSet(signature); if (!isLogin) { return(new Response(2001, "未登录账户").Convert()); } string id = redis.Get <string>(signature); User user = UserDao.GetUserById(id); Experiment exp = ExperimentDao.GetExperimentById(expid); Course course = CourseDao.GetCourseInfoById((int)exp.course_id); if (user.role < 2 && CourseDao.GetAssistantsByCourseId(course.id).Where(a => a.student_id == id).Count() == 0) { return(new Response(2002, "无权访问").Convert()); } if (user.role == 2 && id != course.teacher_id) { return(new Response(2002, "无权访问").Convert()); } if (user.role == 3 && user.department_id != course.department_id) { return(new Response(2002, "无权访问").Convert()); } List <Assignment> assignments = AssignmentDao.GetAssignmentsByExpId(expid); return(new Response(1001, "成功", assignments).Convert()); } catch (Exception e) { ErrorLogUtil.WriteLogToFile(e, Request); return(Response.Error()); } }
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());; } }