فهرست منبع

限定删除条件

zhouj1203@hotmail.com 3 سال پیش
والد
کامیت
602991b535
1فایلهای تغییر یافته به همراه41 افزوده شده و 39 حذف شده
  1. 41 39
      TEAMModelOS.SDK/Models/Service/ActivityService.cs

+ 41 - 39
TEAMModelOS.SDK/Models/Service/ActivityService.cs

@@ -100,7 +100,7 @@ namespace TEAMModelOS.SDK
                     //stujoin新加入名单的
                     foreach (Member member in groupChange.stujoin)
                     {
-                        await updateClassResulte(client, classResults, standerAnswers, member.id);
+                        await updateClassResulte(client, classResults, standerAnswers, member.id, groupChange.listid);
                         var stucourse = new StuActivity
                         {
                             id = activity.id,
@@ -127,7 +127,7 @@ namespace TEAMModelOS.SDK
                     //tmdjoin新加入的
                     foreach (Member member in groupChange.tmdjoin)
                     {
-                        await updateClassResulte(client, classResults, standerAnswers, member.id);
+                        await updateClassResulte(client, classResults, standerAnswers, member.id,groupChange.listid);
                         var stucourse = new StuActivity
                         {
                             id = activity.id,
@@ -180,7 +180,7 @@ namespace TEAMModelOS.SDK
                     {
                         try
                         {
-                            await updateClassResulte(client, classResults, standerAnswers, member.id);
+                            await updateClassResulte(client, classResults, standerAnswers, member.id, groupChange.listid);
                             await client.GetContainer(Constant.TEAMModelOS, "Student").DeleteItemAsync<StuActivity>(activity.id, new PartitionKey($"Activity-{member.code.Replace("Base-", "")}-{member.id}"));
                         }
                         catch (CosmosException)
@@ -193,7 +193,7 @@ namespace TEAMModelOS.SDK
                     {
                         try
                         {
-                            await updateClassResulte(client, classResults, standerAnswers, member.id);
+                            await updateClassResulte(client, classResults, standerAnswers, member.id, groupChange.listid);
                             await client.GetContainer(Constant.TEAMModelOS, "Student").DeleteItemAsync<StuActivity>(activity.id, new PartitionKey($"Activity-{member.id}"));
                         }
                         catch (CosmosException)
@@ -407,50 +407,52 @@ namespace TEAMModelOS.SDK
                 await Task.WhenAll(tasks);
             }
         }
-        public static async Task updateClassResulte(CosmosClient client,List<ExamClassResult> classResults, List<PaperSimple> standerAnswers, string id)
+        public static async Task updateClassResulte(CosmosClient client,List<ExamClassResult> classResults, List<PaperSimple> standerAnswers, string id,string stuListId)
         {
             if (classResults.Count > 0)
             {
                 foreach (var item in classResults)
                 {
-                    int index = item.studentIds.IndexOf(id);
-                    if (index == -1)
-                    {
-                        List<List<string>> standard = new List<List<string>>();
-                        foreach (PaperSimple simple in standerAnswers)
-                        {
-                            standard = simple.answers;
-                        }
-                        List<double> ansPoint = new List<double>();
-                        List<List<string>> anc = new List<List<string>>();
-                        List<List<Details>> mark = new List<List<Details>>();
-                        foreach (List<string> num in standard)
+                    if (item.info.id.Equals(stuListId)) {
+                        int index = item.studentIds.IndexOf(id);
+                        if (index == -1)
                         {
-                            List<string> newAns = new List<string>();
-                            foreach (string san in num)
+                            List<List<string>> standard = new List<List<string>>();
+                            foreach (PaperSimple simple in standerAnswers)
+                            {
+                                standard = simple.answers;
+                            }
+                            List<double> ansPoint = new List<double>();
+                            List<List<string>> anc = new List<List<string>>();
+                            List<List<Details>> mark = new List<List<Details>>();
+                            foreach (List<string> num in standard)
                             {
-                                newAns.Add(san);
+                                List<string> newAns = new List<string>();
+                                foreach (string san in num)
+                                {
+                                    newAns.Add(san);
+                                }
+                                anc.Add(newAns);
+                                ansPoint.Add(-1);
+                                mark.Add(new List<Details>());
                             }
-                            anc.Add(newAns);
-                            ansPoint.Add(-1);
-                            mark.Add(new List<Details>());
+                            item.mark.Add(mark);
+                            item.ans.Add(anc);
+                            item.studentIds.Add(id);
+                            item.studentScores.Add(ansPoint);
+                            item.studentAnswers.Add(new List<string>());
+                            item.sum.Add(0);
                         }
-                        item.mark.Add(mark);
-                        item.ans.Add(anc);
-                        item.studentIds.Add(id);
-                        item.studentScores.Add(ansPoint);
-                        item.studentAnswers.Add(new List<string>());
-                        item.sum.Add(0);
-                    }
-                    else { 
-                        item.mark.RemoveAt(index);
-                        item.ans.RemoveAt(index);
-                        item.studentIds.RemoveAt(index);
-                        item.studentScores.RemoveAt(index);
-                        item.studentAnswers.RemoveAt(index);
-                        item.sum.RemoveAt(index);
-                    }
-                    
+                        else
+                        {
+                            item.mark.RemoveAt(index);
+                            item.ans.RemoveAt(index);
+                            item.studentIds.RemoveAt(index);
+                            item.studentScores.RemoveAt(index);
+                            item.studentAnswers.RemoveAt(index);
+                            item.sum.RemoveAt(index);
+                        }
+                    }                                       
                     await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(item, item.id, new PartitionKey($"{item.code}"));
                 }
             }