/// <summary> /// Ensures a valid task number exists /// </summary> /// <param name="taskNumber">Task number</param> /// <param name="projectId">Project Id</param> /// <returns>Task Number</returns> private async Task <int> EnsureTaskNumber(string projectId, int taskNumber) { if (taskNumber > 0) { return(taskNumber); } return(await _taskNumberDbAccess.GetNextTaskNumber(projectId)); }
public async Task <IActionResult> CreateTaskGroup(string boardId, [FromBody] TaskGroup group) { // Validate Data if (string.IsNullOrEmpty(boardId) || string.IsNullOrEmpty(group.Name)) { return(StatusCode((int)HttpStatusCode.BadRequest)); } _xssChecker.CheckXss(group.Name); _xssChecker.CheckXss(group.Description); // Get Task Board TaskBoard updatedTaskBoard = await _taskBoardDbAccess.GetTaskBoardById(boardId); if (updatedTaskBoard == null) { return(StatusCode((int)HttpStatusCode.NotFound)); } // Create Task Group TaskGroup newGroup = new TaskGroup(); newGroup.Id = Guid.NewGuid().ToString(); newGroup.TaskNumber = await _taskNumberDbAccess.GetNextTaskNumber(updatedTaskBoard.ProjectId); newGroup.Name = group.Name; newGroup.Description = group.Description; newGroup.Status = group.Status; newGroup.AssignedTo = group.AssignedTo; newGroup.Tasks = new List <GoNorthTask>(); await this.SetModifiedData(_userManager, newGroup); if (updatedTaskBoard.TaskGroups == null) { updatedTaskBoard.TaskGroups = new List <TaskGroup>(); } updatedTaskBoard.TaskGroups.Add(newGroup); try { await _taskBoardDbAccess.UpdateTaskBoard(updatedTaskBoard); } catch (Exception ex) { _logger.LogError(ex, "Could not updated task board for creating task group."); return(StatusCode((int)HttpStatusCode.InternalServerError)); } // Add Timeline entry try { await _timelineService.AddTimelineEntry(TimelineEvent.TaskGroupCreated, updatedTaskBoard.Id, updatedTaskBoard.Name, newGroup.Name); } catch (Exception ex) { _logger.LogError(ex, "Could not create task group created timeline entry."); return(StatusCode((int)HttpStatusCode.InternalServerError)); } return(Ok(newGroup)); }