/// <summary> /// used when the work item is completion mode "admin only", and also used to do "admin completion" for any WI /// </summary> /// <param name="item"></param> /// <param name="assignments"></param> /// <param name="userId"></param> /// <param name="workNotes"></param> /// <param name="onBehalfOfUserId"></param> /// <returns></returns> private async Task CompleteWorkItemAdminOnly(WorkItem item, IEnumerable <WorkItemAssignment> assignments, int userId, string workNotes, int?onBehalfOfUserId = null) { if (!onBehalfOfUserId.HasValue) { onBehalfOfUserId = userId; } var assignment = assignments.SingleOrDefault(x => x.UserId == onBehalfOfUserId.Value); if (assignment == null) { assignment = new WorkItemAssignment() { UserId = onBehalfOfUserId.Value, WorkItemId = item.Id }; } var now = _clock.UtcNow.UtcDateTime; assignment.CompletedAt = now; assignment.WorkNotes = workNotes; if (assignment.Id == default(int)) { await _workItemRepository.InsertWorkItemAssignment(assignment); } else { await _workItemRepository.UpdateWorkItemAssignment(assignment); } if (onBehalfOfUserId.HasValue && onBehalfOfUserId != userId) { var assignment2 = assignments.SingleOrDefault(x => x.UserId == userId); if (assignment2 == null) { assignment2 = new WorkItemAssignment() { UserId = userId, WorkItemId = item.Id }; } assignment2.CompletedAt = now; assignment2.WorkNotes = workNotes; if (assignment2.Id == default(int)) { await _workItemRepository.InsertWorkItemAssignment(assignment2); } else { await _workItemRepository.UpdateWorkItemAssignment(assignment2); } } item.CompletedAt = now; item.CompletedByUserId = onBehalfOfUserId.Value; await _workItemRepository.UpdateWorkItem(item); }