コード例 #1
0
 public ActionResult Edit(Track track)
 {
     if (ModelState.IsValid)
     {
         db.Entry(track).State = EntityState.Modified;
         return RedirectToAction("Index");
     }
     return View(track);
 }
コード例 #2
0
        public ActionResult Create(Track track)
        {
            if (ModelState.IsValid)
            {
                db.Tracks.Add(track);
                return RedirectToAction("Index");
            }

            return View(track);
        }
コード例 #3
0
        // 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);
        }
コード例 #4
0
        // 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);
        }
コード例 #5
0
 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);
 }