Browse Source

清除主动关联班级学生。

CrazyIter 4 years ago
parent
commit
9711af8f6a

+ 38 - 37
TEAMModelOS/Controllers/Task/SurveyController.cs

@@ -66,45 +66,46 @@ namespace TEAMModelOS.Controllers
             //清除作业
             if (!request.@params.reset)
             {
-                //根据作业发布对象查找到每一个具体学生生成关联关系表 HomeWorkStudent
-                List<Target> targets = request.@params.survey.target;
-                List<SurveyRecord> surveykStudents = new List<SurveyRecord>();
-                foreach (Target target in targets)
+                //查询之前是否有 关联关系表 HomeWorkStudent 有则删除
+                List<SurveyRecord> surveyRecords = await azureCosmosDBV3Repository.FindByDict<SurveyRecord>(new Dictionary<string, object> { { "id", request.@params.survey.id } });
+                if (surveyRecords.IsNotEmpty())
                 {
-                    //查询之前是否有 关联关系表 HomeWorkStudent 有则删除
-                    List<SurveyRecord> surveyRecords = await azureCosmosDBV3Repository.FindByDict<SurveyRecord>(new Dictionary<string, object> { { "id", request.@params.survey.id } });
-
-                    if (surveyRecords.IsNotEmpty())
-                    {
-                        await azureCosmosDBV3Repository.DeleteAll(surveyRecords);
-                    }
-                    List<ClassStudent> classroom = await azureCosmosDBV3Repository.FindByDict<ClassStudent>(new Dictionary<string, object> { { "id", target.classroomCode } });
-                    if (classroom.IsNotEmpty() && classroom[0].code != null)
-                    {
-                        foreach (ClassStudent student in classroom)
-                        {
-                            SurveyRecord surveyStudent = new SurveyRecord();
-                            surveyStudent.id = request.@params.survey.id;
-                            surveyStudent.code = student.code;
-                            surveyStudent.classroom.code = target.classroomCode;
-                            surveyStudent.classroom.name = target.classroomName;
-                            surveykStudents.Add(surveyStudent);
-                        }
-                    }
-                }
-                if (surveykStudents.IsNotEmpty())
-                {
-                    foreach (SurveyRecord surveyRecord in surveykStudents)
-                    {
-                        List<Student> student = await azureCosmosDBV3Repository.FindById<Student>(surveyRecord.code);
-                        if (student.IsNotEmpty())
-                        {
-                            surveyRecord.name = student[0].name;
-                            surveyRecord.code = student[0].TEAMModelId;
-                        }
-                    }
-                    await azureCosmosDBV3Repository.SaveOrUpdateAll(surveykStudents);
+                    await azureCosmosDBV3Repository.DeleteAll(surveyRecords);
                 }
+
+                ////根据作业发布对象查找到每一个具体学生生成关联关系表 HomeWorkStudent
+                //List<Target> targets = request.@params.survey.target;
+                //List<SurveyRecord> surveykStudents = new List<SurveyRecord>();
+                //foreach (Target target in targets)
+                //{
+                   
+                //    List<ClassStudent> classroom = await azureCosmosDBV3Repository.FindByDict<ClassStudent>(new Dictionary<string, object> { { "id", target.classroomCode } });
+                //    if (classroom.IsNotEmpty() && classroom[0].code != null)
+                //    {
+                //        foreach (ClassStudent student in classroom)
+                //        {
+                //            SurveyRecord surveyStudent = new SurveyRecord();
+                //            surveyStudent.id = request.@params.survey.id;
+                //            surveyStudent.code = student.code;
+                //            surveyStudent.classroom.code = target.classroomCode;
+                //            surveyStudent.classroom.name = target.classroomName;
+                //            surveykStudents.Add(surveyStudent);
+                //        }
+                //    }
+                //}
+                //if (surveykStudents.IsNotEmpty())
+                //{
+                //    foreach (SurveyRecord surveyRecord in surveykStudents)
+                //    {
+                //        List<Student> student = await azureCosmosDBV3Repository.FindById<Student>(surveyRecord.code);
+                //        if (student.IsNotEmpty())
+                //        {
+                //            surveyRecord.name = student[0].name;
+                //            surveyRecord.code = student[0].TEAMModelId;
+                //        }
+                //    }
+                //    await azureCosmosDBV3Repository.SaveOrUpdateAll(surveykStudents);
+                //}
             }
             return builder.Data(homeWork).build();
         }

+ 37 - 35
TEAMModelOS/Controllers/Task/VoteController.cs

@@ -72,44 +72,46 @@ namespace TEAMModelOS.Controllers.Learn
             if (!request.@params.reset)
             {
                 //根据作业发布对象查找到每一个具体学生生成关联关系表 HomeWorkStudent
-                List<Target> targets = request.@params.vote.target;
-                List<VoteRecord> votekStudents = new List<VoteRecord>();
-                foreach (Target target in targets)
-                {
-                    //查询之前是否有 关联关系表 HomeWorkStudent 有则删除
-                    List<VoteRecord> voteRecords = await _cosmos.FindByDict<VoteRecord>(new Dictionary<string, object> { { "id", request.@params.vote.id } });
 
-                    if (voteRecords.IsNotEmpty())
-                    {
-                        await _cosmos.DeleteAll(voteRecords);
-                    }
-                    List<ClassStudent> classroom = await _cosmos.FindByDict<ClassStudent>(new Dictionary<string, object> { { "id", target.classroomCode } });
-                    if (classroom.IsNotEmpty() && classroom[0].code!=null)
-                    {
-                        foreach (ClassStudent student in classroom)
-                        {
-                            VoteRecord voteStudent = new VoteRecord();
-                            voteStudent.id = request.@params.vote.id;
-                            voteStudent.code = student.code;
-                            voteStudent.classroom.code = target.classroomCode;
-                            voteStudent.classroom.name = target.classroomName;
-                            votekStudents.Add(voteStudent);
-                        }
-                    }
-                }
-                if (votekStudents.IsNotEmpty())
+                List<VoteRecord> voteRecords = await _cosmos.FindByDict<VoteRecord>(new Dictionary<string, object> { { "id", request.@params.vote.id } });
+
+                if (voteRecords.IsNotEmpty())
                 {
-                    foreach (VoteRecord voteRecord in votekStudents)
-                    {
-                        List<Student> student = await _cosmos.FindByDict<Student>(new Dictionary<string, object> { { "studentId", voteRecord.code } });
-                        if (student.IsNotEmpty())
-                        {
-                            voteRecord.name = student[0].name;
-                            voteRecord.code = student[0].studentId;
-                        }
-                    }
-                    await _cosmos.SaveOrUpdateAll(votekStudents);
+                    await _cosmos.DeleteAll(voteRecords);
                 }
+                //List<Target> targets = request.@params.vote.target;
+                //List<VoteRecord> votekStudents = new List<VoteRecord>();
+                //foreach (Target target in targets)
+                //{
+                //    //查询之前是否有 关联关系表 HomeWorkStudent 有则删除
+                    
+                //    List<ClassStudent> classroom = await _cosmos.FindByDict<ClassStudent>(new Dictionary<string, object> { { "id", target.classroomCode } });
+                //    if (classroom.IsNotEmpty() && classroom[0].code!=null)
+                //    {
+                //        foreach (ClassStudent student in classroom)
+                //        {
+                //            VoteRecord voteStudent = new VoteRecord();
+                //            voteStudent.id = request.@params.vote.id;
+                //            voteStudent.code = student.code;
+                //            voteStudent.classroom.code = target.classroomCode;
+                //            voteStudent.classroom.name = target.classroomName;
+                //            votekStudents.Add(voteStudent);
+                //        }
+                //    }
+                //}
+                //if (votekStudents.IsNotEmpty())
+                //{
+                //    foreach (VoteRecord voteRecord in votekStudents)
+                //    {
+                //        List<Student> student = await _cosmos.FindByDict<Student>(new Dictionary<string, object> { { "studentId", voteRecord.code } });
+                //        if (student.IsNotEmpty())
+                //        {
+                //            voteRecord.name = student[0].name;
+                //            voteRecord.code = student[0].studentId;
+                //        }
+                //    }
+                //    await _cosmos.SaveOrUpdateAll(votekStudents);
+                //}
             }
             return builder.Data(homeWork).build();
         }