public static List <Job> RecentJobsForAdmin(string sortExpression = "") { List <Job> jobs = RecentJobs(); ObjectSortField osf = null; if (String.IsNullOrEmpty(sortExpression)) { jobs = jobs .OrderByDescending(j => j.JobStatus.Equals(JobStatus.Submitted)) .ThenBy(j => j.DateDue) .ThenByDescending(j => j.JobStatus.Equals(JobStatus.InProgress)) .ThenBy(j => j.JobId) .ToList(); } else if (sortExpression.ToLower().StartsWith("jobstatus.name")) // JobStatus.Name { // custom sort of job statuses for admins jobs = jobs .OrderByDescending(j => j.JobStatus.Equals(JobStatus.Submitted)) .ThenByDescending(j => j.JobStatus.Equals(JobStatus.PendingApproval)) .ThenByDescending(j => j.JobStatus.Equals(JobStatus.InReview)) .ThenByDescending(j => j.JobStatus.Equals(JobStatus.InProgress)) .ThenByDescending(j => j.JobStatus.Equals(JobStatus.Queued)) .ThenByDescending(j => j.JobStatus.Equals(JobStatus.Completed)) .ThenByDescending(j => j.JobStatus.Equals(JobStatus.Canceled)) .ToList(); if (sortExpression.ToUpper().EndsWith(" DESC")) { jobs.Reverse(); } } else { if (sortExpression.ToUpper().EndsWith(" DESC")) { osf = new ObjectSortField(sortExpression.Substring(0, sortExpression.Length - 5), ObjectSortField.SortOrders.Descending); } else { osf = new ObjectSortField(sortExpression, ObjectSortField.SortOrders.Ascending); } jobs.Sort(new ObjectComparer <Job>(new ObjectSortField[] { osf })); } return(jobs); }
public static List <Job> RecentJobsForClient(Client client, string sortExpression = "") { Debug.WriteLine("CacheLayer.RecentJobsForClient()"); List <Job> jobs = RecentJobs(); ObjectSortField osf = null; jobs = jobs.Where(j => j.Client.Equals(client) && !(j.JobStatus.Equals(JobStatus.Completed) && j.PickedUp == false)).ToList(); if (String.IsNullOrEmpty(sortExpression)) { jobs = jobs .OrderByDescending(j => j.JobStatus.Equals(JobStatus.Completed)) // desc b/c 0 comes before 1 .ThenByDescending(j => j.JobStatus.Equals(JobStatus.InProgress)) .ThenBy(j => j.DateDue) .ThenBy(j => j.JobId) .ToList(); } else { if (sortExpression.ToUpper().EndsWith(" DESC")) { osf = new ObjectSortField(sortExpression.Substring(0, sortExpression.Length - 5), ObjectSortField.SortOrders.Descending); } else { osf = new ObjectSortField(sortExpression, ObjectSortField.SortOrders.Ascending); } jobs.Sort(new ObjectComparer <Job>(new ObjectSortField[] { osf })); } foreach (Job job in jobs) { Debug.WriteLine(" - " + job.JobId.ToString()); } return(jobs); }