Exemplo n.º 1
0
        public ActionResult Edit(MascotaEditViewModel mascotaVm)
        {
            if (!ModelState.IsValid)
            {
                mascotaVm.TipoDeMascota = _mapper.Map <List <TipoDeMascotaListViewModel> >(_serviciosTipoDeMascota.GetLista());
                mascotaVm.Raza          = _mapper.Map <List <RazaListViewModel> >(_serviciosRaza.GetLista(null));
                mascotaVm.Cliente       = _mapper.Map <List <ClienteListViewModel> >(_serviciosCliente.GetLista(null));
                return(View(mascotaVm));
            }
            MascotaEditDto mascotaDto = _mapper.Map <MascotaEditDto>(mascotaVm);

            if (_servicio.Existe(mascotaDto))
            {
                ModelState.AddModelError(string.Empty, "Mascota Existente");
                mascotaVm.TipoDeMascota = _mapper.Map <List <TipoDeMascotaListViewModel> >(_serviciosTipoDeMascota.GetLista());
                mascotaVm.Raza          = _mapper.Map <List <RazaListViewModel> >(_serviciosRaza.GetLista(null));
                mascotaVm.Cliente       = _mapper.Map <List <ClienteListViewModel> >(_serviciosCliente.GetLista(null));
                return(View(mascotaVm));
            }
            try
            {
                _servicio.Guardar(mascotaDto);
                TempData["Msg"] = "Mascota Editada....";
                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                ModelState.AddModelError(string.Empty, e.Message);
                mascotaVm.TipoDeMascota = _mapper.Map <List <TipoDeMascotaListViewModel> >(_serviciosTipoDeMascota.GetLista());
                mascotaVm.Raza          = _mapper.Map <List <RazaListViewModel> >(_serviciosRaza.GetLista(null));
                mascotaVm.Cliente       = _mapper.Map <List <ClienteListViewModel> >(_serviciosCliente.GetLista(null));
                return(View(mascotaVm));
            }
        }
Exemplo n.º 2
0
        public ActionResult Create()
        {
            MascotaEditViewModel mascotaVm = new MascotaEditViewModel
            {
                TipoDeMascota = _mapper.Map <List <TipoDeMascotaListViewModel> >(_serviciosTipoDeMascota.GetLista()),
                Raza          = _mapper.Map <List <RazaListViewModel> >(_serviciosRaza.GetLista(null)),
                Cliente       = _mapper.Map <List <ClienteListViewModel> >(_serviciosCliente.GetLista(null))
            };

            return(View(mascotaVm));
        }
Exemplo n.º 3
0
        public ActionResult Create()
        {
            MascotaEditViewModel mascotaVm = new MascotaEditViewModel
            {
                Cliente = mapper
                          .Map <List <ClienteListViewModel> >(servicioCliente.GetLista()),
                TipoDeMascota = mapper
                                .Map <List <TipoDeMascotaListViewModel> >(servicioTipoDeMascota.GetTipoDeMascota()),
                Raza = mapper
                       .Map <List <RazaListViewModel> >(servicioRaza.GetLista(null)),
            };

            return(View(mascotaVm));
        }
Exemplo n.º 4
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            MascotaEditDto       mascotaEditDto = servicio.GetMascotaPorId(id);
            MascotaEditViewModel mascotaVm      = mapper.Map <MascotaEditViewModel>(mascotaEditDto);

            mascotaVm.Cliente = mapper
                                .Map <List <ClienteListViewModel> >(servicioCliente.GetLista());
            mascotaVm.TipoDeMascota = mapper
                                      .Map <List <TipoDeMascotaListViewModel> >(servicioTipoDeMascota.GetTipoDeMascota());
            mascotaVm.Raza = mapper
                             .Map <List <RazaListViewModel> >(servicioRaza.GetLista(null));
            return(View(mascotaVm));
        }
Exemplo n.º 5
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            MascotaEditDto mascotaDto = _servicio.GetMascotaPorId(id);

            if (mascotaDto == null)
            {
                return(HttpNotFound("Còdigo de Mascota No Encontrado"));
            }
            MascotaEditViewModel mascotaVm = _mapper.Map <MascotaEditViewModel>(mascotaDto);

            mascotaVm.TipoDeMascota = _mapper.Map <List <TipoDeMascotaListViewModel> >(_serviciosTipoDeMascota.GetLista());
            mascotaVm.Raza          = _mapper.Map <List <RazaListViewModel> >(_serviciosRaza.GetLista(null));
            mascotaVm.Cliente       = _mapper.Map <List <ClienteListViewModel> >(_serviciosCliente.GetLista(null));
            return(View(mascotaVm));
        }