public object PostFile([FromBody] Resource_View resourceView) { HttpCookie cookie1 = HttpContext.Current.Request.Cookies["CurrentCourse"]; String id = cookie1["CourseId"]; int courseId = int.Parse(id); String a = ""; // String objectId = ""; Resource resource = new Resource(); resource.id = BmobInput.Parse <BmobInt>(resourceView.id); resource.file = resourceView.file; resource.type = resourceView.type; resource.courseId = BmobInput.Parse <BmobInt>(courseId); resource.unitId = BmobInput.Parse <BmobInt>(resourceView.unitId); resource.knowledgeId = BmobInput.Parse <BmobInt>(resourceView.knowledgeId); //var query = new BmobQuery(); //query.WhereEqualTo("id", course.id); var f = Bmob.CreateTaskAsync("Resource", resource); try { a = f.Result.objectId; } catch { a = "失败"; } return(a); }
public object GetResourceInfo(int unitId, int knowledgeId) { HttpCookie cookie1 = HttpContext.Current.Request.Cookies["CurrentCourse"]; String id = cookie1["CourseId"]; int courseId = int.Parse(id); var query = new BmobQuery(); query.WhereEqualTo("courseId", courseId); if (unitId != 0) { var q1 = new BmobQuery(); q1.WhereEqualTo("unitId", unitId); query.And(q1); } if (knowledgeId != 0) { var q1 = new BmobQuery(); q1.WhereEqualTo("knowledgeId", knowledgeId); query.And(q1); } var future = Bmob.FindTaskAsync <Resource>("Resource", query); try { resourceList = future.Result.results; List <Resource_View> resourceView = new List <Resource_View>(); foreach (var resource in resourceList) { Resource_View resources = new Resource_View(); resources.id = resource.id.Get(); resources.fileUrl = resource.file.url; resources.fileName = resource.file.filename; resources.type = resource.type; resourceView.Add(resources); } return(ResultToJson.toJson(resourceView)); } catch { return("fail"); } }