0
Calculus and values return me all right, but when overriding the previous value and add the new one it does not change, keep the old one.
Compra Controller:
public ActionResult Update(CompraModel viewModel)
{
var ConsultaAntigo = ckm.Compra(viewModel.Quant);
var Antigo = ConsultaAntigo.Where(c => c.Id == c.Id).FirstOrDefault();
var Consulta = ckm.ControleEstoque(viewModel.ProdutoId);
var Estoque = Consulta.OrderBy(t => t.NomeProduto).FirstOrDefault();
int AntigoFinal = Estoque.Quantidade - Antigo.Quant;
Estoque.Quantidade = AntigoFinal;
int quantidadefinal = Estoque.Quantidade + viewModel.Quant;
Estoque.Quantidade = quantidadefinal;
viewModel.VlrTotal = viewModel.VlrUnit * viewModel.Quant;
//-------------/\ Pega o valor antigo e retira do estoque /\-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
if (ModelState.IsValid)
{
Compra compra = viewModel.CriaCompra();
dao.Update(compra);
return RedirectToAction("Index");
}
else
{
ViewBag.Estoque = estoqueDAO.Lista();
ViewBag.Fornecedores = fornecedoresDAO.Lista();
return View("FormUpdate", viewModel);
}
}
The idea of the update is to take the value already recorded and subtract from the total value and add the new value typed plus the amount of the stock with subtraction made earlier, when I put the breakpoint in the question of calculations, it does everything right the equation of values but when it will override the amount that was already in the stock and for the new it does not overlap.
Add(Here he makes the same equation and saves normally in stock):
var Consulta = ckm.ControleEstoque(viewModel.ProdutoId);
var Estoque = Consulta.OrderBy(t => t.NomeProduto).FirstOrDefault();
int quantidadefinal = Estoque.Quantidade + viewModel.Quant;
Estoque.Quantidade = quantidadefinal;
I don’t understand. Is the update working or not? Is the update of the values in the controller or in the bank a problem? Show how you’re saving the transaction.
– DiegoSantos
The values and the calculation that performs is all ok, the problem is that in the end it does not transfer the new value that is
QuantidadeFinal
to theEstoque.Quantidade
– Guilherme Padovam
Entity ? is saving ?
– Rovann Linhalis
We need to know how you’re saving the object in the bank
– DiegoSantos
I’m using Nhibernate to make the connection to the bank
– Guilherme Padovam
on the line
Estoque.Quantidade = quantidadefinal;
he passes the value to the propertyEstoque.Quantidade
?. put the code ofUpdate
– Barbetta
@Barbetta ready
– Guilherme Padovam
I couldn’t identify it there in the code where you give
update
in the objectEstoque
. it’s him you’re trying to change, right?– Barbetta
It seems that the update is performed on
dao.Update(compra);
. Check whether the objectcompra
is with the correct information.– StanleyIPC