public async Task <IActionResult> Edit(int id, [Bind("Id,Nombre_Cliente,Direccion,Nit,Listado_Farmacos,Total_Cancelar")] PedidosFarmacos pedidosFarmacos)
        {
            if (id != pedidosFarmacos.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(pedidosFarmacos);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PedidosFarmacosExists(pedidosFarmacos.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(pedidosFarmacos));
        }
Exemplo n.º 2
0
        public IActionResult AgregarPedido2(int id, [Bind("Id,NombreDelCliente,Dirrecion,Nit,Cantidad")] PedidosFarmacos ProductModel)
        {
            ProductModel.Id = F.id;
            Farmaco nuevo = new Farmaco();

            nuevo = F.List2.Find(m => m.Id == ProductModel.Id);
            if (nuevo.Existencia < ProductModel.Cantidad)
            {
                return(RedirectToAction("ErrorCantidad", "Farmacoes"));
            }

            ProductModel.Nombre = F.nombre;
            F.Nit               = ProductModel.Nit;
            F.Nombrecliente     = ProductModel.NombreDelCliente;
            F.dirrecion         = ProductModel.Dirrecion;
            ProductModel.Precio = nuevo.Precio;
            F.Pedidos.Add(ProductModel);

            F.List2.Find(m => m.Id == ProductModel.Id).Existencia = nuevo.Existencia - ProductModel.Cantidad;
            if (nuevo.Existencia == 0)
            {
                var llave = F.Arbol_Farmacos.Find(new LlaveArbol {
                    Nombre_Farmaco = nuevo.Nombre_Farmaco
                });
                F.Arbol_Farmacos.RemoveAt(llave);
            }
            return(RedirectToAction("Index", "PedidosFarmacos"));
        }
        public async Task <IActionResult> Create([Bind("Id,Nombre_Cliente,Direccion,Nit,Listado_Farmacos,Total_Cancelar")] PedidosFarmacos pedidosFarmacos)
        {
            if (ModelState.IsValid)
            {
                _context.Add(pedidosFarmacos);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(pedidosFarmacos));
        }