|
@@ -50,6 +50,7 @@ namespace TEAMModelOS.Controllers
|
|
{
|
|
{
|
|
//TODO : 權限檢查、學校檢查。
|
|
//TODO : 權限檢查、學校檢查。
|
|
if (!request.TryGetProperty("grant_type", out JsonElement grant_type) || !request.TryGetProperty("schoolId", out JsonElement schoolId)) return BadRequest();
|
|
if (!request.TryGetProperty("grant_type", out JsonElement grant_type) || !request.TryGetProperty("schoolId", out JsonElement schoolId)) return BadRequest();
|
|
|
|
+
|
|
switch (grant_type.GetString())
|
|
switch (grant_type.GetString())
|
|
{
|
|
{
|
|
case "create":
|
|
case "create":
|
|
@@ -68,7 +69,9 @@ namespace TEAMModelOS.Controllers
|
|
if (existClass.ContainsKey(item.Key))
|
|
if (existClass.ContainsKey(item.Key))
|
|
{
|
|
{
|
|
//將學生加入教室內。
|
|
//將學生加入教室內。
|
|
- (List<string> existId, List<string> existNo) retJoinClass = await joinClass(schoolId.GetString(), classStudent);
|
|
|
|
|
|
+ var classStudents
|
|
|
|
+ = new Dictionary<string, List<(string id, string name, string no)>>() { { item.Key, classStudent[item.Key].Select(o => (o.id, o.name, o.no)).ToList() } };
|
|
|
|
+ (List<string> existId, List<string> existNo) retJoinClass = await joinClass(schoolId.GetString(), classStudents);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
@@ -200,12 +203,17 @@ namespace TEAMModelOS.Controllers
|
|
using var stream = new MemoryStream();
|
|
using var stream = new MemoryStream();
|
|
using var writer = new Utf8JsonWriter(stream);
|
|
using var writer = new Utf8JsonWriter(stream);
|
|
writer.WriteStartObject();
|
|
writer.WriteStartObject();
|
|
- if (current.TryGetProperty("name", out var tmpName))
|
|
|
|
|
|
+ if (current.TryGetProperty("name", out var tmpName) && !string.IsNullOrWhiteSpace(tmpName.GetString()))
|
|
{
|
|
{
|
|
writer.WriteString("name", tmpName.GetString());
|
|
writer.WriteString("name", tmpName.GetString());
|
|
studentInfo.name = tmpName.GetString();
|
|
studentInfo.name = tmpName.GetString();
|
|
}
|
|
}
|
|
else writer.WriteNull("name");
|
|
else writer.WriteNull("name");
|
|
|
|
+ if (current.TryGetProperty("gender", out var tmpGender) && !string.IsNullOrWhiteSpace(tmpGender.GetString()))
|
|
|
|
+ {
|
|
|
|
+ writer.WriteString("gender", tmpGender.GetString());
|
|
|
|
+ }
|
|
|
|
+ else writer.WriteNull("gender");
|
|
writer.WriteString("pk", $"Base");
|
|
writer.WriteString("pk", $"Base");
|
|
writer.WriteString("code", $"Base-{schoolId}");
|
|
writer.WriteString("code", $"Base-{schoolId}");
|
|
writer.WriteString("id", id.GetString());
|
|
writer.WriteString("id", id.GetString());
|
|
@@ -537,6 +545,7 @@ namespace TEAMModelOS.Controllers
|
|
while (accounts.MoveNext())
|
|
while (accounts.MoveNext())
|
|
{
|
|
{
|
|
JsonElement account = accounts.Current;
|
|
JsonElement account = accounts.Current;
|
|
|
|
+
|
|
listStudent.Add((account.GetProperty("id").GetString(), account.GetProperty("name").GetString(), account.GetProperty("picture").GetString(), account.GetProperty("year").GetString()));
|
|
listStudent.Add((account.GetProperty("id").GetString(), account.GetProperty("name").GetString(), account.GetProperty("picture").GetString(), account.GetProperty("year").GetString()));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -768,10 +777,12 @@ namespace TEAMModelOS.Controllers
|
|
if (student.TryGetProperty("classId", out var tmpClassId) && !string.IsNullOrWhiteSpace(tmpClassId.GetString()))
|
|
if (student.TryGetProperty("classId", out var tmpClassId) && !string.IsNullOrWhiteSpace(tmpClassId.GetString()))
|
|
{
|
|
{
|
|
classId = tmpClassId.GetString();
|
|
classId = tmpClassId.GetString();
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(classId) && classStudent.ContainsKey(classId)) classStudent[classId].Add(id);
|
|
|
|
+ else classStudent.Add(classId, new List<string>() { id });
|
|
}
|
|
}
|
|
-
|
|
|
|
- if (!string.IsNullOrWhiteSpace(classId) && classStudent.ContainsKey(classId)) classStudent[classId].Add(id);
|
|
|
|
- else classStudent.Add(classId, new List<string>() { id });
|
|
|
|
|
|
+
|
|
|
|
+ //如果沒給教室?但卻有加入過教室
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
foreach (var c in classStudent)
|
|
foreach (var c in classStudent)
|
|
@@ -844,7 +855,7 @@ namespace TEAMModelOS.Controllers
|
|
/// 將學生加入教室,並且會比對id及座號是否有重複
|
|
/// 將學生加入教室,並且會比對id及座號是否有重複
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
- private async Task<(List<string> existId, List<string> existNo)> joinClass(string schoolId, Dictionary<string, List<(string id, string name, string no, string year)>> classStudents)
|
|
|
|
|
|
+ private async Task<(List<string> existId, List<string> existNo)> joinClass(string schoolId, Dictionary<string, List<(string id, string name, string no)>> classStudents)
|
|
{
|
|
{
|
|
try
|
|
try
|
|
{
|
|
{
|
|
@@ -860,6 +871,7 @@ namespace TEAMModelOS.Controllers
|
|
importItem.Value.RemoveAll(o => o.id.Equals(id));
|
|
importItem.Value.RemoveAll(o => o.id.Equals(id));
|
|
existId.Add(id);
|
|
existId.Add(id);
|
|
}
|
|
}
|
|
|
|
+
|
|
var duplicateNo = importItem.Value.GroupBy(o => o.no).Where(o => o.Count() > 1).Select(o => o.Key).ToList();
|
|
var duplicateNo = importItem.Value.GroupBy(o => o.no).Where(o => o.Count() > 1).Select(o => o.Key).ToList();
|
|
foreach (var no in duplicateNo)
|
|
foreach (var no in duplicateNo)
|
|
{
|
|
{
|
|
@@ -889,7 +901,7 @@ namespace TEAMModelOS.Controllers
|
|
if (existStudents.GetArrayLength() != 0)
|
|
if (existStudents.GetArrayLength() != 0)
|
|
{
|
|
{
|
|
//若學生數量不為0,代表裡面已有資料,故要檢查是否有重複
|
|
//若學生數量不為0,代表裡面已有資料,故要檢查是否有重複
|
|
- List<(string id, string name, string no, string year)> tmpStuds = new List<(string id, string name, string no, string year)>();
|
|
|
|
|
|
+ List<(string id, string name, string no)> tmpStuds = new List<(string id, string name, string no)>();
|
|
//取得雲端教室的名單,並檢查id及座號是否重複
|
|
//取得雲端教室的名單,並檢查id及座號是否重複
|
|
var studs = existStudents.EnumerateArray();
|
|
var studs = existStudents.EnumerateArray();
|
|
|
|
|
|
@@ -900,16 +912,16 @@ namespace TEAMModelOS.Controllers
|
|
string id = stud.GetProperty("id").GetString();
|
|
string id = stud.GetProperty("id").GetString();
|
|
string no = stud.GetProperty("no").GetString();
|
|
string no = stud.GetProperty("no").GetString();
|
|
string name = stud.GetProperty("name").GetString();
|
|
string name = stud.GetProperty("name").GetString();
|
|
- string year = stud.GetProperty("year").GetString();
|
|
|
|
|
|
+ //string year = stud.GetProperty("year").GetString();
|
|
|
|
|
|
- tmpStuds.Add((id, name, no, year));
|
|
|
|
|
|
+ tmpStuds.Add((id, name, no));
|
|
}
|
|
}
|
|
|
|
|
|
//先檢查ID及座號是否重複,重複的則記錄在duplicate內
|
|
//先檢查ID及座號是否重複,重複的則記錄在duplicate內
|
|
var duplicate = tmpStuds.Where(
|
|
var duplicate = tmpStuds.Where(
|
|
a => importItem.Value.Exists(t => a.no.Contains(t.no))
|
|
a => importItem.Value.Exists(t => a.no.Contains(t.no))
|
|
|| importItem.Value.Exists(t => a.id.Contains(t.id))).ToList();
|
|
|| importItem.Value.Exists(t => a.id.Contains(t.id))).ToList();
|
|
- foreach (var (id, name, no, year) in duplicate)
|
|
|
|
|
|
+ foreach (var (id, name, no) in duplicate)
|
|
{
|
|
{
|
|
importItem.Value.RemoveAll(o => o.id.Equals(id) || o.no.Equals(no));
|
|
importItem.Value.RemoveAll(o => o.id.Equals(id) || o.no.Equals(no));
|
|
}
|
|
}
|
|
@@ -922,6 +934,7 @@ namespace TEAMModelOS.Controllers
|
|
{
|
|
{
|
|
if (!testDataElement.Name.Equals("students", StringComparison.Ordinal)) testDataElement.WriteTo(writer);
|
|
if (!testDataElement.Name.Equals("students", StringComparison.Ordinal)) testDataElement.WriteTo(writer);
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
else if (response.Status == 404)
|
|
else if (response.Status == 404)
|
|
{
|
|
{
|
|
@@ -950,7 +963,8 @@ namespace TEAMModelOS.Controllers
|
|
|
|
|
|
writer.WritePropertyName("students");
|
|
writer.WritePropertyName("students");
|
|
writer.WriteStartArray();
|
|
writer.WriteStartArray();
|
|
- foreach (var (id, name, no, year) in importItem.Value)
|
|
|
|
|
|
+
|
|
|
|
+ foreach (var (id, name, no) in importItem.Value)
|
|
{
|
|
{
|
|
writer.WriteStartObject();
|
|
writer.WriteStartObject();
|
|
writer.WriteString("id", id);
|
|
writer.WriteString("id", id);
|