Sorry for the question, I'm learning Asp.NET with EF and I'm having trouble performing a specific Update.
I want to make a system where there are cash transactions between accounts. The structural part is ok, but the problem is this:
When I perform the first update, the system does the transfer normally, that is, both accounts have $ 100.00, I make the transaction $ 10.00, and one account is $ 90.00 and another with R $ 110.00.
In the second transfer of the same value, an account is $ 80 and another with $ 100.
[HttpPost]
public ActionResult TransferCurrency(Usuario usuario, ViewModelTransfer viewModel)
{
if (usuario.Id == 0)
{
return HttpNotFound();
}
if (viewModel.ForId == null)
{
return HttpNotFound();
}
var usuarioTransaction = _context.Usuario.Single(c => c.NConta == viewModel.ForId);
usuarioTransaction.Currency = usuario.Currency + viewModel.Transfer;
var usuarioInDb = _context.Usuario.Single(m => m.Id == usuario.Id);
usuarioInDb.Currency = usuario.Currency - viewModel.Transfer;
_context.SaveChanges();
return RedirectToAction("Index");
}
Does anyone know the solution?
I know it's pretty basic, but I'm not able to develop logic.