コード例 #1
0
        // PUT api/Symptoms/5
        public HttpResponseMessage PutSymptom(String id, Symptom symptom)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            if (id != symptom.ID)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            db.Entry(symptom).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(Symptom symptom)
        {
            if (ModelState.IsValid)
            {
                symptom.ID = symptom.KeyName;
                db.WellCastSymptoms.Add(symptom);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.SymptomCategoryID = new SelectList(db.WellCastSymptomCategories, "ID", "KeyName", symptom.SymptomCategoryID);
            return View(symptom);
        }
コード例 #3
0
        // POST api/Symptoms
        public HttpResponseMessage PostSymptom(Symptom symptom)
        {
            if (ModelState.IsValid)
            {
                db.WellCastSymptoms.Add(symptom);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, symptom);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = symptom.ID }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
コード例 #4
0
 public ActionResult Edit(Symptom symptom)
 {
     if (ModelState.IsValid)
     {
         db.Entry(symptom).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.SymptomCategoryID = new SelectList(db.WellCastSymptomCategories, "ID", "KeyName", symptom.SymptomCategoryID);
     return View(symptom);
 }