|
@@ -224,7 +224,8 @@ namespace TEAMModelOS.Controllers
|
|
|
sql.Append("select value(c) from c ");
|
|
|
Dictionary<string, object> dict = new Dictionary<string, object>();
|
|
|
//处理id
|
|
|
- if (request.ids.IsNotEmpty()) {
|
|
|
+ if (request.ids.IsNotEmpty())
|
|
|
+ {
|
|
|
dict.Add("id", request.ids.ToArray());
|
|
|
}
|
|
|
string school_code = request.code;
|
|
@@ -312,51 +313,33 @@ namespace TEAMModelOS.Controllers
|
|
|
[ProducesDefaultResponseType]
|
|
|
//[AuthToken(Roles = "Teacher")]
|
|
|
[HttpPost("upsert-management")]
|
|
|
- public async Task<IActionResult> upsertCourseManagement(JsonElement requert)
|
|
|
+ public async Task<IActionResult> upsertCourseManagement(CourseManagement requert)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
CourseManagement course = new CourseManagement();
|
|
|
//course = room.ToObject<CourseManagement>();
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
- //string code = requert.code;
|
|
|
- requert.TryGetProperty("code", out JsonElement schoolCodeJson);
|
|
|
-
|
|
|
-
|
|
|
- //[Jeff] Class表追加課程安排 (Class.courses)
|
|
|
-
|
|
|
- //[Jeff] Course表追加課程安排 (Course.classes)
|
|
|
- if (requert.TryGetProperty("courses", out JsonElement coursesJson))
|
|
|
- {
|
|
|
- foreach (var courseInfo in coursesJson.EnumerateArray())
|
|
|
- {
|
|
|
- //var response = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(requert.id, new PartitionKey($"CourseManagement-{code}"));
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- //[Jeff] CourseManagement表廢除
|
|
|
- //requert.code = "CourseManagement-" + requert.code;
|
|
|
+ string code = requert.code;
|
|
|
+ requert.code = "CourseManagement-" + requert.code;
|
|
|
/* if (requert.scope.Equals) {
|
|
|
|
|
|
}*/
|
|
|
- //var response = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(requert.id, new PartitionKey($"CourseManagement-{code}"));
|
|
|
- //if (response.Status == 200)
|
|
|
- //{
|
|
|
- // /*using var json = await JsonDocument.ParseAsync(response.ContentStream);
|
|
|
- // CourseManagement courseManagement = json.ToObject<CourseManagement>();
|
|
|
- // courseManagement.courses = requert.courses;*/
|
|
|
- // //return Ok(new { error = ResponseCode.DATA_EXIST, V = "课程编码已经存在!" });
|
|
|
- // course = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").ReplaceItemAsync(requert,requert.id, new PartitionKey($"CourseManagement-{code}"));
|
|
|
+ var response = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(requert.id, new PartitionKey($"CourseManagement-{code}"));
|
|
|
+ if (response.Status == 200)
|
|
|
+ {
|
|
|
+/* using var json = await JsonDocument.ParseAsync(response.ContentStream);
|
|
|
+ CourseManagement courseManagement = json.ToObject<CourseManagement>();
|
|
|
+ courseManagement.courses = requert.courses;*/
|
|
|
+ //return Ok(new { error = ResponseCode.DATA_EXIST, V = "课程编码已经存在!" });
|
|
|
+ course = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").ReplaceItemAsync(requert, requert.id, new PartitionKey($"CourseManagement-{code}"));
|
|
|
|
|
|
- //}
|
|
|
- //else
|
|
|
- //{
|
|
|
- // course = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").CreateItemAsync(requert, new PartitionKey($"CourseManagement-{code}"));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ course = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").CreateItemAsync(requert, new PartitionKey($"CourseManagement-{code}"));
|
|
|
|
|
|
- //}
|
|
|
- ////[Jeff] CourseManagement表廢除
|
|
|
+ }
|
|
|
|
|
|
|
|
|
return Ok(new { course });
|
|
@@ -380,7 +363,7 @@ namespace TEAMModelOS.Controllers
|
|
|
public async Task<IActionResult> FindManagement(JsonElement requert)
|
|
|
{
|
|
|
//if (!requert.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
|
- if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest(); //school_code
|
|
|
+ if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest();
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
List<object> courses = new List<object>();
|
|
|
StringBuilder sql = new StringBuilder();
|
|
@@ -397,38 +380,17 @@ namespace TEAMModelOS.Controllers
|
|
|
dict.Remove("code");
|
|
|
}
|
|
|
AzureCosmosQuery cosmosDbQuery = SQLHelper.GetSQL(dict, sql);
|
|
|
- //[Jeff] 取得Class表中課程安排 (Class.courses)
|
|
|
- if (dict.TryGetValue("id", out object classId)) {
|
|
|
- var response = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(classId.ToString(), new PartitionKey($"Class-{code}"));
|
|
|
- if (response.Status == 200)
|
|
|
+ await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"CourseManagement-{code}") }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
{
|
|
|
- dynamic courseResult = new ExpandoObject();
|
|
|
- using var json = await JsonDocument.ParseAsync(response.ContentStream);
|
|
|
- courseResult.id = json.RootElement.GetProperty("id").GetString();
|
|
|
- courseResult.courses = new List<coursesInClass>();
|
|
|
- if (json.RootElement.TryGetProperty("courses", out JsonElement coursesJobj))
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
{
|
|
|
- courseResult.courses = coursesJobj.ToObject<object>();
|
|
|
+ courses.Add(obj.ToObject<object>());
|
|
|
}
|
|
|
- courses.Add(courseResult);
|
|
|
}
|
|
|
}
|
|
|
- ////[Jeff] 取得Class表中課程安排 (Class.courses)
|
|
|
-
|
|
|
- //[Jeff] CourseManagement表廢除
|
|
|
- //await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"CourseManagement-{code}") }))
|
|
|
- //{
|
|
|
- // using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
- // if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
- // {
|
|
|
- // foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
- // {
|
|
|
- // courses.Add(obj.ToObject<object>());
|
|
|
- // }
|
|
|
- // }
|
|
|
- //}
|
|
|
- ////[Jeff] CourseManagement表廢除
|
|
|
-
|
|
|
/* List<object> courses = new List<object>();
|
|
|
var response = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(id.ToString(), new PartitionKey($"CourseManagement-{code}"));
|
|
|
if (response.Status == 200)
|