public async Task <ActionResult <IEnumerable <TaskDto> > > PutTask(long taskId, TaskDto task) { if (taskId != task.Id) { return(BadRequest()); } var taskEntity = TaskMapper.mapFromDto(task); if (taskEntity.State == State.Closed) { taskEntity.ClosedAt = DateTime.Now; } var oldTask = _context.Tasks .AsNoTracking() .FirstOrDefault(t => t.Id == taskId); if (oldTask.State == State.Closed && taskEntity.State != State.Closed) { taskEntity.ClosedAt = null; } _context.Entry(taskEntity).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TaskExists(taskId)) { return(NotFound()); } else { throw; } } List <TaskDto> states = new List <TaskDto>(); states.Add(TaskMapper.mapToDto(oldTask)); states.Add(task); return(states); }