public void InsertOrUpdate(Speaker speaker)
 {
     if (speaker.Id == default(int)) {
         // New entity
         context.Speakers.Add(speaker);
     } else {
         // Existing entity
         context.Entry(speaker).State = EntityState.Modified;
     }
 }
        // POST api/Speaker
        public HttpResponseMessage PostSpeaker(Speaker session)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    repository.InsertOrUpdate(session);
                    repository.Save();
                }
                catch (DbUpdateConcurrencyException)
                {
                    return Request.CreateResponse(HttpStatusCode.NotFound);
                }

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, session);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = session.Id }));
                return response;
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }
        // PUT api/Speaker/5
        public HttpResponseMessage PutSpeaker(int id, Speaker session)
        {
            if (ModelState.IsValid && id == session.Id)
            {
                try
                {
                    repository.InsertOrUpdate(session);
                    repository.Save();
                }
                catch (DbUpdateConcurrencyException)
                {
                    return Request.CreateResponse(HttpStatusCode.NotFound);
                }

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