diff --git a/Api.SeaHavenIndustries/Controllers/WorkOrderController.cs b/Api.SeaHavenIndustries/Controllers/WorkOrderController.cs index 929d29a..0bb4a43 100644 --- a/Api.SeaHavenIndustries/Controllers/WorkOrderController.cs +++ b/Api.SeaHavenIndustries/Controllers/WorkOrderController.cs @@ -369,7 +369,7 @@ namespace Api.SeaHavenIndustries.Controllers // GET: api/WorkOrder/GetWorkOrderList // ----------------------------------- [HttpGet("GetWorkOrderList")] - public IActionResult GetWorkOrderList(string? search = "", int page = 1, int pageSize = 12) + public IActionResult GetWorkOrderList(string? search = "", int page = 1, int pageSize = 12, string? sortBy = "lastUpdated", string? sortDir = "desc") { search ??= ""; @@ -392,8 +392,21 @@ namespace Api.SeaHavenIndustries.Controllers var totalCount = query.Count(); - var data = query - .OrderByDescending(w => w.Id) + var isAsc = sortDir?.ToLower() == "asc"; + IOrderedQueryable ordered = (sortBy?.ToLower()) switch + { + "number" => isAsc ? query.OrderBy(w => w.InternalWONumber) : query.OrderByDescending(w => w.InternalWONumber), + "title" => isAsc ? query.OrderBy(w => w.WorkerOrderTitle) : query.OrderByDescending(w => w.WorkerOrderTitle), + "location" => isAsc ? query.OrderBy(w => w.Locations != null ? w.Locations.Name : "") : query.OrderByDescending(w => w.Locations != null ? w.Locations.Name : ""), + "priority" => isAsc ? query.OrderBy(w => w.Priority) : query.OrderByDescending(w => w.Priority), + "status" => isAsc ? query.OrderBy(w => w.Status) : query.OrderByDescending(w => w.Status), + "createddate" => isAsc ? query.OrderBy(w => w.CreatedDate) : query.OrderByDescending(w => w.CreatedDate), + "assignedto" => isAsc ? query.OrderBy(w => w.AssignToUser != null ? w.AssignToUser.FirstName : "") : query.OrderByDescending(w => w.AssignToUser != null ? w.AssignToUser.FirstName : ""), + "lastupdated" => isAsc ? query.OrderBy(w => w.LastModificationTime) : query.OrderByDescending(w => w.LastModificationTime), + _ => query.OrderByDescending(w => w.Id) + }; + + var data = ordered .Skip((page - 1) * pageSize) .Take(pageSize) .Select(w => new