Example #1
0
        public ActionResult VoteProof(string candidateId)
        {
            // get vote and user details
            VoteProofVM model = new VoteProofVM();

            // init user & candidate
            var user      = db.VoteUsers.Where(x => x.Email == User.Email).FirstOrDefault();
            var candidate = db.VoteUsers.Where(x => x.VoterId == candidateId).FirstOrDefault();

            // log user out if this is an invalid attempt.
            if (user == null || candidate == null)
            {
                RemoveCookie();
                string errorMsg = "Invalid or malicious attempt. You have been logged out.";
                return(RedirectToAction("Index", new { errorMsg = errorMsg }));
            }

            // fill model
            model.Name  = user.FirstName + " " + user.LastName;
            model.Phone = user.Phone;

            // fill candidate
            model.Candidate = candidate;
            model.Position  = db.Position.Where(x => x.Id == candidate.PositionId).Select(x => x.Name).FirstOrDefault();

            // get vote date
            DateTime votedate = db.Votes.Where(x => x.CandidateId == candidateId && x.VoterId == user.VoterId).Select(x => x.DateUtc).FirstOrDefault();

            model.VoteDate = votedate.ToLocalTime();

            // return view with model
            return(View("VoteProof", model));
        }
Example #2
0
        private string GetProofPdfHtml(string candidateId)
        {
            string result;
            // get vote and user details
            VoteProofVM model = new VoteProofVM();

            // init user & candidate
            var user      = db.VoteUsers.Where(x => x.Email == User.Email).FirstOrDefault();
            var candidate = db.VoteUsers.Where(x => x.VoterId == candidateId).FirstOrDefault();

            // log user out if this is an invalid attempt.
            if (user == null || candidate == null)
            {
                // compute result
                #region Error result
                result  = @"<!DOCTYPE html>";
                result += "<html lang=\"en\">";
                result += "<head>";
                result += "<meta charset = \"UTF -8\">";


                result += "<meta name = \"viewport\" content = \"width=device-width, initial-scale=1.0\">";


                result += "<title> REFER.</title>";


                result += "<link rel = \"stylesheet\" href = \"https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css\" integrity = \"sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk\" crossorigin = \"anonymous\">";

                result += " <link rel = \"stylesheet\" href = \"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.0-2/css/all.min.css\">";


                result += " <link href = \"~/Content/style.css\" rel = \"stylesheet\" />";
                result += "</head>";
                result += " <body>";


                result += " <section>";

                result += "<div class=\"container\">";
                result += " <div class=\"row my-3 vote-result\" style=\"position: relative; \">";

                result += "<div class=\"col -12 col-sm-12 h-100 \">";
                result += "<div class=\"d -flex flex-column align-items-center justify-content-center h-100\">";

                result += "  <h1 class=\"text -danger\">Invalid Proof.</h1>";

                result += " </div>";

                result += " </div>";

                result += "</div>";
                result += "</div>";
                result += " </section>";


                result += "    <script src = \"https://code.jquery.com/jquery-3.5.1.slim.min.js\" integrity=\"sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj\" crossorigin=\"anonymous\"></script>";
                result += "<script src = \"https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js\" integrity=\"sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo\" crossorigin=\"anonymous\"></script>";
                result += "<script src = \"https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js\" integrity=\"sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI\" crossorigin=\"anonymous\"></script>";
                result += "</body>";
                result += " </html>";
                #endregion


                return(result);
            }

            // fill model
            model.Name  = user.FirstName + " " + user.LastName;
            model.Phone = user.Phone;

            // fill candidate
            model.Candidate = candidate;
            model.Position  = db.Position.Where(x => x.Id == candidate.PositionId).Select(x => x.Name).FirstOrDefault();

            // get vote date
            DateTime votedate = db.Votes.Where(x => x.CandidateId == candidateId && x.VoterId == user.VoterId).Select(x => x.DateUtc).FirstOrDefault();
            model.VoteDate = votedate.ToLocalTime();


            // compute result
            #region Proof Pdf
            result  = @"<!DOCTYPE html>";
            result += "<html lang=\"en\">";
            result += "<head>";
            result += "<meta charset = \"UTF -8\">";


            result += "<meta name = \"viewport\" content = \"width=device-width, initial-scale=1.0\">";


            result += "     <title> REFER.</title>";


            result += "<link rel = \"stylesheet\" href = \"https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css\" integrity = \"sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk\" crossorigin = \"anonymous\">";

            result += " <link rel = \"stylesheet\" href = \"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.0-2/css/all.min.css\">";


            result += " <link href = \"~/Content/style.css\" rel = \"stylesheet\" />";
            result += "</head>";
            result += " <body>";


            result += " <section>";

            result += "<div class=\"container\">";
            result += " <div class=\"row my-3 vote-result\" style=\"position: relative; \">";

            result += "<div class=\"col -12 col-sm-12 h-100 \">";
            result += "<div class=\"d -flex flex-column align-items-center justify-content-center h-100\">";
            result += "<div class=\"text -center p-2 inline\">";
            result += "<h4>Thank's for casting a vote.</h4>";
            result += " <h5 class=\"text -muted\">Below is your vote result</h5>";
            result += " </div>";
            result += " <div class=\"card rounded-lg\" style=\"width: 18rem;\">";
            result += "    <img src = \"" + model.Candidate.ImageString + "\" class=\"card-img-top\" alt=\"...\">";
            result += "  <div class=\"card -body\">";
            result += "      <div>";
            result += "     <span class=\"title -label\">Name</span>";
            result += "<h5 class=\"card -title result-t-title\">" + model.Candidate.FirstName + " " + model.Candidate.LastName + "</h5>";
            result += " </div>";
            result += "  <div>";
            result += "     <span class=\"title -label\">Position</span>";
            result += "   <h5 class=\"card -title result-t-title\">" + model.Position + "</h5>";
            result += " </div>";
            result += " <div>";
            result += "    <span class=\"title -label\">Vote casted by</span>";
            result += "    <h5 class=\"card -title result-t-title\">" + model.Name + " - " + model.Phone + "</h5>";
            result += " </div>";
            result += "  <div>";
            result += "  <span class=\"title -label\">Date</span>";
            result += "  <h5 class=\"card -title result-t-title\">" + model.VoteDate + "</h5>";
            result += " </div>";
            result += "</div>";

            result += "<p class=\"text -uppercase text-muted text-center mt-3\">&copy; Copyright 2020</p>";


            result += "</div>";
            result += " </div>";

            result += " </div>";

            result += "</div>";
            result += "</div>";
            result += " </section>";


            result += "    <script src = \"https://code.jquery.com/jquery-3.5.1.slim.min.js\" integrity=\"sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj\" crossorigin=\"anonymous\"></script>";
            result += "<script src = \"https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js\" integrity=\"sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo\" crossorigin=\"anonymous\"></script>";
            result += "<script src = \"https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js\" integrity=\"sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI\" crossorigin=\"anonymous\"></script>";
            result += "</body>";
            result += " </html>";
            #endregion


            return(result);
        }