public IHttpActionResult PutTaskModel(int id, TaskModel taskModel) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != taskModel.Id) { return BadRequest(); } db.Entry(taskModel).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!TaskModelExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult PostTaskModel(TaskModel taskModel) { if (!ModelState.IsValid) { return BadRequest(ModelState); } taskModel.CreatedAt = DateTime.UtcNow; db.TaskModels.Add(taskModel); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = taskModel.Id }, taskModel); }