public async Task <ActionResult <Respuesta> > PutInstituciones(int id, [FromBody] InstitucionesRequest instituiconesRequest) { var entity = await this.context.Set <Instituciones>().FindAsync(id); var Tnotas = await this.context.Tnotas.FindAsync(instituiconesRequest.TnotaId); if (Tnotas == null) { return(BadRequest(new Respuesta { EsExitoso = false, Mensaje = "Domicilios no existe.", Resultado = null })); } entity.Tnota = Tnotas; this.context.Entry(entity).State = EntityState.Modified; await this.context.SaveChangesAsync(); return(Ok(new Respuesta { EsExitoso = true, Mensaje = "", Resultado = new InstitucionesRespuesta { TnotaId = entity.TnotaId, CodigoInstitucion = entity.CodigoInstitucion, Nombre = entity.Nombre, Descripcion = entity.Descripcion, } })); }
public async Task <ActionResult <Respuesta> > PostInstituciones([FromBody] InstitucionesRequest institucionesRequest) { if (!ModelState.IsValid) { return(BadRequest(new Respuesta { EsExitoso = false, Mensaje = "Modelo incorrecto.", Resultado = ModelState })); } var user = await this.context.Users.FindAsync("1"); if (user == null) { return(BadRequest(new Respuesta { EsExitoso = false, Mensaje = "Usuario Invalido.", Resultado = null })); } var TnotaId = await this.context.Tnotas.FindAsync(institucionesRequest.TnotaId); if (TnotaId == null) { return(BadRequest(new Respuesta { EsExitoso = false, Mensaje = "Notas no existe.", Resultado = null })); } var CodigoInstitucion = await this.context.Tnotas.FindAsync(institucionesRequest.CodigoInstitucion); if (CodigoInstitucion == null) { return(BadRequest(new Respuesta { EsExitoso = false, Mensaje = "CodigoInstitucion no existe.", Resultado = null })); } var entity = new Instituciones { CodigoInstitucion = institucionesRequest.CodigoInstitucion, TnotaId = institucionesRequest.TnotaId, Nombre = institucionesRequest.Nombre, Descripcion = institucionesRequest.Descripcion, Usuario = user, }; BaseController.CompletaRegistro(entity, 1, "", user, false); await this.context.Set <Instituciones>().AddAsync(entity); try { await this.context.SaveChangesAsync(); } catch (Exception ee) { return(BadRequest(new Respuesta { EsExitoso = false, Mensaje = "Registro no grabado, controlar.", Resultado = null })); } //return Ok(new Respuesta //{ // EsExitoso = true, // Mensaje = "", // Resultado = entity //}); return(Ok(new Respuesta { EsExitoso = true, Mensaje = "", Resultado = new InstitucionesRespuesta { TnotaId = entity.TnotaId, CodigoInstitucion = entity.CodigoInstitucion, Nombre = entity.Nombre, Descripcion = entity.Descripcion, } })); }