Inheritance: HttpResource
 public void InsertOrUpdate(Drill drill)
 {
     if (drill.Id == default(int)) {
         // New entity
         context.Drills.Add(drill);
     } else {
         // Existing entity
         context.Entry(drill).State = EntityState.Modified;
     }
 }
 public void InsertOrUpdate(Drill drill)
 {
     if (drill.Id == default(int))
     {
         // New entity
         context.Drills.Add(drill);
     }
     else
     {
         // Existing entity
         context.Entry(drill).State = EntityState.Modified;
     }
 }
        public HttpResponseMessage Post(Drill item)
        {
            if (ModelState.IsValid)
            {
                this.drillRepository.InsertOrUpdate(item);
                this.drillRepository.Save();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, item);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = item.Id }));
                return response;
            }
            else
            {
                var validationResults = this.ModelState.SelectMany(m => m.Value.Errors.Select(x => x.ErrorMessage + "(Property: " + m.Key + ")" ));
                throw new HttpResponseException(this.Request.CreateResponse(HttpStatusCode.BadRequest, validationResults));
            }
        }
 private static void BuildDrillLinks(UrlHelper urlHelper, Drill drill)
 {
     drill.SelfLink = urlHelper.ApiLink(drill.Id, "drills").ToString();
 }
        public HttpResponseMessage Put(int id, Drill item)
        {
            if (ModelState.IsValid && id == item.Id)
            {
                this.drillRepository.InsertOrUpdate(item);
                this.drillRepository.Save();

                return Request.CreateResponse(HttpStatusCode.OK, item);
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }