Untitled

mail@pastecode.io avatar
unknown
csharp
a year ago
4.1 kB
2
Indexable
Never
switch (sortOrder)
            {
                case "Priority":
                    if (sort == true)
                    {
                        SortedProjs =
                        await _context.Projects
                        .Include(p => p.CreatedBy)
                        .Include(p => p.AssignedTo)
                        .ThenInclude(at => at.ApplicationUser)
                        .Include(p => p.Tickets.OrderByDescending(t => t.TicketPriority))
                        .ThenInclude(t => t.Owner)
                        .ToListAsync();
                    }
                    else
                    {
                        SortedProjs =
                        await _context.Projects
                        .Include(p => p.CreatedBy)
                        .Include(p => p.AssignedTo)
                        .ThenInclude(at => at.ApplicationUser)
                        .Include(p => p.Tickets.OrderBy(t => t.TicketPriority))
                        .ThenInclude(t => t.Owner)
                        .ToListAsync();
                    }

                    break;
                case "RequiredHrs":
                    if (sort == true)
                    {
                        SortedProjs =
                        await _context.Projects
                        .Include(p => p.CreatedBy)
                        .Include(p => p.AssignedTo)
                        .ThenInclude(at => at.ApplicationUser)
                        .Include(p => p.Tickets.OrderByDescending(t => t.RequiredHours))
                        .ThenInclude(t => t.Owner)
                        .ToListAsync();
                    }
                    else
                    {
                        SortedProjs =
                        await _context.Projects
                        .Include(p => p.CreatedBy)
                        .Include(p => p.AssignedTo)
                        .ThenInclude(at => at.ApplicationUser)
                        .Include(p => p.Tickets.OrderBy(t => t.RequiredHours))
                        .ThenInclude(t => t.Owner)
                        .ToListAsync();
                    }

                    break;
                case "Completed":
                    SortedProjs =
                        await _context.Projects
                        .Include(p => p.CreatedBy)
                        .Include(p => p.AssignedTo)
                        .ThenInclude(at => at.ApplicationUser)
                        .Include(p => p.Tickets.Where(t => t.Completed == true))
                        .ThenInclude(t => t.Owner)
                        .ToListAsync();
                    break;
                default:
                    if (userId != null)
                    {
                        SortedProjs =
                        await _context.Projects
                        .OrderBy(p => p.ProjectName)
                        .Include(p => p.CreatedBy)
                        .Include(p => p.AssignedTo)
                        .ThenInclude(at => at.ApplicationUser)
                        .Include(p => p.Tickets.Where(t => t.Owner.Id.Equals(userId)))
                        .ThenInclude(t => t.Owner)
                        .Include(p => p.Tickets).ThenInclude(t => t.TicketWatchers).ThenInclude(tw => tw.Watcher)
                        .ToListAsync();
                    }
                    else
                    {
                        SortedProjs =
                        await _context.Projects
                        .OrderBy(p => p.ProjectName)
                        .Include(p => p.CreatedBy)
                        .Include(p => p.AssignedTo)
                        .ThenInclude(at => at.ApplicationUser)
                        .Include(p => p.Tickets)
                        .ThenInclude(t => t.Owner)
                        .Include(p => p.Tickets).ThenInclude(t => t.TicketWatchers).ThenInclude(tw => tw.Watcher)
                        .ToListAsync();
                    }

                    break;