|
@@ -137,6 +137,7 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
else if ($"{option}".Equals("import") && $"{scope}".Equals("school", StringComparison.OrdinalIgnoreCase)) {
|
|
|
if (!request.TryGetProperty("courses", out JsonElement _courses)) return BadRequest();
|
|
|
+ School schoolObj = await client.GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemAsync<School>(school, new PartitionKey("Base"));
|
|
|
List<Course> courses = _courses.ToObject<List<Course>>();
|
|
|
if (courses.IsNotEmpty())
|
|
|
{
|
|
@@ -148,62 +149,72 @@ namespace TEAMModelOS.Controllers
|
|
|
cos.school = school;
|
|
|
cos.creatorId = id;
|
|
|
cos.code = $"Course-{school}";
|
|
|
- if (cos.scope.Equals("school") && !string.IsNullOrWhiteSpace(cos.period?.id) && !string.IsNullOrWhiteSpace(cos.subject?.id))
|
|
|
+
|
|
|
+ if (cos.scope.Equals("school") && !string.IsNullOrWhiteSpace(cos.period?.id) )
|
|
|
{
|
|
|
- string sql = $"select top 1 value c from c where c.name ='{cos.name}' and c.period.id='{cos.period.id}' and c.subject.id='{cos.subject.id}' ";
|
|
|
- Course courseDb = null;
|
|
|
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School)
|
|
|
- .GetItemQueryIterator<Course>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey(cos.code) }))
|
|
|
- {
|
|
|
- courseDb = item;
|
|
|
- break;
|
|
|
+ if (string.IsNullOrWhiteSpace(cos.subject?.id) && !string.IsNullOrWhiteSpace(cos.subject?.name)) {
|
|
|
+ var sub= schoolObj.period.Where(z => z.id.Equals(cos.period.id)).FirstOrDefault()?.subjects.Where(s => s.name.Equals(cos.subject?.name));
|
|
|
+ if (sub.Any()) {
|
|
|
+ cos.subject.id = sub.First().id;
|
|
|
+ }
|
|
|
}
|
|
|
- if (courseDb != null)
|
|
|
- {
|
|
|
- CourseChange courseChange = new CourseChange { id = courseDb.id, code = courseDb.code, name = courseDb.name, scope = courseDb.scope, school = courseDb.school, creatorId = courseDb.creatorId };
|
|
|
- cos.schedule.ForEach(x =>
|
|
|
+ if (!string.IsNullOrWhiteSpace(cos.subject?.id)) {
|
|
|
+ string sql = $"select top 1 value c from c where c.name ='{cos.name}' and c.period.id='{cos.period.id}' and c.subject.id='{cos.subject.id}' ";
|
|
|
+ Course courseDb = null;
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School)
|
|
|
+ .GetItemQueryIterator<Course>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey(cos.code) }))
|
|
|
{
|
|
|
- if (!string.IsNullOrWhiteSpace(x.teacherId))
|
|
|
+ courseDb = item;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (courseDb != null)
|
|
|
+ {
|
|
|
+ CourseChange courseChange = new CourseChange { id = courseDb.id, code = courseDb.code, name = courseDb.name, scope = courseDb.scope, school = courseDb.school, creatorId = courseDb.creatorId };
|
|
|
+ cos.schedule.ForEach(x =>
|
|
|
{
|
|
|
- if (!string.IsNullOrWhiteSpace(x.stulist))
|
|
|
+ if (!string.IsNullOrWhiteSpace(x.teacherId))
|
|
|
{
|
|
|
- var stulist = courseDb.schedule.FindAll(z => !string.IsNullOrWhiteSpace(z.stulist) && !string.IsNullOrWhiteSpace(z.teacherId) && z.stulist.Equals(x.stulist) && z.teacherId.Equals(x.teacherId));
|
|
|
- if (!stulist.IsNotEmpty())
|
|
|
+ if (!string.IsNullOrWhiteSpace(x.stulist))
|
|
|
{
|
|
|
- courseDb.schedule.Add(x);
|
|
|
- courseChange.addList.Add(x.stulist);
|
|
|
+ var stulist = courseDb.schedule.FindAll(z => !string.IsNullOrWhiteSpace(z.stulist) && !string.IsNullOrWhiteSpace(z.teacherId) && z.stulist.Equals(x.stulist) && z.teacherId.Equals(x.teacherId));
|
|
|
+ if (!stulist.IsNotEmpty())
|
|
|
+ {
|
|
|
+ courseDb.schedule.Add(x);
|
|
|
+ courseChange.addList.Add(x.stulist);
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- if (!string.IsNullOrWhiteSpace(x.classId))
|
|
|
- {
|
|
|
- var classId = courseDb.schedule.FindAll(z => !string.IsNullOrWhiteSpace(z.classId) && !string.IsNullOrWhiteSpace(z.teacherId) && z.classId.Equals(x.classId) && z.teacherId.Equals(x.teacherId));
|
|
|
- if (!classId.IsNotEmpty())
|
|
|
+ if (!string.IsNullOrWhiteSpace(x.classId))
|
|
|
{
|
|
|
- courseDb.schedule.Add(x);
|
|
|
- courseChange.addClass.Add(x.classId);
|
|
|
+ var classId = courseDb.schedule.FindAll(z => !string.IsNullOrWhiteSpace(z.classId) && !string.IsNullOrWhiteSpace(z.teacherId) && z.classId.Equals(x.classId) && z.teacherId.Equals(x.teacherId));
|
|
|
+ if (!classId.IsNotEmpty())
|
|
|
+ {
|
|
|
+ courseDb.schedule.Add(x);
|
|
|
+ courseChange.addClass.Add(x.classId);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- });
|
|
|
- var messageBlob = new ServiceBusMessage(courseChange.ToJsonString()); ;
|
|
|
- messageBlob.ApplicationProperties.Add("name", "Course");
|
|
|
- var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
|
|
|
- await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
|
|
|
- courseDb = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync(courseDb, courseDb.id, new PartitionKey(courseDb.code));
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- cos.id = Guid.NewGuid().ToString();
|
|
|
- CourseChange courseChange = new CourseChange { id = cos.id, code = cos.code, name = cos.name, scope = cos.scope, school = cos.school, creatorId = cos.creatorId };
|
|
|
- courseChange.addClass = cos.schedule.Select(x => x.classId).ToList();
|
|
|
- courseChange.addList = cos.schedule.Select(x => x.stulist).ToList();
|
|
|
- var messageBlob = new ServiceBusMessage(courseChange.ToJsonString()); ;
|
|
|
- messageBlob.ApplicationProperties.Add("name", "Course");
|
|
|
- var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
|
|
|
- await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
|
|
|
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync(cos, new PartitionKey(cos.code));
|
|
|
+ });
|
|
|
+ var messageBlob = new ServiceBusMessage(courseChange.ToJsonString()); ;
|
|
|
+ messageBlob.ApplicationProperties.Add("name", "Course");
|
|
|
+ var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
|
|
|
+ await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
|
|
|
+ courseDb = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync(courseDb, courseDb.id, new PartitionKey(courseDb.code));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ cos.id = Guid.NewGuid().ToString();
|
|
|
+ CourseChange courseChange = new CourseChange { id = cos.id, code = cos.code, name = cos.name, scope = cos.scope, school = cos.school, creatorId = cos.creatorId };
|
|
|
+ courseChange.addClass = cos.schedule.Select(x => x.classId).ToList();
|
|
|
+ courseChange.addList = cos.schedule.Select(x => x.stulist).ToList();
|
|
|
+ var messageBlob = new ServiceBusMessage(courseChange.ToJsonString()); ;
|
|
|
+ messageBlob.ApplicationProperties.Add("name", "Course");
|
|
|
+ var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
|
|
|
+ await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync(cos, new PartitionKey(cos.code));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
return Ok();
|