- Replaced foreach loop with for loop for better index-based access to instructions.

- Added logic to dynamically retrieve media files for each instruction using `Request.Form.Files`.
- Ensured that media files are correctly associated with their respective instructions during recipe creation.
This commit is contained in:
franc
2025-05-05 12:01:53 +02:00
parent 7976545da6
commit 000cead877
@@ -230,14 +230,23 @@
if (model.InstructionViewModel?.Instructions != null)
{
foreach (var instruction in model.InstructionViewModel.Instructions)
for (var i = 0; i < model.InstructionViewModel.Instructions.Count; i++)
{
var instruction = model.InstructionViewModel.Instructions[i];
if (!string.IsNullOrWhiteSpace(instruction.Description))
{
var fileKey = $"InstructionViewModel.Instructions[{i}].MediaFile";
IFormFile? imageFile = null;
if (Request.Form.Files.Any(f => f.Name == fileKey))
{
imageFile = Request.Form.Files[fileKey];
}
await _instructionRepository.CreateInstructionWithImageToRecipeAsync(
recipe.Id,
instruction.Description,
null);
imageFile);
}
}
}