public async Task <IActionResult> GetAssignmentMessages(int userId, int assignmentId) { if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } // convoluted way of getting groupId var user = await _repo.GetUser(userId); var u = user.UserGroups; var groupId = 0; foreach (var ug in u) { groupId = ug.GroupId; break; } var messagesForAssignment = await _repo.GetAssignmentMessages(assignmentId, groupId); var messagesToReturn = _mapper.Map <IEnumerable <AssignmentMessageToReturnDto> >(messagesForAssignment); return(Ok(messagesToReturn)); }