public ActionResult Edit(Track track) { if (ModelState.IsValid) { db.Entry(track).State = EntityState.Modified; return RedirectToAction("Index"); } return View(track); }
public ActionResult Create(Track track) { if (ModelState.IsValid) { db.Tracks.Add(track); return RedirectToAction("Index"); } return View(track); }
// POST api/Tracks public HttpResponseMessage PostTrack(Track track) { if (ModelState.IsValid) { db.Tracks.Add(track); db.SaveChanges(); var response = Request.CreateResponse(HttpStatusCode.Created, track); response.Headers.Location = new Uri(Url.Link("DefaultApi", new {id = track.Id})); return response; } else return Request.CreateResponse(HttpStatusCode.BadRequest); }
// PUT api/Tracks/5 public HttpResponseMessage PutTrack(int id, Track track) { if (ModelState.IsValid && id == track.Id) { db.Entry(track).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return Request.CreateResponse(HttpStatusCode.NotFound); } return Request.CreateResponse(HttpStatusCode.OK, track); } else return Request.CreateResponse(HttpStatusCode.BadRequest); }
private void LoadPalestrantesAndTracksToViewBag(Palestrante palestrante = null, Track track = null) { ViewBag.Palestrantes = new SelectList(db.Palestrantes, "Id", "Nome", palestrante); ViewBag.Tracks = new SelectList(db.Tracks, "Id", "Nome", track); }