public async Task <IActionResult> Index() { var tickets = new List <Ticket>(); var projects = new List <Project>(); if (User.IsInRole("Admin")) { tickets = _ticketServices.GetAll().ToList(); projects = _projectServices.GetAll().ToList(); } else { tickets = _ticketServices.GetAllByUser(_userManager.GetUserId(User)).ToList(); projects = _projectServices.GetAllByUser(_userManager.GetUserId(User)).ToList(); } var ticketIndexModel = new TicketIndexModel { PriorityCount = _ticketServices.GetPriorityCount(tickets), TypeCount = _ticketServices.GetTypeCount(tickets), StatusCount = _ticketServices.GetStatusCount(tickets) }; foreach (var ticket in tickets) { ticketIndexModel.Tickets.Add(_ticketServices.FormatTicket(ticket)); } var projectIndexModel = new ProjectIndexModel(); foreach (var project in projects) { var formattedProject = await _projectServices.FormatProjectAsync(project); projectIndexModel.Projects.Add(formattedProject); } var model = new TicketProjectModel { TicketIndexModel = ticketIndexModel, ProjectIndexModel = projectIndexModel }; return(View(model)); }
public IActionResult Index() { var tickets = new List <Ticket>(); //If User is Admin, show all Tickets if (User.IsInRole("Admin")) { tickets = _ticketServices.GetAll().ToList(); } //Otherwise, show tickets only relative to the User. else { tickets = _ticketServices.GetAllByUser(_userManager.GetUserId(User)).ToList(); } var model = new TicketIndexModel(); foreach (var ticket in tickets) { model.Tickets.Add(_ticketServices.FormatTicket(ticket)); } return(View(model)); }