I have a use case where I want to reorder the priority of a task entity stored in the db using EF Core.
On the frontend the user can reorder the tasks in the column to indicate their priority from 1 to N, and when they finish they would save their work. There are two tables displayed to the user a Review list, and a Ready list.
| Priority | Original Task List | New Task List |
|---|---|---|
| 1 | Task 1 | Task 5 |
| 2 | Task 2 | Task 1 |
| 3 | Task 3 | Task 3 |
| 4 | Task 4 | Task 2 |
| 5 | Task 5 | Task 4 |
When they save the work it sends the priority list for both tables back to the server which then updates the relevant data
priorityList.ForEach(x =>
{
var task = context.Task.Find(x.Id);
if (task != null && (task.Priority != x.Priority))
{
task.Priority = x.Priority;
context.SaveChanges();
}
});
My entity setup:
Task Entity
public class ItemTask {
public Guid Id {get;set;}
public string Title {get;set;}
public int Priority {get;set;}
public TaskList TaskList {get;set;}
}
Task List
public class TaskList {
public Guid Id {get;set;}
public string Title {get;set;}
public List<ItemTask> ReadyList {get;set;}
public List<ItemTask> ReviewList {get;set;}
}
The use case I want to move towards is that when user changes the order, it updates only the relevant data affected, as opposed to both lists. I have made it so that when relevant list changes it sends update to the service with Priority for all items in that list and follows the update process.
I am trying to figure out if there is a way to store sequence by default for the relevant list, and change only relevant data would make it more efficient and simpler.