// GET: Projects/Details/5 public async Task <IActionResult> Details(int?id) { if (id == null) { return(NotFound()); } var project = await _context.Projects .Include(m => m.Tickets) //Project model already has Tickets associated (icollection) .AsNoTracking() //optional; more efficient way to do things apparently .FirstOrDefaultAsync(m => m.Id == id); if (project == null) { return(NotFound()); } var isAuthorized = await _authorizationService.AuthorizeAsync(User, project, ProjectOperations.Read); if (!isAuthorized.Succeeded) { return(Forbid()); } var vm = new ProjectsDetailsVM { Project = project, UsersWithClaim = await _userManager.GetUsersForClaimAsync(new Claim("AssignedProject", project.Id.ToString())) }; return(View(vm)); }
public ActionResult Details(int id) { OvmDbContext context = new OvmDbContext(); Project project = context.Projects.Find(id); ProjectsDetailsVM model = new ProjectsDetailsVM { Id = id, Name = project.Name, Description = project.Description, Teams = project.Teams.Select(t => new TeamsVM { Id = t.Id, Name = t.Name, TeamLeadName = t.TeamLead?.Username, TeamSize = t.Developers.Count }).ToList() }; return(View(model)); }