From f89cf27be46b57ced2bd8fde7e1b80c55c1da224 Mon Sep 17 00:00:00 2001 From: Francesco Lorenzo D'Amico Date: Tue, 20 May 2025 14:26:14 +0200 Subject: [PATCH] Add LIst instead of use an 2 dimensional array --- .../Views/Shared/_RecipeInstructionGridPartial.cshtml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Francesco.Recipes.World/Views/Shared/_RecipeInstructionGridPartial.cshtml b/Francesco.Recipes.World/Views/Shared/_RecipeInstructionGridPartial.cshtml index 2a7b44b..ed4f682 100644 --- a/Francesco.Recipes.World/Views/Shared/_RecipeInstructionGridPartial.cshtml +++ b/Francesco.Recipes.World/Views/Shared/_RecipeInstructionGridPartial.cshtml @@ -6,12 +6,16 @@
@{ var groupedInstructions = Model.Instructions.OrderBy(i => i.Number).ToList(); - var rows = (int)Math.Ceiling(groupedInstructions.Count / 3.0); + var instructionRows = groupedInstructions + .Select((instruction, index) => new { Instruction = instruction, Index = index }) + .GroupBy(x => x.Index / 3) + .Select(g => g.Select(x => x.Instruction).ToList()) + .ToList(); - for (int row = 0; row < rows; row++) + foreach (var row in instructionRows) {
- @for (int col = 0; col < 3 && (row * 3 + col < groupedInstructions.Count); col++) + @for (var instruction in row) { var instruction = groupedInstructions[row * 3 + col];