public async Task <IActionResult> GetPollValues(long pollId)
        {
            var poll = await _pollService.GetPoll(pollId);

            if (poll == null)
            {
                return(NotFound(Errors.GetSingleErrorList("", _localizer["PollNotFound"])));
            }

            var pollType = poll.GetType();

            if (pollType == typeof(PolicyChangePoll))
            {
                var val = _mapper.Map <PolicyChangePoll, PollListViewModel>((PolicyChangePoll)poll);
                val.ListType = await SetListType(poll);

                return(Ok(val));
            }

            if (pollType == typeof(AuthorityPoll))
            {
                var val = await _pollViewModelService.GetUsersForAuthorityVoting((AuthorityPoll)poll);

                var currentUser = val.Users.FirstOrDefault(x => x.Id == User.ApiGetUserId());
                if (currentUser != null)
                {
                    val.Users.Remove(currentUser);
                }
                val.ListType = await SetListType(poll);

                return(Ok(val));
            }

            if (pollType == typeof(MultipleChoicePoll))
            {
                var val = _pollViewModelService.MultipleChoicePollToViewModel((MultipleChoicePoll)poll);
                val.ListType = await SetListType(poll);

                return(Ok(val));
            }

            if (pollType == typeof(SharePoll))
            {
                var val = _pollViewModelService.SharePollToViewModel((SharePoll)poll);
                val.ListType = await SetListType(poll);

                return(Ok(val));
            }

            return(BadRequest(Errors.GetSingleErrorList("", _localizer["UnknownPoll"])));
        }
        public async Task <IActionResult> NewMultipleChoicePoll([FromBody] MultipleChoicePollViewModel model)
        {
            if (ModelState.IsValid)
            {
                model.UserId = User.ApiGetUserId();
                var latestAuthorityPoll = await _pollService.GetLastPollOfType <AuthorityPoll>();

                if (latestAuthorityPoll == null)
                {
                    ModelState.AddModelError("", _localizer["CantStartPollBeforeAuthorityComplete"]);

                    return(BadRequest(Errors.GetErrorList(ModelState)));
                }

                if (latestAuthorityPoll.Result == "Kararsız" ||
                    latestAuthorityPoll.Result == PollResults.Undecided.ToString())
                {
                    ModelState.AddModelError("", _localizer["CantStartPollBeforeAuthorityComplete"]);
                    return(BadRequest(Errors.GetErrorList(ModelState)));
                }

                if (await _pollService.HasActivePollOfType <AuthorityPoll>())
                {
                    ModelState.AddModelError("", _localizer["AuthorityPollActivePollError"]);
                    return(BadRequest(Errors.GetErrorList(ModelState)));
                }

                if (model.Options.Count < 2 || model.Options.Any(string.IsNullOrEmpty))
                {
                    ModelState.AddModelError("", _localizer["PollOptionCountError"]);
                    return(BadRequest(Errors.GetErrorList(ModelState)));
                }

                var poll = await _pollViewModelService.NewMultipleChoicePoll(model);

                await _pollService.NotifyUsers(poll.PollType, PollNotificationTypes.Started, poll);

                var result = _pollViewModelService.MultipleChoicePollToViewModel((MultipleChoicePoll)poll);
                return(Ok(result));
            }

            return(BadRequest(Errors.GetErrorList(ModelState)));
        }