Review Code to make more efficient

Im trying to do a condition to make sure this only fires on a post directive when all of the condtions are true. Can someone review to make sure this will work and also allow me to delete with out getting an error saying there is no labordtl record.

var ttLaborDtlRow = Epicor.Customization.Bpm.EnumerableExtensions.GetSingleRow(ds.LaborDtl, "ttLaborDtl");

if (ttLaborDtlRow.ProjectID != "" && ttLaborDtlRow.PhaseID != "" && ttLaborDtlRow.OpComplete == true && ttLaborDtlRow.RowMod == "A" && ttLaborDtlRow.ProjectDescription.Contains("ARO") || ttLaborDtlRow.ProjectDescription.Contains("ETO") )
{
  return true;
}
else 
{
return false;
}

You might want to put this section in a parenthesis.

I’m not sure what you are doing with that first line but the bottom could be condensed, and fix your OR clauses like @NateS said.

        return
            ttLaborDtlRow.ProjectID != "" &&
            ttLaborDtlRow.PhaseID != "" &&
            ttLaborDtlRow.OpComplete == true &&
            ttLaborDtlRow.RowMod == "A" &&
            (ttLaborDtlRow.ProjectDescription.Contains("ARO") || ttLaborDtlRow.ProjectDescription.Contains("ETO")); 

What i am trying to is only fire the bpm when it returns a true statement otherwise do not continue.

this is what i have updated to adjust my code not sure if that helps or not. But i need something in front of this to check if that dataset is empty on the post processing request.

Wait im stupid there is no added or updated row in a post processing it has already been committed to the database.

var laborRecordExists = ds.LaborDtl.Where(ld => ld.Added() && ld.ProjectID != "" && ld.PhaseID != "" && ld.OpComplete == true  && (ld.ProjectDescription.Contains("ARO") || ld.ProjectDescription.Contains("ETO")));

if (laborRecordExists != null)
{
  return true;
}
else 
{
return false;
}


If you do this as a .Any() then sql will return just the bool

3 Likes