public async Task <IActionResult> AddProjectToPreference([FromQuery][Required] int?projectId, [FromRoute] int groupId) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Project project = await _projectService.GetByIdAsync(projectId ?? 0); Group group = await _groupService.GetByIdAsync(groupId); if (project == null) { return(BadRequest("Project Not Found")); } if (group == null) { return(BadRequest("Group Not Found")); } if (!User.IsInRole("Admin")) { Student student = await _studentService.GetByIdAsync(Int32.Parse(User.Identity.Name)); if (student.Group != group) { return(BadRequest("Action not allowed")); } if (!student.GroupAdmin) { return(BadRequest("You are not group admin")); } } if (await _groupService.ProjectExistsInPreferencesAsync(group, project)) { return(Ok("Already exists")); } await _groupService.AddToPreferencesAsync(project, group, Int32.Parse(User.Identity.Name)); return(Ok()); }