public ActionResult GuardarTalonario(Talonario talonario)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new TalonarioViewModel(talonario)
                {
                    Cajas = _context.Cajas.ToList()
                };

                return(View("TalonarioFormulario", viewModel));
            }

            if (talonario.Id == 0)
            {
                talonario.FechaInicioVigencia = Convert.ToDateTime(talonario.FechaIni);
                talonario.FechaFinVigencia    = Convert.ToDateTime(talonario.FechaFin);
                talonario.NumeroFacturaActual = talonario.NumeroFacturaInicial;
                _context.Talonarios.Add(talonario);
            }
            else
            {
                var talonarioBD = _context.Talonarios.Single(t => t.Id == talonario.Id);
                Mapper.Map <Talonario, Talonario>(talonario, talonarioBD);
                talonarioBD.NumeroFacturaActual = talonario.NumeroFacturaInicial;
                talonarioBD.FechaInicioVigencia = Convert.ToDateTime(talonario.FechaIni);
                talonarioBD.FechaFinVigencia    = Convert.ToDateTime(talonario.FechaFin);
            }

            _context.SaveChanges();

            return(RedirectToAction("Index"));
        }
        public ActionResult NuevoTalonario()
        {
            var talonario = new TalonarioViewModel
            {
                Cajas = _context.Cajas.ToList()
            };

            return(View("TalonarioFormulario", talonario));
        }
        public ActionResult EditarTalonario(int id)
        {
            var talonario = _context.Talonarios.SingleOrDefault(t => t.Id == id);

            if (talonario == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new TalonarioViewModel(talonario);

            return(View("TalonarioFormulario", viewModel));
        }
        public ActionResult EditarTalonario(int id)
        {
            var talonario = _context.Talonarios.SingleOrDefault(t => t.Id == id);

            if (talonario == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new TalonarioViewModel(talonario)
            {
                Cajas = _context.Cajas.ToList()
            };

            viewModel.FechaIni = viewModel.FechaInicioVigencia.ToString();
            viewModel.FechaFin = viewModel.FechaFinVigencia.ToString();
            return(View("TalonarioFormulario", viewModel));
        }
        public ActionResult GuardarTalonario(Talonario talonario)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new TalonarioViewModel(talonario);

                return(View("TalonarioFormulario", viewModel));
            }

            if (talonario.Id == 0)
            {
                _context.Talonarios.Add(talonario);
            }
            else
            {
                var talonarioBD = _context.Talonarios.Single(t => t.Id == talonario.Id);
                Mapper.Map <Talonario, Talonario>(talonario, talonarioBD);
            }

            _context.SaveChanges();

            return(RedirectToAction("Index"));
        }
        public ActionResult NuevoTalonario()
        {
            var talonario = new TalonarioViewModel();

            return(View("TalonarioFormulario", talonario));
        }