예제 #1
0
        private void SetearFila(DataGridViewRow r, RazaListDto raza)
        {
            r.Cells[cmnRaza.Index].Value = raza.Descripcion;
            r.Cells[cmnTipo.Index].Value = raza.TipoDeMascota;

            r.Tag = raza;
        }
예제 #2
0
        public static void CargarComboRaza(ref MetroComboBox cbo)
        {
            IServicioRaza serviceRaza = DI.Create <IServicioRaza>();
            var           listaRaza   = serviceRaza.GetLista(null);
            var           razaListDto = new RazaListDto
            {
                RazaId      = 0,
                Descripcion = "<Seleccione una Raza>"
            };

            listaRaza.Insert(0, razaListDto);
            cbo.DataSource    = listaRaza;
            cbo.ValueMember   = "RazaId";
            cbo.DisplayMember = "Descripcion";
            cbo.SelectedIndex = 0;
        }
예제 #3
0
        public ActionResult Delete(RazaListViewModel razaVm)
        {
            try
            {
                RazaListDto razaDto = mapper
                                      .Map <RazaListDto>(servicio.GetRazaPorId(razaVm.RazaId));
                razaVm = mapper.Map <RazaListViewModel>(razaDto);

                servicio.Borrar(razaVm.RazaId);
                TempData["Msg"] = "Registro borrado...";
                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                ModelState.AddModelError(String.Empty, e.Message);
                return(View(razaVm));
            }
        }
예제 #4
0
        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");
                }
            }
        }
예제 #5
0
        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));
            }
        }
예제 #6
0
        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));
        }