コード例 #1
0
        private void btnAgregar_Click(object sender, EventArgs e)
        {
            frmTipoDeMascotaAE frm = DI.Create <frmTipoDeMascotaAE>();

            frm.Titulo("Nuevo Tipo De Mascota");
            DialogResult dr = frm.ShowDialog(this);

            if (dr == DialogResult.OK)
            {
                try
                {
                    TipoDeMascotaEditDto tipoEditDto = frm.GetTipo();
                    if (servicio.Existe(tipoEditDto))
                    {
                        frmMessageBox messageBox = new frmMessageBox();
                        messageBox.Show();
                        messageBox.ShowError("Tipo De Mascota Existente", $"{tipoEditDto.Descripcion} ya existe en la base de datos");
                    }
                    servicio.Guardar(tipoEditDto);
                    DataGridViewRow      r           = ConstruirFila();
                    TipoDeMascotaListDto tipoListDto = mapper.Map <TipoDeMascotaListDto>(tipoEditDto);
                    SetearFila(r, tipoListDto);
                    AgregarFila(r);
                    frmMessageBox frmMessage = new frmMessageBox();
                    frmMessage.Show();
                    frmMessage.ShowInfo("Registro Agregado", $"{tipoListDto.Descripcion} ya a sido agergado");
                }
                catch (Exception)
                {
                    frmMessageBox frmMessage = new frmMessageBox();
                    frm.Show();
                    frmMessage.ShowError("Error", $"El registro no se pudo agregar. Intentelo nuevamente");
                }
            }
        }
コード例 #2
0
        public ActionResult Create(TipoDeMascotaEditViewModel tipoVm)
        {
            if (!ModelState.IsValid)
            {
                return(View(tipoVm));
            }

            TipoDeMascotaEditDto tipoDto = mapper.Map <TipoDeMascotaEditDto>(tipoVm);

            if (servicio.Existe(tipoDto))
            {
                ModelState.AddModelError(string.Empty, "Registro existente...");
                return(View(tipoVm));
            }

            try
            {
                servicio.Guardar(tipoDto);
                TempData["Msg"] = "Registro agregado";
                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                ModelState.AddModelError(string.Empty, e.Message);
                return(View(tipoVm));
            }
        }
コード例 #3
0
        public ActionResult Edit(TipoDeMascotaEditViewModel tipoMasVm)
        {
            if (!ModelState.IsValid)
            {
                return(View(tipoMasVm));
            }
            TipoDeMascotaEditDto tipoMasDto = _mapper.Map <TipoDeMascotaEditDto>(tipoMasVm);

            if (_servicio.Existe(tipoMasDto))
            {
                ModelState.AddModelError(string.Empty, "Registro duplicado....");
                return(View(tipoMasVm));
            }
            try
            {
                _servicio.Guardar(tipoMasDto);
                TempData["Msg"] = "Registro Modeificado...";
                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                ModelState.AddModelError(string.Empty, e.Message);
                return(View(tipoMasVm));
            }
        }
コード例 #4
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TipoDeMascotaEditDto       tipoMasDto = _servicio.GetipoDeMascotaPorId(id);
            TipoDeMascotaEditViewModel tipoMasVm  = _mapper.Map <TipoDeMascotaEditViewModel>(tipoMasDto);

            return(View(tipoMasVm));
        }
コード例 #5
0
 public bool Existe(TipoDeMascotaEditDto tipomascotaEditDto)
 {
     try
     {
         TipoDeMascota tipo = mapper.Map <TipoDeMascota>(tipomascotaEditDto);
         return(_repositorio.Existe(tipo));
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
コード例 #6
0
 public bool EstaRelacionado(TipoDeMascotaEditDto tipoMasDto)
 {
     try
     {
         TipoDeMascota tipoDeMascota = _mapper.Map <TipoDeMascota>(tipoMasDto);
         return(_repositorio.EstaRelacionado(tipoDeMascota));
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
コード例 #7
0
        private void btnAceptar_Click(object sender, EventArgs e)
        {
            if (ValidarDatos())
            {
                if (tipoEditDto == null)
                {
                    tipoEditDto = new TipoDeMascotaEditDto();
                }

                tipoEditDto.Descripcion = txtTipo.Text;
                DialogResult            = DialogResult.OK;
            }
        }
コード例 #8
0
 public void Guardar(TipoDeMascotaEditDto tipomascotaEditDto)
 {
     try
     {
         TipoDeMascota tipo = mapper.Map <TipoDeMascota>(tipomascotaEditDto);
         _repositorio.Guardar(tipo);
         _unitOfWork.Save();
         tipo.TipoDeMascotaId = tipomascotaEditDto.TipoDeMascotaId;
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
コード例 #9
0
        private void btnEditar_Click(object sender, EventArgs e)
        {
            if (dgvDatos.SelectedRows.Count == 0)
            {
                return;
            }

            DataGridViewRow    r           = dgvDatos.SelectedRows[0];
            var                tipoListDto = r.Tag as TipoDeMascotaListDto;
            var                tipoCopia   = (TipoDeMascotaListDto)tipoListDto.Clone();
            frmTipoDeMascotaAE frm         = DI.Create <frmTipoDeMascotaAE>();

            frm.Titulo("Editar Tipo De Mascota");
            TipoDeMascotaEditDto tipoEditDto = mapper.Map <TipoDeMascotaEditDto>(tipoListDto);

            frm.SetTipo(tipoEditDto);
            DialogResult dr = frm.ShowDialog(this);

            if (dr == DialogResult.Cancel)
            {
                return;
            }

            tipoEditDto = frm.GetTipo();
            if (servicio.Existe(tipoEditDto))
            {
                frmMessageBox messageBox = new frmMessageBox();
                messageBox.Show();
                messageBox.ShowError("Tipo De Mascota Existente", $"{tipoEditDto.Descripcion} ya existe en la base de datos");
                SetearFila(r, tipoCopia);
                return;
            }
            try
            {
                servicio.Guardar(tipoEditDto);
                var tListDto = mapper.Map <TipoDeMascotaListDto>(tipoEditDto);
                SetearFila(r, tListDto);
                frmMessageBox messageBox = new frmMessageBox();
                messageBox.Show();
                messageBox.ShowInfo("Tipo De Mascota Editada", $"{tListDto.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.");
            }
        }
コード例 #10
0
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TipoDeMascotaEditDto tipoMasDto = _servicio.GetipoDeMascotaPorId(id);

            if (tipoMasDto == null)
            {
                return(HttpNotFound("Còdigo de Tipo de Mascota inexistente..."));
            }
            TipoDeMascotaEditViewModel tipoMasVm = _mapper.Map <TipoDeMascotaEditViewModel>(tipoMasDto);

            return(View(tipoMasVm));
        }
コード例 #11
0
        public ActionResult Delete(TipoDeMascotaEditViewModel tipoMasVm)
        {
            TipoDeMascotaEditDto tipoMasDto = _mapper.Map <TipoDeMascotaEditDto>(tipoMasVm);

            if (_servicio.EstaRelacionado(tipoMasDto))
            {
                ModelState.AddModelError(string.Empty, "Registro relacionado con otra tabla...Baja denegada");
                return(View(tipoMasVm));
            }
            try
            {
                tipoMasVm = _mapper.Map <TipoDeMascotaEditViewModel>(_servicio.GetipoDeMascotaPorId(tipoMasVm.TipoDeMascotaId));
                _servicio.Borrar(tipoMasVm.TipoDeMascotaId);
                TempData["Msg"] = "Registro Borrado...";
                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                ModelState.AddModelError(string.Empty, e.Message);
                return(View(tipoMasVm));
            }
        }
コード例 #12
0
 public void SetTipo(TipoDeMascotaEditDto tipoEditDto)
 {
     this.tipoEditDto = tipoEditDto;
 }