// POST api/TimeTable public HttpResponseMessage PostTimeTable(TimeTable timetable) { if (ModelState.IsValid) { db.TimeTable.Add(timetable); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, timetable); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = timetable.Id })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
public ActionResult Create(TimeTable timetable) { if (ModelState.IsValid) { List<TimeTable> s = db.TimeTable.Where(l => l.Active == true).ToList(); if (s.Count == 1) { TimeTable timetableActive = s.First(); timetableActive.Active = false; db.Entry(timetableActive).State = EntityState.Modified; } db.TimeTable.Add(timetable); db.SaveChanges(); return RedirectToAction("Index"); } return View(timetable); }
// PUT api/TimeTable/5 public HttpResponseMessage PutTimeTable(Int32 id, TimeTable timetable) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != timetable.Id) { return Request.CreateResponse(HttpStatusCode.BadRequest); } db.Entry(timetable).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }