I really hope I can get help here.
In my code, I have an Ienumerable of a container that has 3 things: 1) containerCode 2)drawer1 3)drawer2
drawer1 and drawer2 both has typeCode and statusCode. Now, I want to loop through drawer1 and drawer2 to check if typeCode and statusCode exists in a specific statuses. If it does, I want to throw an error message. My code somehow doesn't look at both drawers. If only one drawer has the matching status, it still throws the error message. Below is my code.
if (myObject!= null)
{
var 1stDrawer= false;
var 2ndDrawer= false;
var drawers = myObject.Collection.Where(x => x.typeCode.In(new[] { "firstDrawer", "secondDrawer" }));
foreach (var x in drawers)
{
if (x.statusCode == "ex1" && x.typeCode== "firstDrawer")
1stDrawer= true;
if (x.statusCode == "ex1" && x.typeCode == "secondDrawer")
2ndDrawer= true;
}
if (1stDrawer == true && 2ndDrawer == true && myObject.containerCode == "container")
{
context.AddErrorResult("Error was thrown");
return;
}
}
Aucun commentaire:
Enregistrer un commentaire