public async Task <ActionResult> PostGroups(CountableGroup Groups) { // add new group as added Context.CountableGroup.Add(Groups); // commit a new group await Context.SaveChangesAsync(); // set std status code for this action HttpContext.Response.StatusCode = 201; // return a new id for group return(Ok(new { id = Groups.Id })); }
public async Task <IActionResult> EditName(uint id, string newName) { // validate id value if (id == default) { return(BadRequest()); } // create target record var current = new CountableGroup { Id = id, Name = newName }; // mark as modified Context.Entry(current).State = EntityState.Modified; try { // try commit change await Context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { // check problems if (!await Context.CountableGroup.AnyAsync(e => e.Id == id)) { return(NotFound()); } else { throw; } } return(NoContent()); }