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 bool Existe(RazaEditDto razaDto) { try { Raza raza = mapper.Map <Raza>(razaDto); return(repositorioRaza.Existe(raza)); } catch (Exception e) { throw new Exception(e.Message); } }
public bool EstaRelacionado(RazaEditDto razaDto) { try { Raza raza = _mapper.Map <Raza>(razaDto); return(_repositorio.EstaRelacionado(raza)); } catch (Exception e) { throw new Exception(e.Message); } }
private void btnEditar_Click(object sender, EventArgs e) { if (dgvDatos.SelectedRows.Count == 0) { return; } DataGridViewRow r = dgvDatos.SelectedRows[0]; var razaListDto = r.Tag as RazaListDto; var razaCopia = (RazaListDto)razaListDto.Clone(); frmRazaAE frm = DI.Create <frmRazaAE>(); frm.Titulo("Editar Raza"); RazaEditDto razaEditDto = servicio.GetRazaPorId(razaListDto.RazaId); frm.SetRaza(razaEditDto); DialogResult dr = frm.ShowDialog(this); if (dr == DialogResult.Cancel) { return; } razaEditDto = frm.GetRaza(); if (servicio.Existe(razaEditDto)) { frmMessageBox messageBox = new frmMessageBox(); messageBox.Show(); messageBox.ShowError("Raza Existente", $"{razaEditDto.Descripcion} ya existe en la base de datos"); SetearFila(r, razaCopia); return; } try { servicio.Guardar(razaEditDto); var rListDto = mapper.Map <RazaListDto>(razaEditDto); razaListDto.TipoDeMascota = (servicioTipo .GetTipoDeMascotaPorId(razaEditDto.TipoDeMascotaId)) .Descripcion; SetearFila(r, rListDto); frmMessageBox messageBox = new frmMessageBox(); messageBox.Show(); messageBox.ShowInfo("Raza Editada", $"{rListDto.Descripcion} " + $"ah sido editada correctamente"); } catch (Exception) { frmMessageBox messageBox = new frmMessageBox(); messageBox.Show(); messageBox.ShowError("Error", $"Ocurrio un problema no se pudo completar la transaccion. Intentelo nuevamente."); } }
public void Guardar(RazaEditDto razaDto) { try { Raza raza = mapper.Map <Raza>(razaDto); repositorioRaza.Guardar(raza); unitOfWork.Save(); } catch (Exception e) { throw new Exception(e.Message); } }
private void btnAceptar_Click(object sender, EventArgs e) { if (ValidarDatos()) { if (razaEditDto == null) { razaEditDto = new RazaEditDto(); } razaEditDto.Descripcion = txtRaza.Text; razaEditDto.TipoDeMascotaId = ((TipoDeMascotaListDto)mcbTipo.SelectedItem).TipoDeMascotaId; DialogResult = DialogResult.OK; } }
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)); }
private void btnAgregar_Click(object sender, EventArgs e) { frmRazaAE frm = DI.Create <frmRazaAE>(); frm.Titulo("Nueva Raza"); DialogResult dr = frm.ShowDialog(this); if (dr == DialogResult.OK) { try { RazaEditDto razaEditDto = frm.GetRaza(); if (servicio.Existe(razaEditDto)) { frmMessageBox messageBox = new frmMessageBox(); messageBox.Show(); messageBox.ShowError("Raza Existente", $"{razaEditDto.Descripcion} ya existe en la base de datos"); } servicio.Guardar(razaEditDto); DataGridViewRow r = ConstruirFila(); RazaListDto razaListDto = mapper.Map <RazaListDto>(razaEditDto); razaListDto.TipoDeMascota = (servicioTipo .GetTipoDeMascotaPorId(razaEditDto.TipoDeMascotaId)) .Descripcion; SetearFila(r, razaListDto); AgregarFila(r); frmMessageBox frmMessage = new frmMessageBox(); frmMessage.Show(); frmMessage.ShowInfo("Registro Agregado", $"{razaListDto.Descripcion} ya a sido agergado"); } catch (Exception) { frmMessageBox frmMessage = new frmMessageBox(); frm.Show(); frmMessage.ShowError("Error", $"El registro no se pudo agregar. Intentelo nuevamente"); } } }
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)); } }
public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } RazaEditDto razaEditDto = servicio.GetRazaPorId(id); if (razaEditDto == null) { return(HttpNotFound("Código de raza inexistente...")); } RazaListDto razaDto = mapper.Map <RazaListDto>(servicio.GetRazaPorId(id)); var tipo = serviciosTipo.GetTipoDeMascotaPorId(razaEditDto.TipoDeMascotaId); razaDto.TipoDeMascota = tipo.Descripcion; RazaListViewModel razaVm = mapper.Map <RazaListViewModel>(razaDto); return(View(razaVm)); }
public void SetRaza(RazaEditDto razaEditDto) { this.razaEditDto = razaEditDto; }