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

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

            return(RedirectToAction("Index"));
        }
Example #2
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));
            }
        }