Example #1
0
 private static void Reorder(int newPriority, Student student, Table target)
 {
     int originalPrioirty = student.Priority;
     if (newPriority == originalPrioirty)
     {
         //do nothing?
     }
     else if (newPriority < originalPrioirty)
     //the item was moved up, so everything else, up to the item that was moved, gets the priority plus one
     {
         foreach (Student x in target.Students)
         {
             if (x.Priority >= newPriority && x.Priority < originalPrioirty)
             {
                 x.Priority++;
             }
         }
     }
     else //the item was moved down, so every thing else, up to the item that was moved, gets a priority minus one
     {
         foreach (Student x in target.Students)
         {
             if (x.Priority <= newPriority && x.Priority > originalPrioirty)
             {
                 x.Priority--;
             }
         }
     }
 }
Example #2
0
 private static void Reorder(Table table)
 {
     int i = 0;
     foreach (var student in table.Students.OrderBy(x => x.Priority))
     {
         student.Priority = i;
         i++;
     }
 }