public object GetExaminationDetails(int id) { var query = new BmobQuery(); query.WhereEqualTo("id", id); var future = Bmob.FindTaskAsync <Examination>("Examination", query); examinationList = future.Result.results; try { examinationList = future.Result.results; foreach (var e in examinationList) //由于BmobModel中有BmobInt类型不能直接显示到页面中,所以需要对字段的类型进行处理,变为相对应的ViewModel格式。 { Examination_View examination_View = new Examination_View(); examination_View.objectId = e.objectId; examination_View.name = e.name; examination_View.questionList = e.questionList; examination_View.id = e.id.Get(); examination_View.difficulty = e.difficulty.Get(); examination_View.courseId = e.courseId.Get(); //if(examination_View.questionList != "") //{ // string[] results = examination_View.questionList.Split(new[] { ';' }); // examination_View.examQuestion = Array.ConvertAll<string, int>(results, s => int.Parse(s)); //} eList.Add(examination_View); } } catch { } return(ResultToJson.toJson(eList)); //返回数据需要json格式 }
[HttpGet] //定义访问方式(Post或Get方法) public object Get() //返回数据的函数,如果是Get方法则方法名为Get开头,若是Post则使用Post开头。 { HttpCookie cookie1 = HttpContext.Current.Request.Cookies["CurrentCourse"]; String id = cookie1["CourseId"]; int courseId = int.Parse(id); var query = new BmobQuery(); query.Limit(300); query.WhereEqualTo("courseId", courseId); query.OrderBy("id"); var future = Bmob.FindTaskAsync <Examination>("Examination", query); try { examinationList = future.Result.results; foreach (var e in examinationList) //由于BmobModel中有BmobInt类型不能直接显示到页面中,所以需要对字段的类型进行处理,变为相对应的ViewModel格式。 { Examination_View examination_View = new Examination_View(); examination_View.objectId = e.objectId; examination_View.name = e.name; examination_View.questionList = e.questionList; examination_View.id = e.id.Get(); examination_View.difficulty = e.difficulty.Get(); examination_View.courseId = e.courseId.Get(); eList.Add(examination_View); } } catch { } return(ResultToJson.toJson(eList)); //返回数据需要json格式 }
public object PostSavePaper([FromBody] Examination_View examination_View) { HttpCookie cookie1 = HttpContext.Current.Request.Cookies["CurrentCourse"]; String id = cookie1["CourseId"]; int courseId = int.Parse(id); Examination examination = new Examination(); examination.id = BmobInput.Parse <BmobInt> (examination_View.id); examination.name = examination_View.name; examination.questionList = examination_View.questionList; examination.difficulty = BmobInput.Parse <BmobDouble>(examination_View.difficulty); examination.courseId = BmobInput.Parse <BmobInt>(courseId); var future = Bmob.CreateTaskAsync("Examination", examination); try { String objectId = future.Result.objectId; return(objectId); } catch { return("获取失败"); } }