From 4badbb156984517ea6e4bd87fff99d0ac0b1994a Mon Sep 17 00:00:00 2001 From: gg12 darfren Date: Sun, 17 Mar 2024 11:13:42 +0400 Subject: [PATCH] One more LINQ --- .../Implements/OrderStorage.cs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/IceCreamShop/IceCreamShopDatabaseImplement/Implements/OrderStorage.cs b/IceCreamShop/IceCreamShopDatabaseImplement/Implements/OrderStorage.cs index bb3371a..8a23f6d 100644 --- a/IceCreamShop/IceCreamShopDatabaseImplement/Implements/OrderStorage.cs +++ b/IceCreamShop/IceCreamShopDatabaseImplement/Implements/OrderStorage.cs @@ -85,14 +85,10 @@ namespace IceCreamShopDatabaseImplement.Implements if (model == null) return null; using var context = new IceCreamShopDataBase(); - foreach (var iceCream in context.IceCreams) - { - if (iceCream.Id == model.IceCreamId) - { - model.IceCreamName = iceCream.IceCreamName; - break; - } - } + var iceCream = context.IceCreams.FirstOrDefault(x => (x.Id == model.IceCreamId)); + if (iceCream == null) + return model; + model.IceCreamName = iceCream.IceCreamName; return model; } }