public async Task <IActionResult> Edit(int id, [Bind("Id,BalanceId,Category,Description,Amount,Date")] Spending spending) { if (id != spending.Id) { return(NotFound()); } if (ModelState.IsValid) { try { if (await _repository.Update(spending) != null) { return(RedirectToAction(nameof(Details), "Balance", new { id = spending.BalanceId }, null)); } } catch (DbUpdateConcurrencyException) { if (!_repository.SpendingExists(spending.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(spending)); }
public async Task <IActionResult> PutSpending(int id, Spending spending) { try { if (id != spending.Id) { return(BadRequest()); } if (await _repository.Update(spending) == null) { return(BadRequest()); } await _repository.UpdateBalance(spending.BalanceId); return(NoContent()); } catch (Exception) { if (!_repository.Exist(id)) { return(NotFound()); } else { return(BadRequest()); } } }
public void Update_Test() { item.Id = 1; item.Description = "bla bla"; item.SpendingDate = DateTime.Now; item.MoneySpent = 5; item.MoneySpent = 7; spendingRepo.Update(item); }