public ActionResult AddSurvey(SurveyModel model) { if (ModelState.IsValid) { var survey = new Survey(model.Title); Context.AddSurvey(survey); Context.SaveChanges(); } return JsonView(ModelState.IsValid, "_AddSurvey", model); }
public ActionResult Edit(SurveyModel model) { if (ModelState.IsValid) { Survey survey; if (!Context.Surveys.TryGetById(model.Id, out survey)) throw new InvalidOperationException(string.Format("survey with id {0} was not found", model.Id)); survey.Title = model.Title; Context.SaveChanges(); } return View("EditSurvey", model); }
public ActionResult Edit(long id) { Survey survey; if (!Context.Surveys.TryGetById(id, out survey)) throw new InvalidOperationException(string.Format("survey with id {0} was not found", id)); var model = new SurveyModel { Id = survey.Id, Title = survey.Title, Active = survey.Active }; return View("EditSurvey", model); }