예제 #1
0
        public ActionResult Create(Posting posting)
        {
            if (!ModelState.IsValid)
            {
                TempData["Message"] = "Invalid posting!";
                return RedirectToAction("Index");
            }

            _miniSpiirDbContext.Postings.Add(posting);
            _miniSpiirDbContext.SaveChanges();

            return RedirectToAction("Index");
        }
예제 #2
0
        // POST api/PostingApi
        public HttpResponseMessage PostPosting(Posting posting)
        {
            if (ModelState.IsValid)
            {
                db.Postings.Add(posting);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, posting);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = posting.Id }));
                return response;
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }
예제 #3
0
        // PUT api/PostingApi/5
        public HttpResponseMessage PutPosting(int id, Posting posting)
        {
            if (ModelState.IsValid && id == posting.Id)
            {
                db.Entry(posting).State = EntityState.Modified;

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

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