Пример #1
0
        // PUT api/Read/5
        public HttpResponseMessage PutRead(string id, Read read)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            if (id != read.readId)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

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

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

            return Request.CreateResponse(HttpStatusCode.OK);
        }
Пример #2
0
        public ActionResult Create(Read read)
        {
            if (ModelState.IsValid)
            {
                db.Reads.Add(read);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(read);
        }
Пример #3
0
        // POST api/Read
        public HttpResponseMessage PostRead(Read read)
        {
            if (ModelState.IsValid)
            {
                db.Reads.Add(read);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, read);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = read.readId }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
Пример #4
0
 public ActionResult Edit(Read read)
 {
     if (ModelState.IsValid)
     {
         db.Entry(read).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(read);
 }