Does not update value

0

The calculation and the values returns everything to me, however when it comes to overlapping the previous value and adding the new it does not change, it keeps the old one.

Buy 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 registered and subtract from the total value and add the new value typed plus the amount of stock with subtraction done previously, when I put the breakpoint in the question of the calculations, it does all right the equation of values but when it will overlap the amount that was already in the stock and the new one does not overlap.

Add (Here he makes the same equation and saves it 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;
    
asked by anonymous 27.03.2018 / 17:23

0 answers