// GET api/<controller>/5 public async Task <Table> Get(int id) { using (var x = new DataEntities1()) { var result = await x.Table.FirstOrDefaultAsync(_ => _.Id == id); return(result); } }
// GET api/<controller> public async Task <List <Table> > Get() { using (var x = new DataEntities1()) { var result = await x.Table.ToListAsync(); return(result); } }
// DELETE api/<controller>/5 public async Task Delete([FromBody] int id) { using (var x = new DataEntities1()) { var table = await x.Table.FirstOrDefaultAsync(_ => _.Id == id); if (table != null) { x.Table.Remove(table); await x.SaveChangesAsync(); } } }
// POST api/<controller> public async Task <int> Post([FromBody] Table model) { using (var x = new DataEntities1()) { var table = new Table { Title = model.Title, Content = model.Content }; x.Table.Add(table); await x.SaveChangesAsync(); var result = table.Id; return(result); } }
// PUT api/<controller>/5 public async Task Put([FromBody] Table model) { using (var x = new DataEntities1()) { var table = await x.Table.FirstOrDefaultAsync(_ => _.Id == model.Id); if (table == null) { return; } table.Content = model.Content; table.Title = model.Title; await x.SaveChangesAsync(); } }