diff --git a/CutList.Mcp/InventoryTools.cs b/CutList.Mcp/InventoryTools.cs index f568258..f4a0715 100644 --- a/CutList.Mcp/InventoryTools.cs +++ b/CutList.Mcp/InventoryTools.cs @@ -117,6 +117,7 @@ public class InventoryTools var materials = await query .OrderBy(m => m.Shape) + .ThenBy(m => m.SortOrder) .ThenBy(m => m.Size) .ToListAsync(); @@ -313,6 +314,7 @@ public class InventoryTools return await query .Select(d => d.Material) .OrderBy(m => m.Shape) + .ThenBy(m => m.SortOrder) .ThenBy(m => m.Size) .ToListAsync(); } @@ -322,7 +324,7 @@ public class InventoryTools { var flatBars = await SearchByDimension(d => d.Width >= minValue && d.Width <= maxValue, shape); var rectTubes = await SearchByDimension(d => d.Width >= minValue && d.Width <= maxValue, shape); - return flatBars.Concat(rectTubes).OrderBy(m => m.Shape).ThenBy(m => m.Size).ToList(); + return flatBars.Concat(rectTubes).OrderBy(m => m.Shape).ThenBy(m => m.SortOrder).ThenBy(m => m.Size).ToList(); } // Height is used by RectangularTube, Channel, IBeam @@ -331,7 +333,7 @@ public class InventoryTools var rectTubes = await SearchByDimension(d => d.Height >= minValue && d.Height <= maxValue, shape); var channels = await SearchByDimension(d => d.Height >= minValue && d.Height <= maxValue, shape); var ibeams = await SearchByDimension(d => d.Height >= minValue && d.Height <= maxValue, shape); - return rectTubes.Concat(channels).Concat(ibeams).OrderBy(m => m.Shape).ThenBy(m => m.Size).ToList(); + return rectTubes.Concat(channels).Concat(ibeams).OrderBy(m => m.Shape).ThenBy(m => m.SortOrder).ThenBy(m => m.Size).ToList(); } // Size is used by SquareBar, SquareTube @@ -339,7 +341,7 @@ public class InventoryTools { var squareBars = await SearchByDimension(d => d.Size >= minValue && d.Size <= maxValue, shape); var squareTubes = await SearchByDimension(d => d.Size >= minValue && d.Size <= maxValue, shape); - return squareBars.Concat(squareTubes).OrderBy(m => m.Shape).ThenBy(m => m.Size).ToList(); + return squareBars.Concat(squareTubes).OrderBy(m => m.Shape).ThenBy(m => m.SortOrder).ThenBy(m => m.Size).ToList(); } // Thickness is used by FlatBar, Angle @@ -347,7 +349,7 @@ public class InventoryTools { var flatBars = await SearchByDimension(d => d.Thickness >= minValue && d.Thickness <= maxValue, shape); var angles = await SearchByDimension(d => d.Thickness >= minValue && d.Thickness <= maxValue, shape); - return flatBars.Concat(angles).OrderBy(m => m.Shape).ThenBy(m => m.Size).ToList(); + return flatBars.Concat(angles).OrderBy(m => m.Shape).ThenBy(m => m.SortOrder).ThenBy(m => m.Size).ToList(); } // Wall is used by RoundTube, SquareTube, RectangularTube, Pipe @@ -357,7 +359,7 @@ public class InventoryTools var squareTubes = await SearchByDimension(d => d.Wall >= minValue && d.Wall <= maxValue, shape); var rectTubes = await SearchByDimension(d => d.Wall >= minValue && d.Wall <= maxValue, shape); var pipes = await SearchByDimension(d => d.Wall != null && d.Wall >= minValue && d.Wall <= maxValue, shape); - return roundTubes.Concat(squareTubes).Concat(rectTubes).Concat(pipes).OrderBy(m => m.Shape).ThenBy(m => m.Size).ToList(); + return roundTubes.Concat(squareTubes).Concat(rectTubes).Concat(pipes).OrderBy(m => m.Shape).ThenBy(m => m.SortOrder).ThenBy(m => m.Size).ToList(); } private static MaterialDimensions? CreateDimensionsForShape( @@ -825,13 +827,14 @@ public class InventoryTools }; } - // Parse material type - if (!Enum.TryParse(type, ignoreCase: true, out var parsedType)) + // Parse material type (default to Steel if not provided) + var typeValue = string.IsNullOrWhiteSpace(type) ? "Steel" : type; + if (!Enum.TryParse(typeValue, ignoreCase: true, out var parsedType)) { return new AddStockWithOfferingResult { Success = false, - Error = $"Unknown material type: {type}. Valid types are: Steel, Aluminum, Stainless, Brass, Copper" + Error = $"Unknown material type: {typeValue}. Valid types are: Steel, Aluminum, Stainless, Brass, Copper" }; } diff --git a/CutList.Web/Controllers/MaterialsController.cs b/CutList.Web/Controllers/MaterialsController.cs index 49a8c19..eebb367 100644 --- a/CutList.Web/Controllers/MaterialsController.cs +++ b/CutList.Web/Controllers/MaterialsController.cs @@ -22,6 +22,7 @@ public class MaterialsController : ControllerBase var materials = await _context.Materials .Where(m => m.IsActive) .OrderBy(m => m.Shape) + .ThenBy(m => m.SortOrder) .ThenBy(m => m.Size) .Select(m => new MaterialDto { diff --git a/CutList.Web/Services/MaterialService.cs b/CutList.Web/Services/MaterialService.cs index cf9caf8..251eb2f 100644 --- a/CutList.Web/Services/MaterialService.cs +++ b/CutList.Web/Services/MaterialService.cs @@ -157,7 +157,7 @@ public class MaterialService .Where(d => d.Material.IsActive) .Where(d => d.Diameter >= minValue && d.Diameter <= maxValue) .Select(d => d.Material) - .OrderBy(m => m.Size) + .OrderBy(m => m.SortOrder).ThenBy(m => m.Size) .ToListAsync(); } @@ -174,7 +174,7 @@ public class MaterialService .Where(d => d.Material.IsActive) .Where(d => d.OuterDiameter >= minValue && d.OuterDiameter <= maxValue) .Select(d => d.Material) - .OrderBy(m => m.Size) + .OrderBy(m => m.SortOrder).ThenBy(m => m.Size) .ToListAsync(); } @@ -191,7 +191,7 @@ public class MaterialService .Where(d => d.Material.IsActive) .Where(d => d.Width >= minValue && d.Width <= maxValue) .Select(d => d.Material) - .OrderBy(m => m.Size) + .OrderBy(m => m.SortOrder).ThenBy(m => m.Size) .ToListAsync(); } @@ -208,7 +208,7 @@ public class MaterialService .Where(d => d.Material.IsActive) .Where(d => d.Size >= minValue && d.Size <= maxValue) .Select(d => d.Material) - .OrderBy(m => m.Size) + .OrderBy(m => m.SortOrder).ThenBy(m => m.Size) .ToListAsync(); } @@ -225,7 +225,7 @@ public class MaterialService .Where(d => d.Material.IsActive) .Where(d => d.Size >= minValue && d.Size <= maxValue) .Select(d => d.Material) - .OrderBy(m => m.Size) + .OrderBy(m => m.SortOrder).ThenBy(m => m.Size) .ToListAsync(); } @@ -242,7 +242,7 @@ public class MaterialService .Where(d => d.Material.IsActive) .Where(d => d.Width >= minValue && d.Width <= maxValue) .Select(d => d.Material) - .OrderBy(m => m.Size) + .OrderBy(m => m.SortOrder).ThenBy(m => m.Size) .ToListAsync(); } @@ -259,7 +259,7 @@ public class MaterialService .Where(d => d.Material.IsActive) .Where(d => d.Leg1 >= minValue && d.Leg1 <= maxValue) .Select(d => d.Material) - .OrderBy(m => m.Size) + .OrderBy(m => m.SortOrder).ThenBy(m => m.Size) .ToListAsync(); } @@ -276,7 +276,7 @@ public class MaterialService .Where(d => d.Material.IsActive) .Where(d => d.Height >= minValue && d.Height <= maxValue) .Select(d => d.Material) - .OrderBy(m => m.Size) + .OrderBy(m => m.SortOrder).ThenBy(m => m.Size) .ToListAsync(); } @@ -293,7 +293,7 @@ public class MaterialService .Where(d => d.Material.IsActive) .Where(d => d.Height >= minValue && d.Height <= maxValue) .Select(d => d.Material) - .OrderBy(m => m.Size) + .OrderBy(m => m.SortOrder).ThenBy(m => m.Size) .ToListAsync(); } @@ -310,7 +310,7 @@ public class MaterialService .Where(d => d.Material.IsActive) .Where(d => d.NominalSize >= minValue && d.NominalSize <= maxValue) .Select(d => d.Material) - .OrderBy(m => m.Size) + .OrderBy(m => m.SortOrder).ThenBy(m => m.Size) .ToListAsync(); } @@ -328,7 +328,7 @@ public class MaterialService query = query.Where(m => m.IsActive); } - return await query.OrderBy(m => m.Size).ToListAsync(); + return await query.OrderBy(m => m.SortOrder).ThenBy(m => m.Size).ToListAsync(); } ///