public JsonResult CountryDashboardList(string country)   // accepts the country and returns the list of campaigns by the JSON call
        {
            DynamicChartsModel dM    = new DynamicChartsModel(); // assign country with this
            CampaignViewModel  camVM = new CampaignViewModel();
            // get all the campaigns in the list with thier ids
            List <CampaignDTO> camp = new List <CampaignDTO>();

            camp = camVM.GetAllCampaigns();

            List <string> campaingCountrylist = new List <string>();  // get the campaigns name from the list campaings model and add them to string list

            foreach (var item in camp)
            {
                if (!campaingCountrylist.Contains(item.Country.ToString()))
                {
                    campaingCountrylist.Add(item.Country);
                }
            }

            dM.Countries = campaingCountrylist; // string list of campaigns names, store them in the Campaigns list where declared in the model
            List <string> allCampaignsOfCountry = new List <string>();

            foreach (var cam in camp)
            {
                if (country == cam.Country)
                {
                    allCampaignsOfCountry.Add(cam.Description); // get all the campaigns related to the country
                }
            }
            dM.Campaigns = allCampaignsOfCountry;
            dM.Campagin  = allCampaignsOfCountry.First();
            dM.Country   = country;
            return(Json(dM, JsonRequestBehavior.AllowGet));
        }
        public List <CampaignDTO> GetCampaigns() // accessing the database in CampaignViewModels/CampaignViewModel to get all the campaigns
        {
            CampaignViewModel  campVM    = new CampaignViewModel();
            List <CampaignDTO> campaigns = campVM.GetAllCampaigns();

            return(campaigns);
        }
Exemple #3
0
        public ActionResult Index()
        {
            // get all the list of Campaign from the UserStatusViewModels and return the model to cshtml page

            CampaignViewModel  campVM    = new CampaignViewModel();
            List <CampaignDTO> campaigns = campVM.GetAllCampaigns();

            return(View(campaigns));
        }
        // GET: DynamicallyUpdateChart
        public ActionResult CountryChart()
        {
            DynamicChartsModel dM = new DynamicChartsModel();
            //CandidateDTO candidateDTO = new CandidateDTO();
            CampaignViewModel camVM = new CampaignViewModel();
            // get all the campaigns in the list with thier ids
            List <CampaignDTO> camp = new List <CampaignDTO>();

            camp = camVM.GetAllCampaigns();

            List <string> campaingCountrylist = new List <string>();  // get the campaigns name from the list campaings model and add them to string list

            foreach (var item in camp)
            {
                if (!campaingCountrylist.Contains(item.Country.ToString()))
                {
                    campaingCountrylist.Add(item.Country);
                }
            }
            campaingCountrylist.Sort();
            dM.Countries = campaingCountrylist;       // string list of campaigns names, store them in the Campaigns list where declared in the model

            dM.Country = campaingCountrylist.First(); // get the first country for the Campaigns
            var           country = dM.Country;
            List <string> allCampaignsOfCountry = new List <string>();

            foreach (var cam in camp)
            {
                if (country == cam.Country)
                {
                    allCampaignsOfCountry.Add(cam.Description); // get all the campaigns related to the country
                }
            }


            bool isEmpty = !allCampaignsOfCountry.Any();

            if (!isEmpty) // check if the list is not null than add the values to the object , else redirect the user that there are no campaigns in the country
            {
                dM.Campaigns = allCampaignsOfCountry;
                dM.Campagin  = allCampaignsOfCountry.First();

                CampaignDashBoardList(dM.Country, dM.Campagin); // default draw of the data
                return(View("~/Views/DynamicallyUpdateChart/CountryChart.cshtml", dM));
            }
            else
            {
                return(View("~/Views/Results/NotFound.cshtml")); // no ca
            }
        }
        // GET: Results/ResultsChart
        public ActionResult ResultsChart()
        {
            String uId = User.Identity.GetUserId();        // get logged in users Id

            ResultsViewModel rVM = new ResultsViewModel(); // get all the user roles


            ResultsDTO results = new ResultsDTO(); //


            List <ResultsDTO> resultsDTO = rVM.GetUsersRole();

            bool found = false;

            foreach (var result in resultsDTO)
            {
                if (uId != result.UserId)
                {
                    found = true;
                }
            }
            CampaignViewModel  camVM    = new CampaignViewModel(); // get all the campaign
            List <CampaignDTO> campaign = new List <CampaignDTO>();

            campaign = camVM.GetAllCampaigns();

            ChartsViewModel   cVM         = new ChartsViewModel();
            RegisterViewModel userDetails = cVM.GetUserDetailsById(uId);  // get signed in users details

            List <string> usersCountryCampainglist = new List <string>(); // get the campaigns name from the list campaings model and add them to string list

            if (found == true)                                            // if the user exist
            {
                foreach (var cam in campaign)
                {
                    if (userDetails.Country == cam.Country)
                    {
                        if (!usersCountryCampainglist.Contains(cam.Description.ToString()))
                        {
                            usersCountryCampainglist.Add(cam.Description);
                        }
                    }
                }
            }
            //bool isEmpty = !results.Any();
            bool isEmpty = !usersCountryCampainglist.Any();

            if (!isEmpty) // check if the list is not null than add the values to the object , else redirect the user that there are no campaigns in the country
            {
                results.Campagin  = usersCountryCampainglist.First();
                results.Campaigns = usersCountryCampainglist;
                ViewBag.Campaign  = usersCountryCampainglist.First();         // get the first country for the Campaigns
                var collectedCampaign = usersCountryCampainglist.First();     // get the first country for the Campaigns
                CampaignDashBoardList(collectedCampaign);                     // default draw of the data
                return(View("~/Views/Results/ResultsChart.cshtml", results)); // return with the values to view.
            }
            else
            {
                return(View("~/Views/Results/NotFound.cshtml")); // no ca
            }
        }
Exemple #6
0
        // 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
        }