public HttpResponseMessage PutBar(int id, Bar bar) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, new HttpRequestException("Model not valid")); } if (id != bar.ID) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, new HttpRequestException("Model not valid")); } db.Entry(bar).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!BarExists(id)) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, new HttpRequestException("Bar not found")); } else { throw; } } return Request.CreateResponse<Bar>(HttpStatusCode.OK, bar); }
public HttpResponseMessage PostBar(Bar bar) { bar.Created = DateTime.Now; bar.Updated = DateTime.Now; if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, new HttpRequestException("Model not valid")); } db.Bars.Add(bar); db.SaveChanges(); return Request.CreateResponse<Bar>(HttpStatusCode.Created, bar); }