MCPcopy Create free account
hub / github.com/GmpABR/NexusFlow / MoveTaskAsync

Method MoveTaskAsync

backend/Services/TaskService.cs:156–206  ·  view source on GitHub ↗
(int taskId, MoveTaskDto dto, int userId)

Source from the content-addressed store, hash-verified

154 }
155
156 public async Task<TaskCardDto?> MoveTaskAsync(int taskId, MoveTaskDto dto, int userId)
157 {
158 Console.WriteLine($"[MoveTask] Moving Task {taskId} to Column {dto.TargetColumnId} at Order {dto.NewOrder}");
159 var task = await _db.TaskCards
160 .Include(t => t.Column)
161 .Include(t => t.Assignee)
162 .Include(t => t.Assignees).ThenInclude(a => a.User)
163 .Include(t => t.Subtasks)
164 .Include(t => t.Attachments).ThenInclude(a => a.UploadedBy)
165 .Include(t => t.TimeLogs)
166 .FirstOrDefaultAsync(t => t.Id == taskId);
167
168 if (task == null) return null;
169
170 if (!await VerifyTaskAccessAsync(taskId, userId))
171 throw new UnauthorizedAccessException("User does not have access to this task.");
172
173 int oldColumnId = task.ColumnId;
174
175 // 1. Get all tasks in the target column (excluding the moved task)
176 var targetColumnTasks = await _db.TaskCards
177 .Where(t => t.ColumnId == dto.TargetColumnId && t.Id != taskId)
178 .OrderBy(t => t.Order)
179 .ToListAsync();
180
181 // 2. Insert the moved task at the new position
182 int newIndex = Math.Max(0, Math.Min(dto.NewOrder, targetColumnTasks.Count));
183
184 task.ColumnId = dto.TargetColumnId;
185
186 targetColumnTasks.Insert(newIndex, task);
187
188 // 3. Update Order for all tasks in the target column
189 for (int i = 0; i < targetColumnTasks.Count; i++)
190 {
191 targetColumnTasks[i].Order = i;
192 }
193
194 await _db.SaveChangesAsync();
195
196 if (oldColumnId != dto.TargetColumnId)
197 {
198 await LogActivity(taskId, userId, "Moved", $"Moved to column {dto.TargetColumnId}");
199 }
200 else
201 {
202 await LogActivity(taskId, userId, "Reordered", "Reordered within same column");
203 }
204
205 return await MapToDto(task);
206 }
207
208 public async Task<int?> DeleteTaskAsync(int taskId, int userId)
209 {

Callers 1

MoveTaskMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected