Esempio n. 1
0
        public ActionResult Create([Bind(Include = "ID,FirstName,LastName")] Author author)
        {
            if (ModelState.IsValid)
            {
                db.Authors.Add(author);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(author));
        }
        public ActionResult Create([Bind(Include = "ID,BookTitle,BookContent,Rate")] Book book)
        {
            if (ModelState.IsValid)
            {
                db.Books.Add(book);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(book));
        }
Esempio n. 3
0
        // PUT api/myobjects/
        // The PUT command will be send along with the object
        // Compare this to the scaffolded version to see the difference.
        public HttpResponseMessage PutMyObject(MyObject myObject)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

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

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

            return(Request.CreateResponse(HttpStatusCode.OK, myObjet));
        }