Exemplo n.º 1
0
        [HttpGet]                       //定义访问方式(Post或Get方法)
        public object GetKnowledge()    //返回数据的函数,如果是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.WhereEqualTo("courseId", courseId);
            query.OrderBy("id");
            var future = Bmob.FindTaskAsync <Knowledge>("Knowledge", query);

            try
            {
                knowledgeList = future.Result.results;
                foreach (var k in knowledgeList)     //由于BmobModel中有BmobInt类型不能直接显示到页面中,所以需要对字段的类型进行处理,变为相对应的ViewModel格式。
                {
                    Knowledge_View knowledge_view = new Knowledge_View();
                    knowledge_view.id       = k.id.Get();
                    knowledge_view.name     = k.name;
                    knowledge_view.courseId = k.courseId.Get();
                    knowledge_view.unitId   = k.unitId.Get();

                    kList.Add(knowledge_view);
                }
            }catch
            {
            }
            return(ResultToJson.toJson(kList));      //返回数据需要json格式
        }
Exemplo n.º 2
0
        public object GetSelectedKnowledge(int unitId)
        {
            String     objectId = "";
            HttpCookie cookie1  = HttpContext.Current.Request.Cookies["CurrentCourse"];
            String     id       = cookie1["CourseId"];
            int        courseId = int.Parse(id);
            var        query    = new BmobQuery();

            query.WhereEqualTo("courseId", courseId);
            var f = Bmob.FindTaskAsync <Knowledge>("Knowledge", query);

            try
            {
                query.WhereEqualTo("unitId", unitId);
                var future = Bmob.FindTaskAsync <Knowledge>("Knowledge", query);
                knowledgeList = future.Result.results;
                foreach (var k in knowledgeList)     //由于BmobModel中有BmobInt类型不能直接显示到页面中,所以需要对字段的类型进行处理,变为相对应的ViewModel格式。
                {
                    objectId = f.Result.results[0].objectId;
                    Knowledge_View knowledge_view = new Knowledge_View();
                    knowledge_view.id       = k.id.Get();
                    knowledge_view.name     = k.name;
                    knowledge_view.courseId = k.courseId.Get();
                    knowledge_view.unitId   = k.unitId.Get();
                    kList.Add(knowledge_view);
                }
                return(ResultToJson.toJson(kList));
            }
            catch
            {
                return("获取失败");
            }
        }
Exemplo n.º 3
0
        [HttpGet]                       //定义访问方式(Post或Get方法)
        public object Get(int unitId)   //返回数据的函数,如果是Get方法则方法名为Get开头,若是Post则使用Post开头。
        {
            var query = new BmobQuery();

            query.Limit(300);
            query.WhereEqualTo("unitId", unitId);
            var future = Bmob.FindTaskAsync <Knowledge>("Knowledge", query);

            knowledgeList = future.Result.results;
            foreach (var k in knowledgeList)     //由于BmobModel中有BmobInt类型不能直接显示到页面中,所以需要对字段的类型进行处理,变为相对应的ViewModel格式。
            {
                Knowledge_View knowledge_view = new Knowledge_View();
                knowledge_view.id       = k.id.Get();
                knowledge_view.name     = k.name;
                knowledge_view.courseId = k.courseId.Get();
                knowledge_view.unitId   = k.unitId.Get();

                kList.Add(knowledge_view);
            }
            return(ResultToJson.toJson(kList));      //返回数据需要json格式
        }
Exemplo n.º 4
0
        [HttpPost]                                                               //定义访问方式(Post或Get方法)
        public object PostAddKnowledge([FromBody] Knowledge_View knowledge_view) //返回数据的函数,如果是Get方法则方法名为Get开头,若是Post则使用Post开头。
        {
            String    result    = "";
            Knowledge knowledge = new Knowledge();

            knowledge.id       = knowledge_view.id;
            knowledge.name     = knowledge_view.name;
            knowledge.courseId = knowledge_view.courseId;
            knowledge.unitId   = knowledge_view.unitId;
            var future = Bmob.CreateTaskAsync("Knowledge", knowledge);

            try
            {
                result = future.Result.objectId;
            }
            catch
            {
                result = "失败";
            }
            return(result);
        }