瀏覽代碼

survey move option fix

ganahrhr 2 年之前
父節點
當前提交
a7deea29a3
共有 1 個文件被更改,包括 23 次插入0 次删除
  1. 23 0
      Models/Survey.cs

+ 23 - 0
Models/Survey.cs

@@ -235,6 +235,29 @@ namespace HyperCube.Models
             if (SurveyItemOptions.Count > 0 && SurveyItemOptions.ContainsKey(optionID))
             {
                 Console.WriteLine($"Survey [{SurveyID}] Item [{ID}] MoveOption id:{SurveyItemOptions[optionID].ID}");
+
+                int min = SurveyItemOptions.Select(o => o.Value.Position).Min();
+                int max = SurveyItemOptions.Select(o => o.Value.Position).Max();
+
+                Console.WriteLine($"min:{min}, max:{max}.");
+
+                int oldPosition, newPosition;
+                oldPosition = SurveyItemOptions[optionID].Position;
+
+                int targetPosition = (oldPosition + step < min) ? min : oldPosition + step;
+                targetPosition = (oldPosition + step > max) ? max : oldPosition + step;
+
+                Console.WriteLine($"oldPosition:{oldPosition}, step:{step}, target:{targetPosition}.");
+
+                int targetKey = SurveyItemOptions.FirstOrDefault(x => x.Value.Position == targetPosition).Key;
+                if (targetKey != 0)
+                {
+                    newPosition = SurveyItemOptions[targetKey].Position;
+                    Console.WriteLine($"newPosition:{newPosition}.");
+
+                    SurveyItemOptions[optionID].Position = newPosition;
+                    SurveyItemOptions[targetKey].Position = oldPosition;
+                }
             }
         }