public ActionResult EditSurvey(GroupCreateEditSurveyViewModel model) { if (!Request.IsAuthenticated) throw new AuthenticationException(); var survey = DataService.PerThread.ContentSet.OfType<Survey>().SingleOrDefault(x => x.Id == model.SurveyId); if (survey == null) throw new BusinessLogicException("Указан неверный идентификатор опроса"); if (!ModelState.IsValid) return View(model); var data = new SurveyData { Id = model.SurveyId, Duration = model.Duration, IsPrivate = model.IsPrivate, Tags = model.TagTitles, Text = model.Text, Title = model.Title, VariantsCount = model.VariantsCount }; var options = model.Options .Select(o => new SurveyOptionData { Description = o.Description, Title = o.Title }) .ToList(); data.Options = options; VotingService.UpdateSurvey(survey, data, UserContext.Current.Id); return RedirectToAction("survey", new { id = survey.Id }); }
public ActionResult CreateSurvey(GroupCreateEditSurveyViewModel model) { if (!Request.IsAuthenticated) throw new AuthenticationException(); if (!ModelState.IsValid) return View(model); var data = new SurveyData { Duration = model.Duration, GroupId = model.GroupId, IsPrivate = model.IsPrivate, IsDraft = model.IsDraft, Tags = model.TagTitles, Text = model.Text, Title = model.Title, VariantsCount = model.VariantsCount, HasOpenProtocol = model.HasOpenProtocol }; var options = model.Options .Select(o => new SurveyOptionData { Description = o.Description, Title = o.Title }) .ToList(); data.Options = options; var survey = VotingService.CreateSurvey(data, UserContext.Current.Id); return RedirectToAction("survey", new { id = survey.Id }); }