|
@@ -98,6 +98,10 @@ namespace TEAMModelOS.Controllers
|
|
|
CourseChange courseChange = new CourseChange { id = course.id, code = course.code, name = course.name, scope = course.scope, school = course.school, creatorId = course.creatorId };
|
|
|
courseChange.addClass = course.schedule.Select(x => x.classId).ToList();
|
|
|
courseChange.addList = course.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);
|
|
|
course = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher").CreateItemAsync(course, new PartitionKey($"Course-{code}"));
|
|
|
}
|
|
|
}
|
|
@@ -108,19 +112,93 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
|
|
|
Course odlCourse = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").ReadItemAsync<Course>( course.id, new PartitionKey($"Course-{code}"));
|
|
|
- CourseChange courseChange = new CourseChange { id = course.id, code = course.code, name = course.name, scope = course.scope, school = course.school, creatorId = course.creatorId };
|
|
|
+ CourseChange courseChange = new CourseChange { id = course.id, code = course.code, name = course.name, scope = course.scope, school = code };
|
|
|
var oldCls = odlCourse.schedule.Select(x => x.classId).ToList();
|
|
|
var oldLst = odlCourse.schedule.Select(x => x.stulist).ToList();
|
|
|
var newCls = course.schedule.Select(x => x.classId).ToList();
|
|
|
var newLst = course.schedule.Select(x => x.stulist).ToList();
|
|
|
-
|
|
|
-
|
|
|
+ List<string> addCls = new List<string>();
|
|
|
+ List<string> addLst = new List<string>();
|
|
|
+ List<string> delCls = new List<string>();
|
|
|
+ List<string> delLst = new List<string>();
|
|
|
+ oldCls.ForEach(x => {
|
|
|
+ if (!newCls.Contains(x)) {
|
|
|
+ delCls.Add(x);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ newCls .ForEach(x => {
|
|
|
+ if (!oldCls.Contains(x))
|
|
|
+ {
|
|
|
+ addCls.Add(x);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ oldLst.ForEach(x => {
|
|
|
+ if (!newLst.Contains(x))
|
|
|
+ {
|
|
|
+ delLst.Add(x);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ newLst.ForEach(x => {
|
|
|
+ if (!oldLst.Contains(x))
|
|
|
+ {
|
|
|
+ addLst.Add(x);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ courseChange.addClass = addCls;
|
|
|
+ courseChange.addList = addLst;
|
|
|
+ courseChange.delClass = delCls;
|
|
|
+ courseChange.delList = delLst;
|
|
|
course = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").ReplaceItemAsync(course, course.id, new PartitionKey($"Course-{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);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- var odlCourse = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Course>(course.id, new PartitionKey($"Course-{code}"));
|
|
|
+ Course odlCourse = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Course>(course.id, new PartitionKey($"Course-{code}"));
|
|
|
+ CourseChange courseChange = new CourseChange { id = course.id, code = course.code, name = course.name, scope = course.scope, creatorId = code };
|
|
|
+ var oldCls = odlCourse.schedule.Select(x => x.classId).ToList();
|
|
|
+ var oldLst = odlCourse.schedule.Select(x => x.stulist).ToList();
|
|
|
+ var newCls = course.schedule.Select(x => x.classId).ToList();
|
|
|
+ var newLst = course.schedule.Select(x => x.stulist).ToList();
|
|
|
+ List<string> addCls = new List<string>();
|
|
|
+ List<string> addLst = new List<string>();
|
|
|
+ List<string> delCls = new List<string>();
|
|
|
+ List<string> delLst = new List<string>();
|
|
|
+ oldCls.ForEach(x => {
|
|
|
+ if (!newCls.Contains(x))
|
|
|
+ {
|
|
|
+ delCls.Add(x);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ newCls.ForEach(x => {
|
|
|
+ if (!oldCls.Contains(x))
|
|
|
+ {
|
|
|
+ addCls.Add(x);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ oldLst.ForEach(x => {
|
|
|
+ if (!newLst.Contains(x))
|
|
|
+ {
|
|
|
+ delLst.Add(x);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ newLst.ForEach(x => {
|
|
|
+ if (!oldLst.Contains(x))
|
|
|
+ {
|
|
|
+ addLst.Add(x);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ courseChange.addClass = addCls;
|
|
|
+ courseChange.addList = addLst;
|
|
|
+ courseChange.delClass = delCls;
|
|
|
+ courseChange.delList = delLst;
|
|
|
course = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync(course, course.id, new PartitionKey($"Course-{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);
|
|
|
}
|
|
|
}
|
|
|
return Ok(new { course });
|
|
@@ -694,10 +772,26 @@ namespace TEAMModelOS.Controllers
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
if (scope.ToString().Equals("school"))
|
|
|
{
|
|
|
+ Course course= await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<Course>(id.ToString(), new PartitionKey($"Course-{code}"));
|
|
|
+ CourseChange courseChange = new CourseChange { id = course.id, code = course.code, name = course.name, scope = course.scope, school = course.school, creatorId = course.creatorId };
|
|
|
+ courseChange.delClass = course.schedule.Select(x => x.classId).ToList();
|
|
|
+ courseChange.delList = course.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 client.GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"Course-{code}"));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
+ Course course = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Course>(id.ToString(), new PartitionKey($"Course-{code}"));
|
|
|
+ CourseChange courseChange = new CourseChange { id = course.id, code = course.code, name = course.name, scope = course.scope, school = course.school, creatorId = course.creatorId };
|
|
|
+ courseChange.delClass = course.schedule.Select(x => x.classId).ToList();
|
|
|
+ courseChange.delList = course.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 client.GetContainer("TEAMModelOS", "Teacher").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"Course-{code}"));
|
|
|
}
|
|
|
return Ok(new { id });
|