I need with a if statement logic inside a foreach loop, the problem I am having is that when reading the if statements inside the loop when my loop does the return I am getting the wrong results.
the foreach loop is reading a coming data from a list and then make the decision in the foreach loop based on the if statements
list return method so here in my code for example if data coming in for 5 records and for establishment contains 038 are 4 records and 1 record for establishment 088 when I get the return of that data I get 1 038 then 088 then again 038 and then 088 and so on, and it shouldn't be like that it should return 4 038 and 1 088, so the lotlist return will return a string for example 111920-325 but that is not the problem the problem I am having is the logic of the if statements in the loop
public List<string> ParseLot()
{
var lotList = new List<string>();
var establishmentList = GetEstablishmentCode();
foreach (var lot in GetBarcodeList())
{
if (establishmentList.Contains("038"))
{
lotList.Add(lot.Substring(28, 6) + _lotEstablishment.LoganSport038Property);
}
if (establishmentList.Contains("072"))
{
lotList.Add(lot.Substring(28, 6) + _lotEstablishment.LouisaCounty072Property);
}
if (establishmentList.Contains("086"))
{
lotList.Add(lot.Substring(28, 6) + _lotEstablishment.Madison086Property);
}
if (establishmentList.Contains("089"))
{
lotList.Add(lot.Substring(28, 6) + _lotEstablishment.Perry089Property);
}
if (establishmentList.Contains("069"))
{
lotList.Add(lot.Substring(28, 6) + _lotEstablishment.StormLake069Property);
}
if (establishmentList.Contains("088"))
{
lotList.Add(lot.Substring(28, 6) + _lotEstablishment.Waterloo088Property);
}
if (establishmentList.Contains("265"))
{
lotList.Add(lot.Substring(28, 6) + _lotEstablishment.GoodLetsVille265Property);
}
if (establishmentList.Contains("087"))
{
lotList.Add(lot.Substring(28, 6) + _lotEstablishment.CouncilBluffs087Property);
}
if (establishmentList.Contains("064"))
{
lotList.Add(lot.Substring(28, 6) + _lotEstablishment.Sherman064Property);
}
}
return lotList;
}
here is the lotstablishment class
public class LotEstablishment
{
// private variable field (access modifiers)
private const string LoganSport038 = "-244I";
private const string LouisaCounty072 = "-244L";
private const string Madison086 = "-244M";
private const string Perry089 = "-244P";
private const string StormLake069 = "-244";
private const string Waterloo088 = "-244W";
private const string GoodLetsVille265 = "-244G";
private const string CouncilBluffs087 = "-244C";
private const string Sherman064 = "-244S";
// properties
public string LoganSport038Property => LoganSport038;
public string LouisaCounty072Property => LouisaCounty072;
public string Madison086Property => Madison086;
public string Perry089Property => Perry089;
public string StormLake069Property => StormLake069;
public string Waterloo088Property => Waterloo088;
public string GoodLetsVille265Property => GoodLetsVille265;
public string CouncilBluffs087Property => CouncilBluffs087;
public string Sherman064Property => Sherman064;
}
calling lot stablishment method
public List<string> GetEstablishmentCode()
{
var establishmentList = new List<string>();
foreach (var establishmentCode in GetBarcodeList())
{
establishmentList.Add(establishmentCode.Substring(36, 3));
}
return establishmentList;
}
so again, the end result for the lostList return should be based on the if statements inside the foreach loop.
I couldn't find any solid solution in other questions in stackoverflow or google.
Aucun commentaire:
Enregistrer un commentaire