Beispiel #1
0
 public static Survey UpdateSurvey(Survey survey, SurveyData data, Guid? userId)
 {
     return _votingService.UpdateSurvey(survey, data, userId);
 }
Beispiel #2
0
 public static Survey CreateSurvey(SurveyData surveyData, Guid userId)
 {
     return _votingService.CreateSurvey(surveyData, userId);
 }
        public Survey UpdateSurvey(SurveyData data, Guid? userId)
        {
            var survey = DataService.PerThread.ContentSet.OfType<Survey>().SingleOrDefault(x => x.Id == data.Id);
            if (survey == null)
                throw new BusinessLogicException("Указан неверный идентификатор опроса");

            return UpdateSurvey(survey, data, userId);
        }
        public Survey UpdateSurvey(Survey survey, SurveyData data, Guid? userId)
        {
            if (survey.State != (byte)ContentState.Draft && survey.State != (byte)ContentState.Premoderated)
                throw new BusinessLogicException("Данный опрос нельзя изменять");

            if (userId.HasValue)
            {
                if (survey.AuthorId != userId)
                    throw new BusinessLogicException("Вы не являетесь автором опроса");

                GroupService.UserInGroup(userId.Value, survey.Group, true);
            }

            if (data.VariantsCount >= data.Options.Count)
                throw new BusinessLogicException("Разрешено выбирать слишком много вариантов");

            survey.Title = data.Title;
            survey.Text = data.Text;
            survey.IsPrivate = data.IsPrivate;
            survey.Duration = data.Duration;
            survey.VariantsCount = data.VariantsCount;
            survey.Tags.Clear();

            foreach (var tag in TagsHelper.ConvertStringToTagList(data.Tags, survey.GroupId))
                survey.Tags.Add(tag);

            var optionsForDelete = survey.Options.ToList();
            foreach (var option in optionsForDelete)
                DataService.PerThread.OptionSet.DeleteObject(option);

            var options = new List<Option>();
            byte optPos = 0;
            foreach (var o in data.Options)
            {
                var option = new Option
                {
                    Position = optPos,
                    Title = o.Title,
                    Description = o.Description,
                    SurveyId = survey.Id
                };
                DataService.PerThread.OptionSet.AddObject(option);
                options.Add(option);
                optPos++;
            }

            survey.Options.Clear();
            foreach (var option in options)
                survey.Options.Add(option);

            DataService.PerThread.SaveChanges();

            return survey;
        }
        public Survey CreateSurvey(SurveyData data, Guid? userId)
        {
            var group = DataService.PerThread.GroupSet.SingleOrDefault(x => x.Id == data.GroupId);
            if (group == null)
                throw new BusinessLogicException("Указан неверный идентификатор группы");

            if (userId.HasValue)
                GroupService.UserInGroup(userId.Value, group, true);

            if (data.VariantsCount >= data.Options.Count)
                throw new BusinessLogicException("Разрешено выбирать слишком много вариантов");

            var survey = new Survey
            {
                AuthorId = userId,
                Title = data.Title,
                Text = data.Text,
                IsPrivate = data.IsPrivate,
                Tags = TagsHelper.ConvertStringToTagList(data.Tags, data.GroupId),
                GroupId = data.GroupId,
                Duration = data.Duration,
                VariantsCount = data.VariantsCount,
                CreationDate = DateTime.Now,
                State = data.IsDraft ? (byte)ContentState.Draft : (byte)ContentState.Premoderated,
                HasOpenProtocol = data.HasOpenProtocol
            };

            var options = new List<Option>();
            byte optPos = 0;
            foreach (var o in data.Options)
            {
                var option = new Option
                {
                    Position = optPos,
                    Title = o.Title,
                    Description = o.Description,
                    SurveyId = survey.Id
                };
                options.Add(option);
                optPos++;
            }
            survey.Options = options;

            DataService.PerThread.ContentSet.AddObject(survey);
            DataService.PerThread.SaveChanges();

            return survey;
        }
Beispiel #6
0
        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 });
        }
Beispiel #7
0
        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 });
        }
Beispiel #8
0
 public static Survey UpdateSurvey(Survey survey, SurveyData data, Guid?userId)
 {
     return(_votingService.UpdateSurvey(survey, data, userId));
 }
Beispiel #9
0
 public static Survey CreateSurvey(SurveyData surveyData, Guid userId)
 {
     return(_votingService.CreateSurvey(surveyData, userId));
 }