public IHttpActionResult PostProject(Project project) { try { if (!ModelState.IsValid) { return BadRequest(ModelState); } else { project.ModifiedOn = DateTime.Now; } db.Projects.Add(project); db.Entry(project).State = EntityState.Added; db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = project.ProjectId }, project); } catch (Exception) { throw; } }
public IHttpActionResult PutProject(int id, Project project) { if (!ModelState.IsValid) { return BadRequest(ModelState); } else { project.ModifiedOn = DateTime.Now; } if (id != project.ProjectId) { return BadRequest(); } db.Entry(project).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ProjectExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }