Exemple #1
0
        public ActionResult Create(TarjetaEditViewModel tVm)
        {
            if (!ModelState.IsValid)
            {
                tVm.CarteraDeConsumo = _mapper.Map <List <CarteraDeConsumoListViewModel> >(_servicioCarteraDeConsumo.GetLista());
                tVm.Clientes         = _mapper.Map <List <ClienteListViewModel> >(_servicioCliente.GetLista(null, null, null));
                return(View(tVm));
            }

            TarjetaEditDto tarjetaDto = _mapper.Map <TarjetaEditDto>(tVm);

            if (_servicio.Existe(tarjetaDto))
            {
                ModelState.AddModelError(string.Empty, @"Tarjeta existente");
                tVm.CarteraDeConsumo = _mapper.Map <List <CarteraDeConsumoListViewModel> >(_servicioCarteraDeConsumo.GetLista());
                tVm.Clientes         = _mapper.Map <List <ClienteListViewModel> >(_servicioCliente.GetLista(null, null, null));
                return(View(tVm));
            }

            try
            {
                _servicio.Guardar(tarjetaDto);

                TempData["Msg"] = "Tarjeta agregado";
                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                ModelState.AddModelError(string.Empty, e.Message);
                tVm.CarteraDeConsumo = _mapper.Map <List <CarteraDeConsumoListViewModel> >(_servicioCarteraDeConsumo.GetLista());
                tVm.Clientes         = _mapper.Map <List <ClienteListViewModel> >(_servicioCliente.GetLista(null, null, null));
                return(View(tVm));
            }
        }
Exemple #2
0
        public ActionResult Create()
        {
            TarjetaEditViewModel tVm = new TarjetaEditViewModel
            {
                CarteraDeConsumo = _mapper.Map <List <CarteraDeConsumoListViewModel> >(_servicioCarteraDeConsumo.GetLista()),
                Clientes         = _mapper.Map <List <ClienteListViewModel> >(_servicioCliente.GetLista(null, null, null))
            };

            return(View(tVm));
        }
Exemple #3
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            TarjetaEditDto       tEditDto = _servicio.GetTarjetaPorId(id);
            TarjetaEditViewModel tVm      = _mapper.Map <TarjetaEditViewModel>(tEditDto);

            tVm.CarteraDeConsumo = _mapper.Map <List <CarteraDeConsumoListViewModel> >(_servicioCarteraDeConsumo.GetLista());
            tVm.Clientes         = _mapper.Map <List <ClienteListViewModel> >(_servicioCliente.GetLista(null, null, null));
            return(View(tVm));
        }