// GET: /Vote/Index public ActionResult Index() { CandidatesViewModel candidateVM = new CandidatesViewModel(); List <CandidateDTO> candidates = candidateVM.GetAllCandidates(); return(View(candidates)); }
public List <CandidateDTO> GetCandidates() // accessing the database to get all the candidates { CandidatesViewModel candidateVM = new CandidatesViewModel(); List <CandidateDTO> candidates = candidateVM.GetAllCandidates(); return(candidates); }
public ActionResult Index() { // get all the list of candidates from the candidatesViewModel and return the model to cshtml page CandidatesViewModel candidateVM = new CandidatesViewModel(); List <CandidateDTO> candidates = candidateVM.GetAllCandidates(); return(View(candidates)); }
// GET: Vote public ActionResult Index() { CandidatesViewModel candidateVM = new CandidatesViewModel(); List<CandidateDTO> candidates = candidateVM.GetAllCandidates(); // all the candidate list that in the system List<CandidateDTO> getCandidateListToView = new List<CandidateDTO>(); CampaignViewModel cVM = new CampaignViewModel(); List<CampaignDTO> campaign = cVM.GetAllCampaigns(); bool empty = !campaign.Any(); // check if the campaign list is not empty string currentData = ""; string date = DateTime.Now.ToString("dd/MM/yyyy "); string time = DateTime.Now.ToString("hh:mm:ss"); currentData = Convert.ToDateTime(date + time).ToString("dd/MM/yyyy HH:mm:ss"); List<string> uniqueCampID = new List<string>(); // get the unique ID fro each campaign string getID = ""; bool found = false; bool timeOK = false; if (empty != true) { foreach (var camp in campaign) { if (DateTime.Parse(currentData) <= camp.EndDate) { timeOK = true; } else { timeOK = false; } if (timeOK == true) { foreach (var can in candidates) { if (can.CampaignID == camp.CampaignID) { found = true; } if (found == true) { if (!getID.Contains(can.CandidateId)) getID += can.CandidateId + ","; } found = false; } } } getID = getID.TrimEnd(',', ' '); var canIdsArray = getID.Split(','); // unique candidate Ids are extracted from the campaigns that are runing currently bool isInList = false; for (int i = 0; i < canIdsArray.Length; i++) { foreach (var can in candidates) { if (canIdsArray[i] == can.CandidateId) { CandidateDTO candidate = new CandidateDTO { CandidateId = can.CandidateId, FirstName = can.FirstName, Surname = can.Surname, Gender = can.Gender, Country = can.Country, City = can.City, DOB = can.DOB, CandidatePic = can.CandidatePic, CampaignID = can.CampaignID }; getCandidateListToView.Add(candidate); isInList = true; } } } if (isInList == true) // if even one campaign found in the system return list/a candidate to the view { return View(getCandidateListToView); } else // if no campaigns are found in the system means there are no campaigns in the system yet { return View("NoCampaigns"); } } else { return View("NoCandidatesInSystem"); // if there are no campaigns in the system redirect the user to this page } // this is just for the DEMO day //return View(candidates); }
public List <string> GetAllTheDeTailsRelatedToEachCountry(string selectedCountry, string selectedCampaign) { DynamicChartsModel dM = new DynamicChartsModel(); // get the data from the DB ChartsViewModel cVM = new ChartsViewModel(); List <RegisterViewModel> users = cVM.GetAllUsres(); // get the users // get all the Campaign to count the number of Campaigns in each country CampaignViewModel campVM = new CampaignViewModel(); List <CampaignDTO> campaigns = campVM.GetAllCampaigns(); // get all the candidates of the system and count the total number of candidates of each country CandidatesViewModel candidateVM = new CandidatesViewModel(); List <CandidateDTO> candidates = candidateVM.GetAllCandidates(); // get alll the Votes for each candidates of each country. VoteViewModel vVM = new VoteViewModel(); List <VotesDTO> votes = vVM.GetAllTheVotes(); string cand = ""; selectedCountry = selectedCountry.Trim(); selectedCampaign = selectedCampaign.Trim(); List <string> countryCampainglist = new List <string>(); foreach (var item in campaigns) { if (!countryCampainglist.Contains(item.Country.ToString())) { countryCampainglist.Add(item.Country); } } int total_votes = 0; int total_users = 0; bool canFound = false; var votesForEachCandidate = ""; var totalUsresForEachCampaignVoted = ""; foreach (var country in countryCampainglist) // get the candidates related to the selected country and campaigns { if (selectedCountry == country) { foreach (var cam in campaigns) { if (selectedCampaign == cam.Description) { foreach (var can in candidates) { if (can.CampaignID == cam.CampaignID) { cand += can.FirstName + ","; canFound = true; foreach (var vot in votes) { if (can.CandidateId == vot.CandidateId) // total votes for the each candidate { total_votes++; } } if (canFound == true) { votesForEachCandidate += total_votes + ","; total_votes = 0; } } } } } } } foreach (var user in users) // count total number of users related to that country { if (selectedCountry == user.Country) { total_users++; } } var totalVoters = total_users.ToString(); cand = cand.TrimEnd(',', ' '); // removing the last comma from the string votesForEachCandidate = votesForEachCandidate.TrimEnd(',', ' '); // removing the last comma from the string //totalUsresForEachCampaignVoted = totalUsresForEachCampaignVoted.TrimEnd(',', ' '); // removing the last comma from the string var arrayCand = votesForEachCandidate.Split(','); for (int i = 0; i < arrayCand.Length; i++) { total_users = (total_users - Int32.Parse(arrayCand[i]));// get the possiable votes left } totalUsresForEachCampaignVoted = total_users.ToString(); dM.Candidates = cand; dM.Votes = votesForEachCandidate; // this is just for the testing////////////////////////////DEMO/////////////////DEMO////////////////////////DEMO///////////// cand = "Hamid Karzai,Abdullah Abdullah,Ashraf Ghani,Abdul Rashid Dostum,Mohammad Hanif Atmar"; votesForEachCandidate = "350000,2100000,2800000,840000,910000"; totalUsresForEachCampaignVoted = "3000000"; totalVoters = "10000000"; //////////////////////////////////////////////DEMO/////////////////////DEMO////////////////////DEMO///////////////////////// List <string> data = new List <string>// return this list to the view and extract the values in the script to chart. { selectedCountry, selectedCampaign, cand, votesForEachCandidate, totalUsresForEachCampaignVoted, totalVoters }; return(data); // return the data to the view }