Ejemplo n.º 1
0
        public async Task <IActionResult> Login_Codebehind(string controlNumber, LanguagePreference languagePreference)
        {
            HttpContext.Session.SetString("ControlNumber", controlNumber);
            SHOAccount shoAccount = _context.shoaccounts.AsQueryable().FirstOrDefault(a => a.ControlNumber == controlNumber);

            HttpContext.Session.SetString("AvailableShares", shoAccount.AvailableShares.ToString());
            List <Question> questions = _blockchainContext.questions;
            List <Answer>   answers   = new List <Answer>();

            foreach (Question question in questions)
            {
                Answer answer = new Answer();
                answer.quid   = question.quid;
                answer.answid = "A";
                answer.test   = "FOR";
                answers.Add(answer);
                answer        = new Answer();
                answer.quid   = question.quid;
                answer.answid = "B";
                answer.test   = "AGAINST";
                answers.Add(answer);
                answer        = new Answer();
                answer.quid   = question.quid;
                answer.answid = "Z";
                answer.test   = "ABSTAIN";
                answers.Add(answer);
            }
            HttpContext.Session.SetString("answers", Newtonsoft.Json.JsonConvert.SerializeObject(answers));

            if (languagePreference == LanguagePreference.Russian)
            {
                return(await Task.Run <IActionResult>(() => { return RedirectToAction("Index_Russian", new { revote = "0" }); }));
            }
            else
            {
                return(await Task.Run <IActionResult>(() => { return RedirectToAction("Index", new { revote = "0" }); }));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Index_CodeBehind(LanguagePreference languagePreference, string revote)
        {
            string voteAnswerChoices = "";

            if (HttpContext.Session.GetString("ControlNumber") == null)
            {
                return(await Task.Run <IActionResult>(() => { return RedirectToAction("Login"); }));
            }

            List <VoteSubmission> voteSubmissions = _context.votesubmission.AsQueryable().ToList();

            string controlNumber = HttpContext.Session.GetString("ControlNumber");

            SHOAccount shoaccount = _context.shoaccounts.AsQueryable().Where(sho => sho.ControlNumber == controlNumber).FirstOrDefault();

            if (shoaccount.maskedVoters != null && shoaccount.maskedVoters.Any())
            {
                List <string> voteSessionIds     = new List <string>();
                string        voteSessionId      = "";
                string        firstVoteSessionId = "";
                bool          allTheSame         = true;
                for (int x = 0; x < shoaccount.maskedVoters.Count(); x++)
                {
                    VoteMask voteMask = shoaccount.maskedVoters[x];
                    Voter    voter1   = await _blockchainContext.getVoteAnswersByVoterId(voteMask.voterId);

                    voteAnswerChoices = voter1.voteSelections;
                    string voteSessionId1 = voter1.sessionId;
                    voteSessionIds.Add(voteSessionId1);
                    if (x == 0)
                    {
                        firstVoteSessionId = voteSessionId1;
                    }
                    else
                    {
                        if (firstVoteSessionId != voteSessionId1)
                        {
                            allTheSame = false;
                        }
                    }
                }

                if (allTheSame)
                {
                    voteSessionId = firstVoteSessionId;
                }
                else
                {
                }

                var existingVoteSubmissions = voteSubmissions.Where(v => v.ControlNumber == controlNumber && v.voteSubmissionStatus == VoteSubmissionStatus.VotesConfirmed);
                if (existingVoteSubmissions.Any())
                {
                    if (existingVoteSubmissions.Any(vs => vs._id == voteSessionId) && allTheSame)
                    {
                        var filterVoteSubmission = Builders <VoteSubmission> .Filter.Eq("_id", voteSessionId);

                        _context.votesubmission.DeleteMany(filterVoteSubmission);
                    }
                    else
                    {
                        if (languagePreference == LanguagePreference.Russian)
                        {
                            return(RedirectToAction("Confirm_Russian", new { id = existingVoteSubmissions.FirstOrDefault()._id }));
                        }
                        else
                        {
                            return(RedirectToAction("Confirm", new { id = existingVoteSubmissions.FirstOrDefault()._id }));
                        }
                    }
                }
                else
                {
                    if (revote == "0")
                    {
                        var filterVoteSubmission = Builders <VoteSubmission> .Filter.Eq("ControlNumber", controlNumber);

                        _context.votesubmission.DeleteMany(filterVoteSubmission);
                    }
                }
            }

            if (revote == "1" || voteAnswerChoices == "")
            {
                MainVM viewModel = new MainVM();
                if (controlNumber != "-1")
                {
                    List <Question> questions = _blockchainContext.questions;

                    viewModel.activeQuestions = (from q in questions
                                                 orderby q.questionIndex
                                                 select new QuestionVM
                    {
                        quid = q.quid,
                        boardRecommendation = q.boardRecommendation,
                        text = q.text,
                        text_ru = q.text_ru,
                        questionIndex = q.questionIndex,
                        keyid = q.quid + "|",
                        SelectedAnswerId = "Z"
                    }
                                                 ).ToList();

                    viewModel.activeQuestions.ForEach(sv => sv.orderNum = Convert.ToInt32(sv.questionIndex) + 1);

                    List <Answer> answers = new List <Answer>();
                    Answer        answer  = new Answer();
                    answer.answid = "A";
                    answer.test   = "FOR";
                    answers.Add(answer);
                    Answer answer2 = new Answer();
                    answer2.answid = "B";
                    answer2.test   = "AGAINST";
                    answers.Add(answer2);
                    Answer answer3 = new Answer();
                    answer3.answid = "Z";
                    answer3.test   = "ABSTAIN";
                    answers.Add(answer3);

                    foreach (QuestionVM question in viewModel.activeQuestions)
                    {
                        question.Answers = (from a in answers
                                            orderby a.answid
                                            select new AnswerVM
                        {
                            quid = question.quid,
                            answid = a.answid,
                            text = a.test
                        }
                                            ).ToList();
                    }
                }
                else
                {
                    viewModel.activeQuestions = new List <QuestionVM>();
                }

                return(await Task.Run <IActionResult>(() => { return View(viewModel); }));
            }
            else
            {
                if (languagePreference == LanguagePreference.Russian)
                {
                    return(await Task.Run <IActionResult>(() => { return RedirectToAction("Confirm_Russian", new { id = "0" }); }));
                }
                else
                {
                    return(await Task.Run <IActionResult>(() => { return RedirectToAction("Confirm", new { id = "0" }); }));
                }
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Confirm_Codebehind(string id)
        {
            if (HttpContext.Session.GetString("ControlNumber") == null)
            {
                return(await Task.Run <IActionResult>(() => { return RedirectToAction("Login"); }));
            }

            string controlNumber = HttpContext.Session.GetString("ControlNumber");

            MainVM viewModel = new MainVM();

            if (id != "0")
            {
                IMongoQueryable <VoteSubmission> voteSubmission = _context.votesubmission.AsQueryable();

                var savedVotes = voteSubmission.Where(e => e._id == id);

                viewModel.VoteSubmissionId = id;
                if (savedVotes.Any())
                {
                    viewModel.activeQuestions = savedVotes.FirstOrDefault().VoteSelections;
                    viewModel.activeQuestions.ForEach(q => q.orderNum = (q.questionIndex) + 1);
                    viewModel.activeQuestions = viewModel.activeQuestions.OrderBy(q => q.orderNum).ToList();

                    viewModel.voteSubmissionStatus = savedVotes.FirstOrDefault().voteSubmissionStatus;
                    if (savedVotes.FirstOrDefault().dateSubmitted != null)
                    {
                        viewModel.dateSubmitted = savedVotes.FirstOrDefault().dateSubmitted;
                    }
                    else
                    {
                        viewModel.dateSubmitted = DateTime.Now;
                    }
                }
            }
            else
            {
                viewModel.VoteSubmissionId = id;
                SHOAccount shoaccount = _context.shoaccounts.AsQueryable().Where(sho => sho.ControlNumber == controlNumber).FirstOrDefault();
                Voter      voter1     = await _blockchainContext.getVoteAnswersByVoterId(shoaccount.maskedVoters[0].voterId);

                string          voteString = voter1.voteSelections;
                List <Question> questions  = _blockchainContext.questions;

                viewModel.activeQuestions = (from q in questions
                                             orderby q.questionIndex
                                             select new QuestionVM
                {
                    quid = q.quid,
                    boardRecommendation = q.boardRecommendation,
                    text = q.text,
                    text_ru = q.text_ru,
                    questionIndex = q.questionIndex,
                    keyid = q.quid + "|",
                    SelectedAnswerId = "Z"
                }
                                             ).ToList();

                viewModel.activeQuestions.ForEach(q => q.orderNum = (q.questionIndex) + 1);
                viewModel.activeQuestions = viewModel.activeQuestions.OrderBy(q => q.orderNum).ToList();

                for (int x = 0; x < viewModel.activeQuestions.Count(); x++)
                {
                    viewModel.activeQuestions[x].SelectedAnswerId = voteString.Substring(x, 1);
                }

                viewModel.voteSubmissionStatus = VoteSubmissionStatus.VotesConfirmed;
            }

            return(await Task.Run <IActionResult>(() => { return View(viewModel); }));
        }