|
@@ -112,8 +112,38 @@ namespace TEAMModelOS.Controllers
|
|
case "remove":
|
|
case "remove":
|
|
//將學生基本資料內的classId、no、groupId及groupName寫入null
|
|
//將學生基本資料內的classId、no、groupId及groupName寫入null
|
|
(List<string> studs, List<string> nonexistentIds, List<string> errorIds) retRemove = await removeStudentClassInfo(schoolId.GetString(), request.GetProperty("students").EnumerateArray());
|
|
(List<string> studs, List<string> nonexistentIds, List<string> errorIds) retRemove = await removeStudentClassInfo(schoolId.GetString(), request.GetProperty("students").EnumerateArray());
|
|
-
|
|
|
|
return Ok(new { code = $"Base-{schoolId.GetString()}", ids = retRemove.studs, retRemove.nonexistentIds, retRemove.errorIds });
|
|
return Ok(new { code = $"Base-{schoolId.GetString()}", ids = retRemove.studs, retRemove.nonexistentIds, retRemove.errorIds });
|
|
|
|
+ case "avatar":
|
|
|
|
+ if (request.TryGetProperty("avatar", out JsonElement _avatar) && _avatar.ValueKind.Equals(JsonValueKind.Array))
|
|
|
|
+ {
|
|
|
|
+ List<Avatar> avatars = _avatar.ToObject<List<Avatar>>();
|
|
|
|
+ if (avatars.IsNotEmpty())
|
|
|
|
+ {
|
|
|
|
+ List<Student> studentsp = new List<Student>();
|
|
|
|
+ string insql = string.Join(',', avatars.Select(x => $"'{x.studentId}'"));
|
|
|
|
+ string sql = $"select value(c) from c where c.id in ({insql}) ";
|
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student")
|
|
|
|
+ .GetItemQueryIterator<Student>(sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Base-{schoolId}") }))
|
|
|
|
+ {
|
|
|
|
+ studentsp.Add(item);
|
|
|
|
+ }
|
|
|
|
+ (string url, string sas) = _azureStorage.GetBlobContainerSAS99Year($"{schoolId}", BlobContainerSasPermissions.Read);
|
|
|
|
+ foreach (Student student in studentsp)
|
|
|
|
+ {
|
|
|
|
+ Avatar avatar = avatars.Find(x => x.studentId.Equals(student.id));
|
|
|
|
+ student.picture = avatar != null ? $"{avatar.picture}?{sas}" : null;
|
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync<Student>(student, student.id, new PartitionKey(student.code));
|
|
|
|
+ }
|
|
|
|
+ return Ok(new { students = studentsp.Select(x=> new {x.id,x.picture,x.code,x.name }) });
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ return BadRequest();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ return BadRequest();
|
|
|
|
+ }
|
|
|
|
+
|
|
default:
|
|
default:
|
|
return BadRequest();
|
|
return BadRequest();
|
|
}
|
|
}
|
|
@@ -125,7 +155,10 @@ namespace TEAMModelOS.Controllers
|
|
}
|
|
}
|
|
return BadRequest();
|
|
return BadRequest();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ public record Avatar {
|
|
|
|
+ public string studentId { get; set; }
|
|
|
|
+ public string picture { get; set; }
|
|
|
|
+ }
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 整理前端匯入的學生資訊
|
|
/// 整理前端匯入的學生資訊
|
|
/// </summary>
|
|
/// </summary>
|