Exemplo n.º 1
0
 public static Poll CreatePoll(string groupUrl, Guid authorId, PollContainer pollData)
 {
     return _votingService.CreatePoll(groupUrl, authorId, pollData);
 }
Exemplo n.º 2
0
        public void UpdatePoll(Guid pollId, PollContainer pollData)
        {
            var poll = DataService.PerThread.ContentSet.OfType<Poll>().SingleOrDefault(x => x.Id == pollId);
            if (poll == null)
                throw new BusinessLogicException("Указанное голосование не найдено");

            if (poll.State == (byte)ContentState.Approved)
                throw new BusinessLogicException("Нельзя редактировать уже опубликованное голосование");

            poll.Title = pollData.Title;
            poll.Text = pollData.Text;
            poll.State = (byte)(pollData.IsDraft ? ContentState.Draft : ContentState.Premoderated);
            poll.Duration = pollData.Duration;

            if (poll.State == (byte) ContentState.Premoderated)
                poll.PublishDate = DateTime.Now;

            poll.Tags.Clear();
            foreach (var tag in pollData.Tags)
            {
                if (poll.Group.Tags.Contains(tag))
                    poll.Tags.Add(tag);
            }

            DataService.PerThread.SaveChanges();
        }
Exemplo n.º 3
0
 public static void UpdatePoll(Guid pollId, PollContainer pollData)
 {
     _votingService.UpdatePoll(pollId, pollData);
 }
Exemplo n.º 4
0
        public Poll CreatePoll(string groupUrl, Guid authorId, PollContainer pollData)
        {
            var group = GroupService.GetGroupByLabelOrId(groupUrl);
            var author = GroupService.UserInGroup(authorId, group.Id);

            if (group.State == (byte)GroupState.Blank)
                throw new BusinessLogicException("Нельзя создавать голосования в еще не оформленных группах");

            if (author == null)
                throw new BusinessLogicException("Вы не являетесь участником указанной группы");
            if (author.State == (byte)GroupMemberState.NotApproved)
                throw new BusinessLogicException("Вы еще не являетесь участником указанной группы");

            var poll = new Poll
            {
                GroupId = group.Id,
                Author = author.User,
                CreationDate = DateTime.Now,
                Title = pollData.Title,
                Text = pollData.Text,
                State = (byte)(pollData.IsDraft ? ContentState.Draft : ContentState.Premoderated),
                Duration = pollData.Duration,
                HasOpenProtocol = pollData.HasOpenProtocol
            };

            if (poll.State == (byte)ContentState.Premoderated)
                poll.PublishDate = DateTime.Now;

            foreach (var tag in pollData.Tags)
                if (group.Tags.Contains(tag))
                    poll.Tags.Add(tag);

            DataService.PerThread.SaveChanges();

            return poll;
        }
Exemplo n.º 5
0
        public ActionResult EditPoll(GroupEditPollViewModel model)
        {
            if (!Request.IsAuthenticated)
                throw new AuthenticationException();

            if (!ModelState.IsValid)
                return View(model);

            var pollContainer = new PollContainer
                {
                    Duration = model.Duration,
                    IsDraft = model.IsDraft,
                    Text = model.Text,
                    Title = model.Title
                };

            if (model.Topics != null)
                foreach (var tag in model.Topics.Where(x => x.IsChecked))
                {
                    var tmp = DataService.PerThread.TagSet.SingleOrDefault(x => x.Id == tag.Id);
                    if (tmp == null)
                        throw new BusinessLogicException("Указан неверный идентификатор тэга");

                    pollContainer.Tags.Add(tmp);
                }

            foreach (var tag in TagsHelper.ConvertStringToTagList(model.TagTitles, model.GroupId))
                pollContainer.Tags.Add(tag);

            VotingService.UpdatePoll(model.PollId, pollContainer);

            return RedirectToAction("poll", new {id = model.PollId});
        }
Exemplo n.º 6
0
        public ActionResult CreatePoll(GroupCreatePollViewModel model)
        {
            if (!Request.IsAuthenticated)
                throw new AuthenticationException();

            var group = GroupService.GetGroupByLabelOrId(model.GroupUrl);

            var redirect = HideInvisibleGroup(group);
            if (redirect != null)
                return redirect;

            if (!ModelState.IsValid)
                return View(model);

            var data = new PollContainer
            {
                Title = model.Title,
                Text = model.Text,
                IsDraft = model.IsDraft,
                Duration = model.Duration,
                HasOpenProtocol = model.HasOpenProtocol
            };

            if (model.Topics != null)
                foreach (var t in model.Topics.Where(x => x.IsChecked))
                {
                    var tag = DataService.PerThread.TagSet.SingleOrDefault(x => x.Id == t.Id);
                    if (tag == null)
                        throw new Exception("Неправильный идентификатор тэга");

                    data.Tags.Add(tag);
                }

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

            var poll = VotingService.CreatePoll(model.GroupUrl, UserContext.Current.Id, data);

            return RedirectToAction("poll", new { id = poll.Id });
        }
Exemplo n.º 7
0
 public static void UpdatePoll(Guid pollId, PollContainer pollData)
 {
     _votingService.UpdatePoll(pollId, pollData);
 }
Exemplo n.º 8
0
 public static Poll CreatePoll(string groupUrl, Guid authorId, PollContainer pollData)
 {
     return(_votingService.CreatePoll(groupUrl, authorId, pollData));
 }