Explorar o código

survey move option fix

ganahrhr %!s(int64=2) %!d(string=hai) anos
pai
achega
a7deea29a3
Modificáronse 1 ficheiros con 23 adicións e 0 borrados
  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;
+                }
             }
         }