public async Task<IHttpActionResult> PutTag(int id, Tag tag) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != tag.Id) { return BadRequest(); } db.Entry(tag).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TagExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public async Task<IHttpActionResult> PostTag(Tag tag) { if (!ModelState.IsValid) { return BadRequest(ModelState); } tag.CreateDate = DateTime.Now; db.Tags.Add(tag); await db.SaveChangesAsync(); return CreatedAtRoute("DefaultApi", new { id = tag.Id }, tag); }