public IActionResult Create(TipoDenuncia tipoDenuncia) { int nVeces = 0; try { nVeces = _db.TipoDenuncia.Where(m => m.TipoDenunciaId == tipoDenuncia.TipoDenunciaId).Count(); if (!ModelState.IsValid || nVeces >= 1) { if (nVeces >= 1) { ViewBag.Error = "Esta registro ya existe!"; } return(View(tipoDenuncia)); } else { cargarUltimoRegistro(); _db.TipoDenuncia.Add(tipoDenuncia); _db.SaveChanges(); } } catch (Exception ex) { ViewBag.Error = ex.Message; } return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> PutTipoDenuncia([FromRoute] int id, [FromBody] TipoDenuncia tipoDenuncia) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != tipoDenuncia.IdTipoDenuncia) { return(BadRequest()); } _context.Entry(tipoDenuncia).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TipoDenunciaExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public IActionResult Edit(int Id) { TipoDenuncia oTipoDenuncia = _db.TipoDenuncia .Where(e => e.TipoDenunciaId == Id).FirstOrDefault(); return(View(oTipoDenuncia)); }
public IActionResult Details(int id) { TipoDenuncia oTipoDenuncia = _db.TipoDenuncia .Where(e => e.TipoDenunciaId == id).First(); return(View(oTipoDenuncia)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Nombre")] TipoDenuncia tipoDenuncia) { if (id != tipoDenuncia.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(tipoDenuncia); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TipoDenunciaExists(tipoDenuncia.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(tipoDenuncia)); }
public async Task <IActionResult> Create([Bind("Id,Nombre")] TipoDenuncia tipoDenuncia) { if (ModelState.IsValid) { _context.Add(tipoDenuncia); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(tipoDenuncia)); }
public async Task <IActionResult> PostTipoDenuncia([FromBody] TipoDenuncia tipoDenuncia) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.TipoDenuncia.Add(tipoDenuncia); await _context.SaveChangesAsync(); return(CreatedAtAction("GetTipoDenuncia", new { id = tipoDenuncia.IdTipoDenuncia }, tipoDenuncia)); }
public IActionResult Delete(int?TipoDenunciaId) { var Error = ""; try { TipoDenuncia oTipoDenuncia = _db.TipoDenuncia .Where(e => e.TipoDenunciaId == TipoDenunciaId).First(); _db.TipoDenuncia.Remove(oTipoDenuncia); _db.SaveChanges(); } catch (Exception ex) { Error = ex.Message; } return(RedirectToAction(nameof(Index))); }
public IActionResult Edit(TipoDenuncia tipoDenuncia) { string error = ""; try { if (!ModelState.IsValid) { return(View(tipoDenuncia)); } else { _db.TipoDenuncia.Update(tipoDenuncia); _db.SaveChanges(); } } catch (Exception ex) { error = ex.Message; } return(RedirectToAction(nameof(Index))); }
protected void btnaceptar_Click(object sender, EventArgs e) { try { if (this.txtdescripcion.Text.Trim() != "") { try { TipoDenuncia tipodenuncia = new TipoDenuncia(); tipodenuncia.descTipoDenuncia = this.txtdescripcion.Text.Trim(); if (hAccion.Value == "agregar") { int Est; if (this.cboestado.SelectedIndex == 0) { Est = 1; } else { Est = 0; } tipodenuncia.estado = Convert.ToBoolean(Est); tipodenuncia.idTipoDenuncia = NegocioMantenimiento.TraerIdTipoDenuncia(); this.cboestado.Enabled = true; NegocioMantenimiento.AgregarTipoDenuncia(tipodenuncia); MostrarMensaje("Un nuevo Tipo de Denuncia ha sido agregada satisfactoriamente"); txtdescripcion.Text = ""; cboestado.SelectedIndex = 0; txtdescripcion.Enabled = false; } else { tipodenuncia.idTipoDenuncia = int.Parse(GvTipoDenuncias.SelectedRow.Cells[1].Text); if (cboestado.SelectedItem.Text == "Activo") { int Est = 1; tipodenuncia.estado = Convert.ToBoolean(Est); } else { int Est = 0; tipodenuncia.estado = Convert.ToBoolean(Est); } NegocioMantenimiento.ModificarTipoDenuncia(tipodenuncia); MostrarMensaje("Usted ha modificado el Tipo de denuncia: " + tipodenuncia.descTipoDenuncia + ", satisfactoriamente."); txtdescripcion.Text = ""; cboestado.SelectedIndex = 0; txtdescripcion.Enabled = false; } CargarGrillaTipoDenuncias(); this.txttipodenuncia.Text = ""; this.txtdescripcion.Text = ""; this.cboestado.Enabled = false; this.GvTipoDenuncias.SelectedIndex = -1; } catch (Exception ex) { Response.Redirect("Errores.aspx?error=" + ex.Message); } } else { MostrarMensaje("Por Favor, complete todos los campos antes de realizar esta función."); this.txtdescripcion.Text = ""; this.txttipodenuncia.Text = ""; this.txtdescripcion.Enabled = false; this.cboestado.Enabled = false; this.GvTipoDenuncias.SelectedIndex = -1; } } catch (Exception ex) { Response.Redirect("Errores.aspx?error=" + ex.Message); } habilitarBotones(true); }