public async Task <IActionResult> PutTiposIdentificacion(int id, TiposIdentificacion tiposIdentificacion) { if (id != tiposIdentificacion.Id) { return(BadRequest()); } _context.Entry(tiposIdentificacion).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TiposIdentificacionExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public TiposIdentificacion ObtenerTipoIdentificacion(int IdTipoIdentificacion) { TiposIdentificacion res = new TiposIdentificacion(); using (var ctx = new DB_A66D31_intratecPrbEntities1()) { res = ctx.TiposIdentificacion.Where(t => t.IdTipoIdentificacion == IdTipoIdentificacion).FirstOrDefault(); } return(res); }
//Crear public void CrearTipoIdentificacion(TiposIdentificacion TipoIdentificacionCrear) { using (var ctx = new DB_A66D31_intratecPrbEntities1()) { if (ctx.TiposIdentificacion.Where(ti => ti.Abreviatura.Equals(TipoIdentificacionCrear.Abreviatura)).FirstOrDefault() == null) { TipoIdentificacionCrear.FechaCreacion = DateTime.Now; TipoIdentificacionCrear.Activo = true; ctx.TiposIdentificacion.Add(TipoIdentificacionCrear); ctx.SaveChanges(); } else { throw new Exception($"Ya existe un Tipo de Identificación con abreviatura {TipoIdentificacionCrear.Abreviatura}"); } } }
//Eliminar public void EliminarTipoIdentificacion(int IdTipoIdentificacion, int IdUsuarioModificacion) { using (var ctx = new DB_A66D31_intratecPrbEntities1()) { TiposIdentificacion TipoIdentificacionEliminar = ctx.TiposIdentificacion.Where(u => u.IdTipoIdentificacion == IdTipoIdentificacion).FirstOrDefault(); if (TipoIdentificacionEliminar != null) { TipoIdentificacionEliminar.Activo = false; TipoIdentificacionEliminar.FechaModificacion = DateTime.Now; TipoIdentificacionEliminar.IdUsuarioModificacion = IdUsuarioModificacion; ctx.SaveChanges(); } else { throw new Exception($"No existe un tipo de identificación con ID {IdTipoIdentificacion}"); } } }
//Editar public void EditarTipoIdentificacion(TiposIdentificacion TipoIdentificacion, int IdUsuarioModificacion) { using (var ctx = new DB_A66D31_intratecPrbEntities1()) { TiposIdentificacion TipoIdentificacionEditar = ctx.TiposIdentificacion.Where(c => c.IdTipoIdentificacion == TipoIdentificacion.IdTipoIdentificacion).FirstOrDefault(); if (ctx.TiposIdentificacion.Where(ti => ti.Abreviatura.Equals(TipoIdentificacion.Abreviatura) && ti.IdTipoIdentificacion != TipoIdentificacion.IdTipoIdentificacion).FirstOrDefault() == null) { TipoIdentificacionEditar.Abreviatura = TipoIdentificacion.Abreviatura; TipoIdentificacionEditar.TipoIdentificacion = TipoIdentificacion.TipoIdentificacion; TipoIdentificacionEditar.Activo = TipoIdentificacion.Activo; TipoIdentificacionEditar.FechaModificacion = DateTime.Now; TipoIdentificacionEditar.IdUsuarioModificacion = IdUsuarioModificacion; ctx.SaveChanges(); } else { throw new Exception($"Ya existe un Tipo de Identificación con abreviatura {TipoIdentificacion.Abreviatura}"); } } }
public async Task <ActionResult <TiposIdentificacion> > PostTiposIdentificacion(TiposIdentificacion tiposIdentificacion) { _context.TiposIdentificacion.Add(tiposIdentificacion); await _context.SaveChangesAsync(); return(CreatedAtAction("GetTiposIdentificacion", new { id = tiposIdentificacion.Id }, tiposIdentificacion)); }