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

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

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