public async Task <IActionResult> PostInfoTest([FromBody] InfoTest infoTest) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.InfoTest.Add(infoTest); await _context.SaveChangesAsync(); return(CreatedAtAction("GetInfoTest", new { id = infoTest.Id }, infoTest)); }
public async Task <IActionResult> PutInfoTest([FromRoute] int id, [FromBody] InfoTest infoTest) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != infoTest.Id) { return(BadRequest()); } // _context.Entry(infoTest).State = EntityState.Modified; var entity = _context.InfoTest.Find(id); entity.Information = infoTest.Information; entity.Timestamp = infoTest.Timestamp; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!InfoTestExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
//添加 public void AddInfoTest(InfoTest infoTest) { _dao.Add(infoTest); }
public void UpdateInfoTest() { var infoTest = new InfoTest();//也可以是实体 _dao.Update(infoTest); }