public async Task <AnualBalance> CalculateAndSave(AnualBalance anualBalance) { try { anualBalance.AnualBalanceResult = 0; List <Balance> balances = await _balanceRepo.GetBalancesFromYear(anualBalance.Id); foreach (Balance balance in balances) { anualBalance.AnualBalanceResult += balance.BalanceResult; } anualBalance.Positive = (anualBalance.AnualBalanceResult >= 0) ? true : false; _context.Update(anualBalance); await _context.SaveChangesAsync(); return(anualBalance); } catch (Exception) { return(null); } }
public async Task <Balance> Update(Balance balance) { try { _context.Update(balance); await _context.SaveChangesAsync(); return(balance); } catch (Exception) { return(null); } }
public async Task <IActionResult> Edit(int id, [Bind("Id,CategoryName")] EIncomeType eIncomeType) { if (id != eIncomeType.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(eIncomeType); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EIncomeTypeExists(eIncomeType.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(eIncomeType)); }
public async Task <Spending> Update(Spending entity) { try { _context.Update(entity); await _context.SaveChangesAsync(); if (await _balanceRepo.CalculateAndSave(await GetParentBalance(entity.Id)) != null) { return(entity); } return(null); } catch (Exception) { return(null); } }