public ActionResult Details(string id)
        {
            CandidatesViewModel candidateVM = new CandidatesViewModel();
            CandidateDTO        candidate   = candidateVM.GetCandidateDetailsById(id);
            CampaignViewModel   camVM       = new CampaignViewModel();
            var camp = camVM.GetAllCampaignNamesAndID();

            foreach (var cam in camp) // find the name of campaing in the details
            {
                if (candidate.CampaignID == cam.CampaignID)
                {
                    candidate.CampaignID = cam.Description;
                }
            }

            return(View(candidate));
        }
        public ActionResult Edit(string id)
        {
            CandidatesViewModel candidateVM = new CandidatesViewModel();
            CandidateDTO        candidate   = candidateVM.GetCandidateDetailsById(id);


            //CampaignViewModel camVM = new CampaignViewModel();
            //// get all the campaigns in the list with thier ids
            //var camp = candidate.Campaigns;
            //camp = camVM.GetAllCampaignNamesAndID();
            //// get countries list to View from account
            //GetCountriesList getCountriesList = new GetCountriesList();
            //candidate.Countries = getCountriesList.CountriesList(); // set the countries list to, where list is string and it's in the model
            //List<string> campainglist = new List<string>();  // get the campaigns name from the list campaings model and add them to string list
            //foreach (var item in camp)
            //{
            //    campainglist.Add(item.Description);
            //}
            //candidate.CampaignsList = campainglist; // string list of campaigns names, store them in the Campaigns list where declared in the model



            return(View(candidate));
        }
示例#3
0
        public ActionResult ThankYou()
        {
            ViewBag.Message = "Thanks For the Vote";
            var canId = Request["CandidateId"];
            // get logged in user id
            String uId = User.Identity.GetUserId();
            //var finprint = Request["UserFingerprint"];
            ViewBag.candidateID = canId;
            ViewBag.userID = uId;
            //ViewBag.fingerprint = finprint;
            // get user status for Voting 
            var userStatusId = "";
            var userDOB = "";
            var userStatusDescription = "";
            // get user DOB and Status in this array
            VoteViewModel voteVM = new VoteViewModel();
            UserDetails userDetails = voteVM.GetUserDetails(uId);
            userStatusId = userDetails.UserStatusId;
            userStatusId = userStatusId.ToString();
            // use DOB 
            userDOB = userDetails.DOB;

            // check if the candidate country is same as the voters country 
            var CandidateCountry = "";
            var UserCountry = "";

            CandidatesViewModel candidatesViewModel = new CandidatesViewModel();
            CandidateDTO canDTO = new CandidateDTO();
            canDTO = candidatesViewModel.GetCandidateDetailsById(canId);
            // candidates Country
            CandidateCountry = canDTO.Country;
            var candidateCampaign = canDTO.CampaignID;
            ViewBag.candidateCampaign = candidateCampaign;

            // users Country
            UserCountry = voteVM.GetLoggedUserCountry(uId);

            userStatusDescription = voteVM.GetUserStatusDescription(userStatusId);

            ViewBag.UserCountry = UserCountry;
            ViewBag.CandidateCountry = CandidateCountry;

            // get user and campaign 
            //UserCampaign userCampaign = new UserCampaign();

            //userCampaign = voteVM.GetUserCampaign(uId, candidateCampaign);

            List<UserCampaign> userCampaign = voteVM.GetUserCampaign();// get all the list of the user id and campaing that voted before




            if (UserCountry == CandidateCountry) //  the user should be the citizen in the country to vote for the candidate
            {
                // check users age at the current time, the user may have grown up and have the age rule 

                GetAgeCalculated gAge = new GetAgeCalculated();
                int userAge = gAge.GetAge(userDOB);
                if (userAge >= 18)
                {
                    ViewBag.result = userAge;

                    if (userCampaign != null)// check if the user campaing table is not empty 
                    {
                        bool userVotedfound = false;
                        foreach (var item in userCampaign)
                        {
                            if (uId == item.UserId && candidateCampaign == item.CampaignID)
                            {
                                userVotedfound = true;
                            }
                            //else
                            //{
                            //    userVotedfound = false;
                            //}
                        }
                        //  than you can vote, check if the user and campaign are not the same 
                        if (userVotedfound == true) // user can vote for multiple campaings but can vote for the second time in the same campaign
                        {
                            //ViewBag.result = "The user already Voted in this campaign";
                            return View("AlreadyVoted");
                        }
                        else // if the user did not vote than let the user vote 
                        {
                            voteVM.InsertDataIntoVoteTable(uId, candidateCampaign, canId); // add the data to Vote table 
                            return View();// return thank you to the user
                        }
                    }
                    else// if the table has no data user did not vote on any campaign than let the user vote 
                    {
                        voteVM.InsertDataIntoVoteTable(uId, candidateCampaign, canId); // add the data to Vote table
                        return View();// return thank you to the user
                    }
                }
                else
                {
                    return View("Rejected");
                }
            }
            else
            {
                return View("Rejected");

            }
        }