|
@@ -85,7 +85,7 @@ namespace TEAMModelOS.Controllers
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- var retStudents = classStudent.SelectMany(o => o.Value.Select(p => new { p.id, p.name, p.no, p.year, classId = o.Key, gradeId = classStuds[o.Key].gradeId, periodId = classStuds[o.Key].periodId }));
|
|
|
|
|
|
+ var retStudents = classStudent.SelectMany(o => o.Value.Select(p => new { p.id, p.name, p.no, p.year, classId = o.Key, classStuds[o.Key].gradeId, classStuds[o.Key].periodId }));
|
|
var retUnclassStudents = unclassStudent.Select(o => new { o.id, o.name, o.no, o.year, classId = (string)null, gradeId = (string)null, periodId = (string)null });
|
|
var retUnclassStudents = unclassStudent.Select(o => new { o.id, o.name, o.no, o.year, classId = (string)null, gradeId = (string)null, periodId = (string)null });
|
|
|
|
|
|
IEnumerable ret = new string[] { };
|
|
IEnumerable ret = new string[] { };
|
|
@@ -790,10 +790,10 @@ namespace TEAMModelOS.Controllers
|
|
{
|
|
{
|
|
exceptions.Add(ex);
|
|
exceptions.Add(ex);
|
|
}
|
|
}
|
|
- if (exceptions.Count == 0) return sucIds;
|
|
|
|
- else if (exceptions.Count > 1) throw new AggregateException(exceptions);
|
|
|
|
- else if (exceptions.Count == 1) throw exceptions.Single();
|
|
|
|
}
|
|
}
|
|
|
|
+ if (exceptions.Count == 0) return sucIds;
|
|
|
|
+ else if (exceptions.Count > 1) throw new AggregateException(exceptions);
|
|
|
|
+ else if (exceptions.Count == 1) throw exceptions.Single();
|
|
}
|
|
}
|
|
catch (CosmosException ex)
|
|
catch (CosmosException ex)
|
|
{
|
|
{
|
|
@@ -1120,7 +1120,7 @@ namespace TEAMModelOS.Controllers
|
|
try
|
|
try
|
|
{
|
|
{
|
|
//Key:id Value:學生基本資訊
|
|
//Key:id Value:學生基本資訊
|
|
- Dictionary<string, (string salt, string pw, string name, string year, string pic,string gender,string mail,string mobile)> studentsInfo
|
|
|
|
|
|
+ Dictionary<string, (string salt, string pw, string name, string year, string pic,string gender,string mail,string mobile)> studentsInfos
|
|
= new Dictionary<string, (string salt, string pw, string name, string year, string pic, string gender, string mail, string mobile)>();
|
|
= new Dictionary<string, (string salt, string pw, string name, string year, string pic, string gender, string mail, string mobile)>();
|
|
List<string> nonexistentIds = new List<string>();
|
|
List<string> nonexistentIds = new List<string>();
|
|
List<string> errorIds = new List<string>();
|
|
List<string> errorIds = new List<string>();
|
|
@@ -1163,10 +1163,10 @@ namespace TEAMModelOS.Controllers
|
|
{
|
|
{
|
|
year = tmpYear.GetString();
|
|
year = tmpYear.GetString();
|
|
}
|
|
}
|
|
- if (!studentsInfo.ContainsKey(id.GetString()))
|
|
|
|
|
|
+ if (!studentsInfos.ContainsKey(id.GetString()))
|
|
{
|
|
{
|
|
//pic,mail,mobile暫不支持更新
|
|
//pic,mail,mobile暫不支持更新
|
|
- studentsInfo.Add(id.GetString(), (salt, pw, name, year, null, gender, null, null));
|
|
|
|
|
|
+ studentsInfos.Add(id.GetString(), (salt, pw, name, year, null, gender, null, null));
|
|
nonexistentIds.Add(id.GetString());
|
|
nonexistentIds.Add(id.GetString());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1174,11 +1174,11 @@ namespace TEAMModelOS.Controllers
|
|
}
|
|
}
|
|
|
|
|
|
//將資料更新到資料庫
|
|
//將資料更新到資料庫
|
|
- if (studentsInfo.Count != 0)
|
|
|
|
|
|
+ if (studentsInfos.Count != 0)
|
|
{
|
|
{
|
|
CosmosContainer cosmosContainer = _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOSTemp", "Student");
|
|
CosmosContainer cosmosContainer = _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOSTemp", "Student");
|
|
//查學生的基本資料
|
|
//查學生的基本資料
|
|
- string queryText = $"SELECT * FROM c WHERE c.pk = 'Base' AND c.id IN ({string.Join(",", studentsInfo.Select(o => $"'{o.Key}'"))})";
|
|
|
|
|
|
+ string queryText = $"SELECT * FROM c WHERE c.pk = 'Base' AND c.id IN ({string.Join(",", studentsInfos.Select(o => $"'{o.Key}'"))})";
|
|
|
|
|
|
List<JsonElement> listStudent = new List<JsonElement>();
|
|
List<JsonElement> listStudent = new List<JsonElement>();
|
|
|
|
|
|
@@ -1196,6 +1196,8 @@ namespace TEAMModelOS.Controllers
|
|
JsonElement account = accounts.Current;
|
|
JsonElement account = accounts.Current;
|
|
string id = account.GetProperty("id").GetString();
|
|
string id = account.GetProperty("id").GetString();
|
|
|
|
|
|
|
|
+ (string name, string year, string pic, string gender, string mail, string mobile) oldData;
|
|
|
|
+ //oldData = studentsInfos[id];
|
|
bool upPwDone = false;
|
|
bool upPwDone = false;
|
|
using var memoryStream = new MemoryStream();
|
|
using var memoryStream = new MemoryStream();
|
|
using var writer = new Utf8JsonWriter(memoryStream);
|
|
using var writer = new Utf8JsonWriter(memoryStream);
|
|
@@ -1204,23 +1206,33 @@ namespace TEAMModelOS.Controllers
|
|
{
|
|
{
|
|
switch (true)
|
|
switch (true)
|
|
{
|
|
{
|
|
- case bool _ when element.Name.Equals("name", StringComparison.Ordinal) && !string.IsNullOrWhiteSpace(studentsInfo[id].name):
|
|
|
|
- writer.WriteString("name", studentsInfo[id].name);
|
|
|
|
|
|
+ case bool _ when element.Name.Equals("name", StringComparison.Ordinal) && !string.IsNullOrWhiteSpace(studentsInfos[id].name):
|
|
|
|
+ writer.WriteString("name", studentsInfos[id].name);
|
|
|
|
+ break;
|
|
|
|
+ case bool _ when element.Name.Equals("name", StringComparison.Ordinal):
|
|
|
|
+ if (string.IsNullOrWhiteSpace(studentsInfos[id].name))
|
|
|
|
+ {
|
|
|
|
+ element.WriteTo(writer);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ writer.WriteString("name", studentsInfos[id].name);
|
|
|
|
+ }
|
|
break;
|
|
break;
|
|
case bool _ when element.Name.Equals("pw", StringComparison.Ordinal):
|
|
case bool _ when element.Name.Equals("pw", StringComparison.Ordinal):
|
|
case bool _ when element.Name.Equals("salt", StringComparison.Ordinal):
|
|
case bool _ when element.Name.Equals("salt", StringComparison.Ordinal):
|
|
- if (!upPwDone && !string.IsNullOrWhiteSpace(studentsInfo[id].salt) && !string.IsNullOrWhiteSpace(studentsInfo[id].pw))
|
|
|
|
|
|
+ if (!upPwDone && !string.IsNullOrWhiteSpace(studentsInfos[id].salt) && !string.IsNullOrWhiteSpace(studentsInfos[id].pw))
|
|
{
|
|
{
|
|
- writer.WriteString("salt", studentsInfo[id].salt);
|
|
|
|
- writer.WriteString("pw", studentsInfo[id].pw);
|
|
|
|
|
|
+ writer.WriteString("salt", studentsInfos[id].salt);
|
|
|
|
+ writer.WriteString("pw", studentsInfos[id].pw);
|
|
upPwDone = true;
|
|
upPwDone = true;
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
- case bool _ when element.Name.Equals("gender", StringComparison.Ordinal) && !string.IsNullOrWhiteSpace(studentsInfo[id].gender):
|
|
|
|
- writer.WriteString("gender", studentsInfo[id].gender);
|
|
|
|
|
|
+ case bool _ when element.Name.Equals("gender", StringComparison.Ordinal) && !string.IsNullOrWhiteSpace(studentsInfos[id].gender):
|
|
|
|
+ writer.WriteString("gender", studentsInfos[id].gender);
|
|
break;
|
|
break;
|
|
- case bool _ when element.Name.Equals("year", StringComparison.Ordinal) && !string.IsNullOrWhiteSpace(studentsInfo[id].year):
|
|
|
|
- writer.WriteString("year", studentsInfo[id].year);
|
|
|
|
|
|
+ case bool _ when element.Name.Equals("year", StringComparison.Ordinal) && !string.IsNullOrWhiteSpace(studentsInfos[id].year):
|
|
|
|
+ writer.WriteString("year", studentsInfos[id].year);
|
|
break;
|
|
break;
|
|
case bool _ when element.Name.StartsWith("_", StringComparison.Ordinal):
|
|
case bool _ when element.Name.StartsWith("_", StringComparison.Ordinal):
|
|
break;
|
|
break;
|
|
@@ -1258,11 +1270,11 @@ namespace TEAMModelOS.Controllers
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//將輸入不存在的資料移除。
|
|
//將輸入不存在的資料移除。
|
|
- nonexistentIds.ForEach(o => studentsInfo.Remove(o));
|
|
|
|
|
|
+ nonexistentIds.ForEach(o => studentsInfos.Remove(o));
|
|
}
|
|
}
|
|
//整理輸出數據
|
|
//整理輸出數據
|
|
var retStudentsInfo = new Dictionary<string, (string name, string year, string pic, string gender, string mail, string mobile)>();
|
|
var retStudentsInfo = new Dictionary<string, (string name, string year, string pic, string gender, string mail, string mobile)>();
|
|
- foreach (var item in studentsInfo)
|
|
|
|
|
|
+ foreach (var item in studentsInfos)
|
|
{
|
|
{
|
|
retStudentsInfo.Add(item.Key, (item.Value.name, item.Value.year, item.Value.pic, item.Value.gender, item.Value.mail, item.Value.mobile));
|
|
retStudentsInfo.Add(item.Key, (item.Value.name, item.Value.year, item.Value.pic, item.Value.gender, item.Value.mail, item.Value.mobile));
|
|
}
|
|
}
|