I am scanning a list and taking certain values, adding and saving it. In the first run I get the value, add it to an 'x' variable, and go to the second execution ...
I get the value that was added to 'x' and sum to the value of the second execution.
However, in this second execution the value instead of being added, is replaced by the value of the second execution.
public async Task<IHttpActionResult> GetNotas()
{
foreach (var us in resultQuery.ToPagedList(page, pageSize))
{
var nota = await GetNotaAsync(us);
CalcularTotais(nota);
itens.Add(nota);
}
return Ok(itens);
}
private static void CalcularTotais(NotaViewModel nota)
{
decimal totalBaseCalculo = 0;
decimal totalIss = 0;
decimal totalLiquido = 0;
if (!nota.IsIssRetido || nota.Situacao == SituacaoNota.Cancelada) {
totalBaseCalculo += nota.BaseCalculo;
totalIss += nota.Iss;
totalLiquido += nota.Liquido;
}
}
Note: this method is inside a foreach of a public method.