Esempio n. 1
0
        public ActionResult Edit(VoterVM model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user = db.VoteUsers.Where(x => x.VoterId == model.VoterId).FirstOrDefault();

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

            user.FirstName = model.FirstName;
            user.LastName  = model.LastName;
            user.Email     = model.Email;
            user.Phone     = model.Phone;

            db.SaveChanges();

            TempData["SM"] = "Changes Saved";

            return(RedirectToAction("Edit", new { voterId = model.VoterId }));
        }
        public ActionResult doUpdatePassword(string Answer, string NewPassword, string ConfirmNewPassword, string VoterGUID, string id)
        {
            VoterVM voterVM = TempData["voterVM"] as VoterVM;

            registerVoter.voterView = voterVM;

            using (VotingSystemProjectEntities3 db = new VotingSystemProjectEntities3())
            {
                var ans    = registerVoter.HashedData(Answer);
                var vid    = Convert.ToInt32(id);
                var search = db.Voters.Where(x => x.VoterID == vid && x.SecurityQuestionAnswer == ans).FirstOrDefault();
                if (search != null)
                {
                    if (NewPassword == ConfirmNewPassword)
                    {
                        string hassednew  = registerVoter.HashedData(NewPassword);
                        string hassedcnew = registerVoter.HashedData(ConfirmNewPassword);
                        search.VoterPassword = hassednew;
                        db.SaveChanges();
                        TempData["success"] = "Your Password has been updated";
                        return(RedirectToAction("VoterHomePage", new { VoterGUID = registerVoter.voterView.voter.GUID }));
                    }
                }
                else
                {
                    TempData["message"] = "Your Security Question Answer was wrong! Please try again!";
                    return(RedirectToAction("ChangePasswordVoter", new { VoterGUID = registerVoter.voterView.voter.GUID, id = registerVoter.voterView.voter.VoterID }));
                }
            }
            TempData["message"] = "An Error Occured!";
            return(RedirectToAction("VoterHomePage", new { VoterGUID = registerVoter.voterView.voter.GUID }));
        }
        public ActionResult doVoterUpdate([Bind(Include = "VoterIDNumber,VoterFirstNames,VoterLastName,VoterStreetAddress,SuburbID,ProvinceID,CityOrTownID,VoterPhoneNumber,VoterEmail")] Voter voter)
        {
            VoterVM voterVM = TempData["voterVM"] as VoterVM;


            registerVoter.voterView = voterVM;
            Voter u = db.Voters.Where(x => x.VoterIDNumber == voter.VoterIDNumber).FirstOrDefault();

            if (u != null && voter.VoterFirstNames != null && voter.VoterLastName != null && voter.VoterStreetAddress != null && voter.SuburbID != null && voter.VoterPhoneNumber != null && voter.VoterEmail != null)
            {
                u.VoterFirstNames    = voter.VoterFirstNames;
                u.VoterLastName      = voter.VoterLastName;
                u.VoterStreetAddress = voter.VoterStreetAddress;
                u.SuburbID           = voter.SuburbID;
                u.ProvinceID         = voter.ProvinceID;
                u.CityorTownID       = voter.CityorTownID;
                u.VoterEmail         = voter.VoterEmail;
                u.VoterPhoneNumber   = voter.VoterPhoneNumber;
                db.SaveChanges();
                TempData["success"] = "Your Information was updated successfully.";
                return(RedirectToAction("VoterHomePage", new { VoterGUID = registerVoter.voterView.voter.GUID }));
            }
            else
            {
                TempData["message"] = "Your Information was not updated try again!";
                return(RedirectToAction("UpdateVoterInfo", new { VoterGUID = registerVoter.voterView.voter.GUID, id = registerVoter.voterView.voter.VoterID }));
            }
        }
        public ActionResult UpdateVoterInfo(string VoterGUID, int?id)
        {
            ViewBag.message = TempData["message"];
            ViewBag.success = TempData["success"];
            if (VoterGUID != null)
            {
                VoterVM voterVM = new VoterVM();
                if (voterVM.IsLogedIn(db, VoterGUID))
                {
                    voterVM.RefreshGUID(db);
                    int   test = Convert.ToInt32(id);
                    Voter v    = db.Voters.Where(x => x.VoterID == test).FirstOrDefault();

                    registerVoter.voterView = voterVM;
                    registerVoter.VoterList = db.Voters.Where(x => x.VoterID == test).ToList();
                    TempData["voterVM"]     = voterVM;
                    ViewBag.ProvinceID      = new SelectList(db.Provinces, "ProvinceID", "ProvinceName");
                    ViewBag.CityOrTownID    = new SelectList(db.CityOrTowns, "CityOrTownID", "CityOrTownName");
                    ViewBag.SuburbID        = new SelectList(db.Suburbs, "SuburbID", "SuburbName");
                    return(View(v));
                }
            }
            else
            {
                TempData["message"] = "An Error Occured Please try again!";
                return(RedirectToAction("VoterHomePage", new { VoterGUID = registerVoter.voterView.voter.GUID }));
            }
            return(View());
        }
        public ActionResult LogVoterIn(string IDNumber, string Password)
        {
            if (IDNumber.Length != 13)
            {
                TempData["Message"] = "Your ID number is not the right length";
                return(RedirectToAction("VoterLogin"));
            }
            else
            {
                var   IDNum = registerVoter.HashedData(IDNumber);
                var   Pass  = registerVoter.HashedData(Password);
                Voter u     = db.Voters.Where(x => x.VoterIDNumber == IDNum && x.VoterPassword == Pass).FirstOrDefault();
                if (u != null)
                {
                    VoterVM voterVM = new VoterVM();
                    voterVM.voter = u;
                    voterVM.RefreshGUID(db);
                    TempData["voterVM"] = voterVM;

                    return(RedirectToAction("VoterHomePage"));
                }
                else
                {
                    TempData["Message"] = "Your ID number or password was incorect! Please try again!";
                    return(RedirectToAction("VoterLogin", "Voter"));
                }
            }
        }
 public ActionResult doVoteProvincial(string VoterGUID, string id, string PartyID, string provinceID)
 {
     if (VoterGUID != null && PartyID != null && id != null)
     {
         VoterVM voterVM = new VoterVM();
         if (voterVM.IsLogedIn(db, VoterGUID) && voterVM.voter.VoteProvinceStatus == false)
         {
             voterVM.RefreshGUID(db);
             VotingViewModel votingViewModel = new VotingViewModel();
             votingViewModel.voterView = voterVM;
             if (votingViewModel.GetElectionDate() != null)
             {
                 int ids = Convert.ToInt32(id);
                 var v   = db.Voters.Where(x => x.VoterID == ids).FirstOrDefault();
                 if (v != null)
                 {
                     //Gets the Election and increases the total votes by 1
                     Election         getdateElection = votingViewModel.GetElectionDate();
                     ProvincialResult pr = new ProvincialResult();
                     pr.PartyID    = Convert.ToInt32(PartyID);
                     pr.ElectionID = getdateElection.ElectionID;
                     pr.ProvincialResultsTotalVotes = 1;
                     pr.ProvinceID        = Convert.ToInt32(provinceID);
                     v.VoteProvinceStatus = true;
                     db.ProvincialResults.Add(pr);
                     db.SaveChanges();
                     TempData["success"] = "You have successfully voted for a Provincial Government!";
                     return(RedirectToAction("VoterHomePage", new { VoterGUID = votingViewModel.voterView.voter.GUID, id = votingViewModel.voterView.voter.VoterID }));
                 }
                 else
                 {
                     TempData["message"] = "An Error Occured Please Try Again!";
                     return(RedirectToAction("VoteProvincial", new { VoterGUID = votingViewModel.voterView.voter.GUID, id = votingViewModel.voterView.voter.VoterID }));
                 }
             }
             else
             {
                 TempData["message"] = "An Error Occured Please Try Again!";
                 return(RedirectToAction("VoteProvincial", new { VoterGUID = votingViewModel.voterView.voter.GUID, id = votingViewModel.voterView.voter.VoterID }));
             }
         }
         else
         {
             TempData["message"] = "An Error Occured Please Try Again";
             return(RedirectToAction("VoteProvincial", new { VoterGUID = VoterGUID, id = id }));
         }
     }
     else
     {
         TempData["message"] = "An Error Occured Please try again!";
         return(RedirectToAction("VoteProvincial", new { VoterGUID = VoterGUID, id = id }));
     }
 }
Esempio n. 7
0
        public ActionResult Edit(string voterId)
        {
            VoteUserDTO user = db.VoteUsers.Where(x => x.VoterId == voterId).FirstOrDefault();

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

            VoterVM model = new VoterVM(user);

            return(View(model));
        }
 public ActionResult ChangePasswordVoter(string VoterGUID, string id)
 {
     ViewBag.message = TempData["message"];
     if (VoterGUID != null)
     {
         VoterVM voterVM = new VoterVM();
         if (voterVM.IsLogedIn(db, VoterGUID))
         {
             voterVM.RefreshGUID(db);
             int   test = Convert.ToInt32(id);
             Voter v    = db.Voters.Where(x => x.VoterID == test).FirstOrDefault();
             if (v != null)
             {
                 var searchforAnswer = v.SecurityQuestionID;
                 if (searchforAnswer != null)
                 {
                     var FoundAnswer = db.SecurityQuestions.Where(y => y.SecurityQuestionID == searchforAnswer).FirstOrDefault();
                     if (FoundAnswer != null)
                     {
                         registerVoter.voterView = voterVM;
                         registerVoter.VoterList = db.Voters.ToList();
                         TempData["voterVM"]     = voterVM;
                         ViewBag.Answer          = FoundAnswer.SecurityQuestion1;
                         return(View(v));
                     }
                     else
                     {
                         TempData["message"] = "The Security Question was not found";
                         return(RedirectToAction("VoterHomePage", new { VoterGUID = registerVoter.voterView.voter.GUID }));
                     }
                 }
                 else
                 {
                     TempData["message"] = "The Security Question was not found";
                     return(RedirectToAction("VoterHomePage", new { VoterGUID = registerVoter.voterView.voter.GUID }));
                 }
             }
             else
             {
                 TempData["message"] = "Your Information was not found!";
                 return(RedirectToAction("VoterHomePage", new { VoterGUID = registerVoter.voterView.voter.GUID }));
             }
         }
     }
     else
     {
         TempData["message"] = "An Error Has Occured!";
         return(RedirectToAction("VoterHomePage", new { VoterGUID = registerVoter.voterView.voter.GUID }));
     }
     return(View());
 }
Esempio n. 9
0
        public async Task <ActionResult> Create(VoterVM model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            Result = await User.CreateUserAsync(model);

            if (!Result.Success)
            {
                ModelState.AddModelError("duplicate", Result.ErrorMessage);
                return(View(model));
            }

            TempData["SM"] = "Voter added successfully";
            return(RedirectToAction("Create"));
        }
        public ActionResult VoteProvincial(string VoterGUID, string id)
        {
            VotingViewModel votingViewModel = new VotingViewModel();

            if (votingViewModel.GetElectionDate() != null)
            {
                if (VoterGUID != null)
                {
                    VoterVM voterVM = new VoterVM();
                    if (voterVM.IsLogedIn(db, VoterGUID) && voterVM.voter.VoteProvinceStatus == false)
                    {
                        voterVM.RefreshGUID(db);
                        int ids = Convert.ToInt32(id);
                        votingViewModel.voterView = voterVM;
                        var v = db.Voters.Where(l => l.VoterID == ids).FirstOrDefault();
                        if (v != null)
                        {
                            votingViewModel.listcandidate = db.Candidates.Include(y => y.Party).Include(k => k.Party.PartyImage).Where(x => x.ProvinceID == v.ProvinceID && x.CandidatePosition_ID != 1).ToList();
                            return(View(votingViewModel));
                        }
                        else
                        {
                            TempData["message"] = "You have already voted!";
                            return(RedirectToAction("VoterHomePage", new { VoterGUID = votingViewModel.voterView.voter.GUID }));
                        }
                    }
                    else
                    {
                        TempData["message"] = "You have already voted!";
                        return(RedirectToAction("VoterHomePage", new { VoterGUID = VoterGUID }));
                    }
                }
                else
                {
                    TempData["message"] = "An Error Occured Please try again";
                    return(RedirectToAction("VoterHomePage", new { VoterGUID = VoterGUID }));
                }
            }
            else
            {
                TempData["message"] = "You can only vote on the set election date";
                return(RedirectToAction("VoterHomePage", new { VoterGUID = VoterGUID }));
            }
        }
Esempio n. 11
0
        public IEnumerable <VoterVM> GetAllVoters()
        {
            // init candidate vm
            var result = new List <VoterVM>();

            var allUsers = _db.VoteUsers.ToList();

            foreach (var user in allUsers)
            {
                if (UserManager.IsInRoleAsync(user.UserId, "Voter").Result)
                {
                    var voter = new VoterVM(user);
                    result.Add(voter);
                }
            }

            //return result
            return(result);
        }
 public ActionResult VoterHomePage(string VoterGUID)
 {
     if (VoterGUID != null)
     {
         VoterVM voterVM = new VoterVM();
         if (voterVM.IsLogedIn(db, VoterGUID))
         {
             voterVM.RefreshGUID(db);
             RegisterVoterVM registerVoterVM = new RegisterVoterVM();
             registerVoterVM.voterView = voterVM;
             registerVoterVM.VoterList = db.Voters.ToList();
             ViewBag.message           = TempData["message"];
             ViewBag.success           = TempData["success"];
             return(View(registerVoterVM));
         }
         else
         {
             TempData["message"] = "An Error Occured Please Login Again";
             return(RedirectToAction("VoterLogin"));
         }
     }
     else
     {
         VoterVM voterVM = TempData["voterVM"] as VoterVM;
         if (voterVM.IsLogedIn(db))
         {
             voterVM.RefreshGUID(db);
             RegisterVoterVM registerVoterVM = new RegisterVoterVM();
             registerVoterVM.voterView = voterVM;
             registerVoterVM.VoterList = db.Voters.ToList();
             ViewBag.message           = TempData["message"];
             ViewBag.success           = TempData["success"];
             return(View(registerVoterVM));
         }
         else
         {
             TempData["message"] = "An Error Occured Please Login Again";
             return(RedirectToAction("VoterLogin"));
         }
     }
     TempData["message"] = "An Error Occured Please Login Again";
     return(RedirectToAction("VoterLogin"));
 }
Esempio n. 13
0
        public async Task <ResultVM> CreateUserAsync(VoterVM model)
        {
            var existingUser = _db.VoteUsers.Where(x => x.Email == model.Email).FirstOrDefault();

            if (existingUser != null)
            {
                if (await IsInRole(existingUser.UserId, "Voter"))
                {
                    Result.Success      = false;
                    Result.ErrorMessage = "Voter with email: " + existingUser.Email + " already exist";
                    return(Result);
                }
            }

            // generate userId
            string newVoterId = GenerateUserId();

            VoteUserDTO user = new VoteUserDTO
            {
                UserId       = model.UserId,
                VoterId      = newVoterId,
                FirstName    = model.FirstName,
                LastName     = model.LastName,
                Email        = model.Email,
                Phone        = model.Phone,
                DateAddedUtc = DateTime.UtcNow
            };

            _db.VoteUsers.Add(user);
            _db.SaveChanges();

            // add user to role
            //this.AddToRole(user.UserId, "Voter");

            // notify user
            NotifyNewVoter(user);

            Result.Success = true;
            return(Result);
        }
        public ActionResult VoteParty(string VoterGUID, string id)
        {
            VotingViewModel votingViewModel = new VotingViewModel();

            if (votingViewModel.GetElectionDate() != null)
            {
                if (VoterGUID != null)
                {
                    VoterVM voterVM = new VoterVM();
                    if (voterVM.IsLogedIn(db, VoterGUID) && voterVM.voter.VotePartyStatus == false)
                    {
                        voterVM.RefreshGUID(db);

                        votingViewModel.voterView = voterVM;

                        votingViewModel.listcandidate = db.Candidates.Include(y => y.Party).Include(j => j.Party.PartyImage).Where(x => x.CandidatePosition_ID == 1).ToList();
                        votingViewModel.partiesImages = db.PartyImages.ToList();

                        ViewBag.message = TempData["message"];
                        ViewBag.success = TempData["success"];
                        return(View(votingViewModel));
                    }
                    else
                    {
                        TempData["message"] = "You have already voted!";
                        return(RedirectToAction("VoterHomePage", "Voter", new { VoterGUID = VoterGUID }));
                    }
                }
                else
                {
                    TempData["message"] = "An Error Occured Please try again";
                    return(RedirectToAction("VoterHomePage", "Voter", new { VoterGUID = VoterGUID }));
                }
            }
            else
            {
                TempData["message"] = "You can only vote on the set election date";
                return(RedirectToAction("VoterHomePage", new { VoterGUID = VoterGUID }));
            }
        }
        public async Task <IActionResult> CreateVoter([FromBody] VoterVM model)
        {
            var result = await VoterManager.AddAsync(new Voter { Name = model.Name, DOB = model.DOB });

            return(new ContentActionResult <Voter>((result == null) ? HttpStatusCode.BadRequest : HttpStatusCode.Created, result, (result == null) ? "BadRequest" : "OK", Request));
        }