public ActionResult Edit(RazaEditViewModel razaVm) { if (!ModelState.IsValid) { razaVm.TipoDeMascotas = _mapper.Map <List <TipoDeMascotaListViewModel> >(_serviciosTipoDeMascota.GetLista()); return(View(razaVm)); } RazaEditDto razaDto = _mapper.Map <RazaEditDto>(razaVm); if (_servicio.Existe(razaDto)) { ModelState.AddModelError(string.Empty, "Producto existente...."); razaVm.TipoDeMascotas = _mapper.Map <List <TipoDeMascotaListViewModel> >(_serviciosTipoDeMascota.GetLista()); return(View(razaVm)); } try { _servicio.Guardar(razaDto); TempData["Msg"] = "Producto Editado"; return(RedirectToAction("Index")); } catch (Exception e) { ModelState.AddModelError(string.Empty, e.Message); razaVm.TipoDeMascotas = _mapper.Map <List <TipoDeMascotaListViewModel> >(_serviciosTipoDeMascota.GetLista()); return(View(razaVm)); } }
public ActionResult Create(RazaEditViewModel razaVm) { if (!ModelState.IsValid) { razaVm.TipoDeMascota = mapper .Map <List <TipoDeMascotaListViewModel> >(serviciosTipo.GetTipoDeMascota()); return(View(razaVm)); } RazaEditDto razaDto = mapper.Map <RazaEditDto>(razaVm); if (servicio.Existe(razaDto)) { ModelState.AddModelError(string.Empty, @"Raza existente..."); razaVm.TipoDeMascota = mapper .Map <List <TipoDeMascotaListViewModel> >(serviciosTipo.GetTipoDeMascota()); return(View(razaVm)); } try { servicio.Guardar(razaDto); TempData["Msg"] = "Raza agregado..."; return(RedirectToAction("Index")); } catch (Exception e) { ModelState.AddModelError(string.Empty, e.Message); razaVm.TipoDeMascota = mapper .Map <List <TipoDeMascotaListViewModel> >(serviciosTipo.GetTipoDeMascota()); return(View(razaVm)); } }
public ActionResult Create() { RazaEditViewModel razaVm = new RazaEditViewModel { TipoDeMascotas = _mapper.Map <List <TipoDeMascotaListViewModel> >(_serviciosTipoDeMascota.GetLista()) }; return(View(razaVm)); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } RazaEditDto razaEditDto = servicio.GetRazaPorId(id); RazaEditViewModel razaVm = mapper.Map <RazaEditViewModel>(razaEditDto); razaVm.TipoDeMascota = mapper .Map <List <TipoDeMascotaListViewModel> >(serviciosTipo.GetTipoDeMascota()); return(View(razaVm)); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest)); } RazaEditDto razaDto = _servicio.GetRazaPorId(id); if (razaDto == null) { return(HttpNotFound("Còdigo de Raza NO Encontrado")); } RazaEditViewModel razaVm = _mapper.Map <RazaEditViewModel>(razaDto); razaVm.TipoDeMascotas = _mapper.Map <List <TipoDeMascotaListViewModel> >(_serviciosTipoDeMascota.GetLista()); return(View(razaVm)); }
public ActionResult Delete(RazaEditViewModel razaVm) { RazaEditDto razaDto = _mapper.Map <RazaEditDto>(razaVm); if (_servicio.EstaRelacionado(razaDto)) { ModelState.AddModelError(string.Empty, "Registro relacionado con otra tabla...Baja denegada"); return(View(razaVm)); } try { RazaListDto raDto = _mapper.Map <RazaListDto>(_servicio.GetRazaPorId(razaVm.RazaId)); razaVm = _mapper.Map <RazaEditViewModel>(_servicio.GetRazaPorId(razaVm.RazaId)); _servicio.Borrar(razaVm.RazaId); TempData["Msg"] = "Registro Borrado..."; return(RedirectToAction("Index")); } catch (Exception e) { ModelState.AddModelError(string.Empty, e.Message); return(View(razaVm)); } }