コード例 #1
0
        public async Task <IActionResult> Vote(MyVoteContract model)
        {
            return(View("VotingOver"));

            /*
             * if (model.Option1 == VoteOption.NotSure)
             *  ModelState.AddModelError(nameof(model.Option1), "Please answer this question");
             *
             * if (model.Option2 == VoteOption.NotSure)
             *  ModelState.AddModelError(nameof(model.Option2), "Please answer this question");
             *
             * if (model.Option3 == VoteOption.NotSure)
             *  ModelState.AddModelError(nameof(model.Option3), "Please answer this question");
             *
             * if (!string.IsNullOrEmpty(model.Comment) && model.Comment.Length > 500)
             *  ModelState.AddModelError(nameof(model.Comment), "Your question is too long. Max 500 chars allowed");
             *
             * if (!ModelState.IsValid)
             *  return View(model);
             *
             * if (model.NotVoted())
             *  return RedirectToAction("Vote");
             *
             * if (string.IsNullOrEmpty(model.Token))
             * {
             *  var user = this.GetUser();
             *
             *  if (user == null)
             *      return RedirectToAction("Signin");
             *
             *  model.UserId = user.UserId;
             * }
             * else
             * {
             *  var token = await _voteTokensRepository.FindTokenAsync(model.Token);
             *
             *  if (token == null)
             *      return RedirectToAction("Signin");
             *
             * }
             *
             * var vote = await _votesRepository.GetAsync(model.UserId);
             *
             * if (vote != null)
             *  return RedirectToAction("Success");
             *
             * await _votesRepository.VoteAsync(model);
             *
             * return RedirectToAction("Success");
             */
        }
コード例 #2
0
        public async Task <IActionResult> MyVote(MyVoteContract model)
        {
            //return Redirect(urlToRedirect);


            if (model.NotVoted())
            {
                return(RedirectToAction("Vote"));
            }

            if (string.IsNullOrEmpty(model.Token))
            {
                var user = this.GetUser();

                if (user == null)
                {
                    return(RedirectToAction("Signin"));
                }

                model.Email  = user.Email;
                model.UserId = user.UserId;
            }
            else
            {
                var token = await _voteTokensRepository.FindTokenAsync(model.Token);

                if (token == null)
                {
                    return(RedirectToAction("Signin"));
                }

                model.Email = token.Email;
            }

            IVote vote = await _votesRepository.GetAsync(model.Email);

            if (vote != null)
            {
                return(RedirectToAction("Success"));
            }



            await _votesRepository.VoteAsync(model);

            return(RedirectToAction("Success"));
        }