예제 #1
0
        public ActionResult Create(Announcement announcement)
        {
            if (ModelState.IsValid)
            {
                db.Announcements.Add(announcement);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(announcement);
        }
예제 #2
0
        // POST api/Ann
        public HttpResponseMessage PostAnnouncement(Announcement announcement)
        {
            if (ModelState.IsValid)
            {
                db.Announcements.Add(announcement);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, announcement);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = announcement.annId }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
예제 #3
0
        // PUT api/Ann/5
        public HttpResponseMessage PutAnnouncement(string id, Announcement announcement)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            if (id != announcement.annId)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            db.Entry(announcement).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex);
            }

            return Request.CreateResponse(HttpStatusCode.OK);
        }
예제 #4
0
 public ActionResult Edit(Announcement announcement)
 {
     if (ModelState.IsValid)
     {
         db.Entry(announcement).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(announcement);
 }