// PUT api/ProjectMember/5 public HttpResponseMessage PutProjectMember(int id, ProjectMember projectmember) { if (ModelState.IsValid) { db.Entry(projectmember).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return Request.CreateResponse(HttpStatusCode.NotFound); } return Request.CreateResponse(HttpStatusCode.OK); } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }
// POST api/ProjectMember public HttpResponseMessage PostProjectMember(ProjectMember projectmember) { if (ModelState.IsValid) { db.Configuration.ProxyCreationEnabled = false; var query = from pm in db.ProjectMembers where pm.ProjectID == projectmember.ProjectID select pm; if (query.ToList().FirstOrDefault(p => p.UserID == projectmember.UserID) != null) { return Request.CreateResponse(HttpStatusCode.BadRequest); } db.ProjectMembers.Add(projectmember); db.SaveChanges(); db.Configuration.ProxyCreationEnabled = false; HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, projectmember); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = projectmember.ProjectID })); return response; } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }