public async Task <JsonResult> GetTicketsByTeam(int?teamId) { if (teamId != null) { Team curTeam = await db.Teams.Include(x => x.Tickets).SingleOrDefaultAsync(y => y.Id == teamId); if (curTeam != null) { User curUser = await userManager.GetCurrentUser(); if (curTeam.Users.Find(x => x.Id == curUser.Id) != null || curUser.AppRole.Permissions.IsAdmin) { UserPermission curUserPerms = curTeam.UserPermissions.SingleOrDefault(x => x.User.Id == curUser.Id); if ((curUser != null && curUserPerms != null) || (curUser != null && curUser.AppRole.Permissions.IsAdmin)) { TeamRole curTeamUserRole = null; if (curUserPerms != null) { curTeamUserRole = curUserPerms.TeamRole; } List <Ticket> curTickets = await ticketManager.GetTicketsByTeam(teamId); List <TicketDTO> curTicketsDto = dtoConverter.ConvertTicketList(curTickets, curUser, curTeamUserRole.Permissions); return(Json(curTicketsDto, JsonRequestBehavior.AllowGet)); } } } } return(Json(null)); }