コード例 #1
0
 public ActionResult Create(Palestra palestra)
 {
     if (ModelState.IsValid)
     {
         db.Palestras.Add(palestra);
         return RedirectToAction("Index");
     }
     LoadPalestrantesAndTracksToViewBag();
     return View(palestra);
 }
コード例 #2
0
 public ActionResult Edit(Palestra palestra)
 {
     if (ModelState.IsValid)
     {
         var entry = db.Entry(palestra);
         entry.State = EntityState.Modified;
         return RedirectToAction("Index");
     }
     LoadPalestrantesAndTracksToViewBag();
     return View(palestra);
 }
コード例 #3
0
        // POST api/Palestras
        public HttpResponseMessage PostPalestra(Palestra palestra)
        {
            if (ModelState.IsValid)
            {
                db.Palestras.Add(palestra);
                db.SaveChanges();

                var response = Request.CreateResponse(HttpStatusCode.Created, palestra);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new {id = palestra.Id}));
                return response;
            } else
                return Request.CreateResponse(HttpStatusCode.BadRequest);
        }
コード例 #4
0
        // PUT api/Palestras/5
        public HttpResponseMessage PutPalestra(int id, Palestra palestra)
        {
            if (ModelState.IsValid && id == palestra.Id)
            {
                db.Entry(palestra).State = EntityState.Modified;

                try
                {
                    db.SaveChanges();
                } catch (DbUpdateConcurrencyException)
                {
                    return Request.CreateResponse(HttpStatusCode.NotFound);
                }

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