Esempio n. 1
0
        public ActionResult AddSurveyOption(long surveyId)
        {
            Survey survey;
            if (!Context.Surveys.TryGetById(surveyId, out survey))
                throw new InvalidOperationException(string.Format("survey with id {0} was not found", surveyId));

            var model = new SurveyItemModel
            {
                SurveyId = survey.Id
            };

            return PartialView("_AddSurveyOption", model);
        }
Esempio n. 2
0
        public ActionResult AddSurveyOption(SurveyItemModel model)
        {
            if (ModelState.IsValid)
            {
                Survey survey;
                if (!Context.Surveys.TryGetById(model.SurveyId, out survey))
                    throw new InvalidOperationException(string.Format("survey with id {0} was not found", model.SurveyId));

                var surveyOption = new SurveyItem(model.SurveyId, model.Description);

                survey.Options.Add(surveyOption);

                Context.SaveChanges();
            }

            return JsonView(ModelState.IsValid, "_AddSurveyOption", model);
        }
Esempio n. 3
0
        public ActionResult EditSurveyOption(SurveyItemModel model)
        {
            if (ModelState.IsValid)
            {
                SurveyItem surveyItem;
                if (!Context.SurveyItems.TryGetById(model.Id, out surveyItem))
                    throw new InvalidOperationException(string.Format("survey item with id {0} was not found", model.Id));

                surveyItem.Description = model.Description;
                Context.SaveChanges();
            }

            return JsonView(ModelState.IsValid, "_EditSurveyOption", model);
        }
Esempio n. 4
0
        public ActionResult EditSurveyOption(long id)
        {
            SurveyItem surveyItem;
            if (!Context.SurveyItems.TryGetById(id, out surveyItem))
                throw new InvalidOperationException(string.Format("survey item with id {0} was not found", id));

            var model = new SurveyItemModel
            {
                Id = surveyItem.Id,
                SurveyId = surveyItem.SurveyId,
                Description = surveyItem.Description,
                Votes = surveyItem.Votes
            };

            return PartialView("_EditSurveyOption", model);
        }