Does not update value

Asked

Viewed 75 times

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.

  • 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 the Estoque.Quantidade

  • Entity ? is saving ?

  • We need to know how you’re saving the object in the bank

  • I’m using Nhibernate to make the connection to the bank

  • on the line Estoque.Quantidade = quantidadefinal; he passes the value to the property Estoque.Quantidade?. put the code of Update

  • @Barbetta ready

  • I couldn’t identify it there in the code where you give update in the object Estoque. it’s him you’re trying to change, right?

  • It seems that the update is performed on dao.Update(compra);. Check whether the object compra is with the correct information.

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.