예제 #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));
            }
        }
예제 #2
0
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            TarjetaEditDto tEditDto = _servicio.GetTarjetaPorId(id);

            if (tEditDto == null)
            {
                return(HttpNotFound("Tarjeta inexistente"));
            }

            TarjetaListDto tDto             = _mapper.Map <TarjetaListDto>(_servicio.GetTarjetaPorId(id));
            var            carteraDeConsumo = _servicioCarteraDeConsumo.GetCarteraDeConsumoId(tEditDto.CarteraDeConsumoId);
            var            cliente          = _servicioCliente.GetClientePorId(tEditDto.ClienteId);

            tDto.CarteraDeConsumo = carteraDeConsumo.Descripcion;
            tDto.Cliente          = cliente.NumeroDeDocumento;

            TarjetaListViewModel tVm = _mapper.Map <TarjetaListViewModel>(tDto);

            return(View(tVm));
        }
예제 #3
0
 public bool Existe(TarjetaEditDto tarjetaEditDto)
 {
     try
     {
         Tarjeta tarjeta = _mapper.Map <Tarjeta>(tarjetaEditDto);
         return(_repositorio.Existe(tarjeta));
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
예제 #4
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));
        }
예제 #5
0
 public void Guardar(TarjetaEditDto tarjetaDto)
 {
     try
     {
         Tarjeta tarjeta = _mapper.Map <Tarjeta>(tarjetaDto);
         _repositorio.Guardar(tarjeta);
         _unitOfWork.Save();
         tarjetaDto.TarjetaId = tarjeta.TarjetaId;
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }