0
Sorry for the question, I am learning Asp.NET with EF and am having problems 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 the following:
When I perform the first update, the system makes the transfer normally, IE, both accounts have R $ 100,00, I make the transaction of R $ 10,00, and one account has R $ 90,00 and another with R $ 110,00.
In the second transfer of the same amount, one account is R $ 80 and another with R $ 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");
}
Someone knows the solution?
I know it’s pretty basic, but I’m not getting the logic.
Take a look at the assignment, there’s the problem! picking up wrong values
– novic