public async Task <IActionResult> AssignProject([FromRoute] int groupId, [FromQuery][Required] int?projectId) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Group group = await _groupService.GetByIdAsync(groupId); if (group == null) { return(BadRequest("Group not found")); } Project project = await _projectService.GetByIdAsync(projectId ?? 0); if (project == null) { return(BadRequest("Project not found")); } if (!project.Approved) { return(BadRequest("Approve the project first")); } if (project.AssignedGroup != null) { return(BadRequest("Project is already assigned to a group. Please unassign the project first.")); } if (group.FinalProjectAssigned != null) { return(BadRequest("Group already has a project assigned. Please unassign the project first.")); } await _groupService.AssignProjectAsync(project, group, Int32.Parse(User.Identity.Name)); return(Ok()); }