public async Task <IActionResult> ChangeGroupAdmin([FromRoute] int groupAdminId, [FromQuery][Required] int?newAdminId) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Student admin = await _studentService.GetByIdAsync(groupAdminId); Student student = await _studentService.GetByIdAsync(newAdminId ?? 0); if (admin == null || student == null) { return(BadRequest("Student Not Found")); } Group group = admin.Group; if (group == null) { return(BadRequest("Group Not Found")); } if (admin.GroupAdmin) { if (!group.Students.Contains(student)) { return(BadRequest("Student is not part of the group")); } await _studentService.ChangeGroupAdminAsync(admin, student, Int32.Parse(User.Identity.Name)); return(Ok()); } return(BadRequest("Only the group admin can change the admin of the group")); }