public IActionResult PorTurno(int id, ControlExistenciaVM controlExistencia)
        {
            var control = _context.Set <ControlExistenciaVenta>()
                          .SingleOrDefault(c => c.Id == controlExistencia.Id);

            if (control == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    foreach (var item in controlExistencia.Detalles)
                    {
                        var producto = _context.Set <Producto>().Find(item.ProductoId);
                        if (_context.Set <DetalleControlExistenciaVenta>().Any(d => d.ControlId == control.Id && d.ProductoId == item.ProductoId))
                        {
                            var detalle = _context.Set <DetalleControlExistenciaVenta>().SingleOrDefault(d => d.ControlId == control.Id && d.ProductoId == item.ProductoId);
                            detalle.Cantidad = item.Cantidad;
                            detalle.Costo    = producto.Costo;
                            detalle.Precio   = producto.Precio;
                            _context.Update(detalle);
                        }
                        else
                        {
                            _context.Add(new DetalleControlExistenciaVenta {
                                ControlId = control.Id, ProductoId = item.ProductoId, Cantidad = item.Cantidad, Costo = producto.Costo, Precio = producto.Precio
                            });
                        }
                    }
                    _context.SaveChanges();
                    TempData["exito"] = "La acción se ha realizado correctamente";
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ControlExistenciaExists(controlExistencia.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Detalles), new { Id = control.Id }));
            }
            TempData["error"] = "Error en realizar esta acción";
            return(View(controlExistencia));
        }
예제 #2
0
        public IActionResult Edit(int id, [Bind("Id,ProductoId,Cantidad,DestinoId,TurnoId,UsuarioId,Fecha")] TrasladoVenta traslado)
        {
            if (id != traslado.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(traslado);
                    TempData["exito"] = "La acción se ha realizado correctamente";
                    _context.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TrasladoExists(traslado.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DestinoId"]  = new SelectList(_context.Bares, "Id", "Nombre", traslado.DestinoId);
            ViewData["ProductoId"] = new SelectList(_context.Productos, "Id", "Nombre", traslado.ProductoId);
            ViewData["TurnoId"]    = traslado.TurnoId;
            TempData["error"]      = "Error en ralizar esta acción";
            return(View(traslado));
        }
예제 #3
0
        public IActionResult Edit(int id, [Bind("Id,ProductoId,Cantidad,TurnoId")] EntregaDeAlmacenVenta entrada)
        {
            if (id != entrada.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(entrada);
                    TempData["exito"] = "La acción se ha realizado correctamente";
                    _context.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TrasladoExists(entrada.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductoId"] = new SelectList(_context.Productos, "Id", "Nombre", entrada.ProductoId);
            ViewData["TurnoId"]    = entrada.TurnoId;
            TempData["error"]      = "Error en ralizar esta acción";
            return(View(entrada));
        }
        public IActionResult Edit(int id, [Bind("Id,FechaInicio,FechaFin,Activo,DependienteId,BarId")] Turno turno)
        {
            if (id != turno.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(turno);
                    TempData["exito"] = "La acción se ha realizado correctamente";
                    _context.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TurnoExists(turno.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BarId"]         = new SelectList(_context.Bares, "Id", "Nombre", turno.BarId);
            ViewData["DependienteId"] = new SelectList(_context.Dependientes, "Id", "NombreCompleto", turno.DependienteId);
            TempData["error"]         = "Error en ralizar esta acción";
            return(View(turno));
        }