Exemplo n.º 1
0
        public async Task <IActionResult> Edit(string pollId, string editorId)
        {
            var pollRenderViewModel = await _pollRepository.Select(pollId);

            PollBuilderViewModel pollBuilderViewModel;

            if (pollRenderViewModel == null)
            {
                pollBuilderViewModel = new PollBuilderViewModel()
                {
                    PollId      = pollId,
                    EditorToken = editorId
                };
            }
            else
            {
                int primaryKey = await _pollRepository.SelectPollPk(pollId);

                pollBuilderViewModel = new PollBuilderViewModel()
                {
                    Title          = pollRenderViewModel.Title,
                    IsSingleOption = pollRenderViewModel.IsSingleOption,
                    IsPublished    = pollRenderViewModel.IsPublished,
                    PollId         = pollId,
                    EditorToken    = editorId,
                    Options        = await _pollOptionRepository.Select(primaryKey)
                };
            }
            return(View("Edit", pollBuilderViewModel));
        }
        public async Task <IActionResult> Edit(string pollId, string editorId)
        {
            var pollDto = await _pollRepository.Select(pollId);

            PollBuilderViewModel pollBuilderViewModel = new PollBuilderViewModel
            {
                PollId      = pollId,
                EditorToken = editorId,
                Host        = _requestHeaderHandler.GetHost(ControllerContext)
            };

            if (pollDto == null)
            {
                return(NotFound());
            }
            if (pollDto.EditorToken != editorId)
            {
                return(BadRequest());
            }
            if (pollDto.IsPublished)
            {
                pollBuilderViewModel = new PollBuilderViewModel()
                {
                    Title          = pollDto.Title,
                    IsSingleOption = pollDto.IsSingleOption,
                    IsPublished    = pollDto.IsPublished,
                    PollId         = pollDto.PollId,
                    EditorToken    = pollDto.EditorToken,
                    Options        = await _pollOptionRepository.SelectAllForPollPk(pollDto.PrimaryKey),
                    Host           = _requestHeaderHandler.GetHost(ControllerContext)
                };
            }
            return(View("Edit", pollBuilderViewModel));
        }