0

I would like to ask there is it possible to run the

if 
clause together with this. Because that I have a dozens of sections to generate, so is there a way on make all these
if
clause to do check at the same time using async task.

public bool GenerateCategory(List<AllFoodSpendList> allFoodSpendList,Sections section,)
{
if (section.Protein == true || section.Fats == true || section.Grains == true)
{
    List<bool> report = new List<bool>();

    //RUN ACTION WHEN THE IF IS TRUE
    if (section.Protein == true)
    { 
    List< AllFoodSpendList> allFoodList = new List< AllFoodSpendList >();
    foreach(var item in allFoodList.Where(x => x.Type == Protein))
    {
        allFoodList .Add(new AllFoodSpendList ()
                    {
                        Spend = item.Spend,
                        Calori = item.Calori,
                    });
    }

    List< AllFoodSpendList> record = allFoodList.ToList();
    proteinText = JsonConvert.SerializeObject(record);
        if(record.Count > 0)
    {
        report.Add(true);
    }else{
        Report.Add(false);
    }

    }
    
    //RUN ACTION WHEN THE IF IS TRUE
    if (section.Fats == true)
    {
    List< AllFoodSpendList> allFoodList = new List< AllFoodSpendList >();
    foreach(var item in allFoodList.Where(x => x.Type == Protein))
    {
        allFoodList .Add(new AllFoodSpendList ()
                    {
                        Spend = item.Spend,
                        Calori = item.Calori,
                    });
    }

    List< AllFoodSpendList> record = allFoodList.ToList();
    fatsText = JsonConvert.SerializeObject(record);
    if(record.Count > 0)
    {
        report.Add(true);
    }else{
        Report.Add(false);
    }

    }
    //RUN ACTION WHEN THE IF IS TRUE
    if (section.Grains == true)
    {

    List< AllFoodSpendList> allFoodList = new List< AllFoodSpendList >();
    foreach(var item in allFoodList.Where(x => x.Type == Protein))
    {
        allFoodList .Add(new AllFoodSpendList ()
                    {
                        Spend = item.Spend,
                        Calori = item.Calori,
                    });
    }
    List< AllFoodSpendList> record = allFoodList.ToList();
    grainsText = JsonConvert.SerializeObject(record);
    if(record.Count > 0)
    {
        report.Add(true);
    }else{
        Report.Add(false);
    }
}

if (!report.Contains(false))
{
    return true;
}
return false;

}


}
Anonymous Asked question May 14, 2021