// POST api/Match public HttpResponseMessage PostMatch(Match match) { if (ModelState.IsValid) { db.Matches.Add(match); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, match); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = match.Id })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
private void AddMatch(Match match) { db.Matches.Add(match); db.SaveChanges(); }
// PUT api/Match/5 public HttpResponseMessage PutMatch(int id, Match match) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != match.Id) { return Request.CreateResponse(HttpStatusCode.BadRequest); } db.Entry(match).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }
public Match GetEmptyMatch() { var match = new Match(); return match; }