Example #1
0
        public IHttpActionResult Add(int id, Question question)
        {
            if (!ModelState.IsValid)
                return BadRequest(ModelState);

            if (id > 0)
            {
                var survey = db.Surveys.Find(id);
                if (survey == null)
                    return BadRequest("No Survey");

                if (!AdminSecurity.IsValidOrganisation(survey.OrganisationID))
                    return BadRequest("Not Allowed to add");

                question.SurveyID = id;
                if (question.ID == 0)
                {
                    db.Questions.Add(question);
                }
                else
                {
                    db.Questions.Attach(question);
                    db.Entry(question).State = EntityState.Modified;
                }
                db.SaveChanges();

                return CreatedAtRoute("DefaultApi", new { id = question.ID }, question);
            }
            return BadRequest("SurveyID was blank");
        }
        public ActionResult Questions(Question question, int ID)
        {
            if (ModelState.IsValid)
            {
                question.SurveyID = ID;
                db.Questions.Add(question);
                db.SaveChanges();

                ModelState.Clear();

                ViewBag.Questions = db.Questions.Where(q => q.SurveyID == question.SurveyID).ToList();
            }

            ViewBag.ID = ID;
            return View();
        }