コード例 #1
0
        public async Task <IActionResult> Create(CandidatesViewModel view)
        {
            if (ModelState.IsValid)
            {
                var path = string.Empty;

                if (view.ImageFile != null && view.ImageFile.Length > 0)
                {
                    var guid = Guid.NewGuid().ToString();
                    var file = $"{guid}.jpg";

                    path = Path.Combine(
                        Directory.GetCurrentDirectory(),
                        "wwwroot\\images\\Candidate",
                        file);

                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        await view.ImageFile.CopyToAsync(stream);
                    }

                    path = $"~/images/Candidate/{file}";
                }
                var candidates = this.ToActvote(view, path);
                await this.candidatesRepository.CreateAsync(candidates);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(view));
        }
コード例 #2
0
        public ActionResult Delete(string id)
        {
            CandidatesViewModel candidateVM = new CandidatesViewModel();

            candidateVM.DeleteCandidateDetailsById(id);
            return(Redirect("~/Candidate/Index"));
        }
コード例 #3
0
        // GET: /Vote/Index
        public ActionResult Index()
        {
            CandidatesViewModel candidateVM = new CandidatesViewModel();
            List <CandidateDTO> candidates  = candidateVM.GetAllCandidates();

            return(View(candidates));
        }
コード例 #4
0
        public List <CandidateDTO> GetCandidates() // accessing the database to get all the candidates
        {
            CandidatesViewModel candidateVM = new CandidatesViewModel();
            List <CandidateDTO> candidates  = candidateVM.GetAllCandidates();

            return(candidates);
        }
コード例 #5
0
        public ActionResult Rejected()
        {
            var repo = new CandidatesRepository(Properties.Settings.Default.ConStr);
            var vm   = new CandidatesViewModel();

            vm.Candidates = repo.GetCandidates(CandidateStatus.Rejected);
            return(View(vm));
        }
コード例 #6
0
        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));
        }
コード例 #7
0
        public ActionResult GetClass(int?graduationYear)
        {
            CandidatesViewModel model = new CandidatesViewModel();

            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Candidate", "Welcome"));
            }

            graduationYear = graduationYear ??
                             (Request.Cookies.AllKeys.Contains("selected-class") ?
                              int.Parse(Request.Cookies["selected-class"].Value) : 2017);

            if (graduationYear < 2016 || graduationYear > 2018)
            {
                graduationYear = 2017;
            }

            model.GraduationYear = graduationYear.Value;
            Response.Cookies.Set(new HttpCookie("selected-class", graduationYear.ToString()));

            var positions = db.Users
                            .Where(user => user.IsConfirmed && user.GraduationYear == graduationYear)
                            .GroupBy(cand => cand.Position.ToLower())
                            .ToDictionary(c => c.Key, c => c.ToList());

            foreach (var position in positions)
            {
                if (!(new[] { "secretary", "treasurer", "vice president", "president" }.Contains(
                          position.Key)))
                {
                    continue;
                }

                var positionModel = new PositionViewModel {
                    Name = position.Key
                };

                var rand       = new Random();
                var candidates = position.Value
                                 .Where(candidate => candidate.ProfilePicture != null)
                                 .OrderBy(a => rand.Next())
                                 .ToList();

                foreach (var cand in candidates)
                {
                    cand.ToString();
                }

                Mapper.CreateMap <Candidate, CandidateViewModel>();
                positionModel.Candidates = Mapper.Map <List <Candidate>, List <CandidateViewModel> >(candidates);

                model.Positions.Add(positionModel);
            }

            return(View());
        }
コード例 #8
0
        public ActionResult Rejected()
        {
            var repo = new CandidateRepository(Properties.Settings.Default.ConStr);
            var vm   = new CandidatesViewModel();

            vm.Candidates = repo.GetRejected();
            vm.Decision   = Status.Rejected;
            return(View("Decided", vm));
        }
コード例 #9
0
        public IActionResult Declined()
        {
            ViewBag.Page = Active.Declined;
            CandidateRepository repo = new CandidateRepository(_connectionString);
            CandidatesViewModel vm   = new CandidatesViewModel();

            vm.Candidates = repo.GetCandidates(Status.Declined);
            vm.Message    = "Declined";
            return(View("Candidates", vm));
        }
コード例 #10
0
 private Candidates ToActvote(CandidatesViewModel view, string path)
 {
     return(new Candidates
     {
         Id = view.Id,
         ImageUrl = path,
         name = view.name,
         LastName = view.LastName,
         Polparty = view.Polparty
     });
 }
コード例 #11
0
        public IActionResult Candidates()
        {
            ViewBag.Page = Active.Pending;
            CandidateRepository repo = new CandidateRepository(_connectionString);
            CandidatesViewModel vm   = new CandidatesViewModel();

            vm.Candidates = repo.GetCandidates(Status.Pending);
            vm.Message    = "Pending";
            vm.Pending    = true;
            return(View(vm));
        }
コード例 #12
0
        public bool UpdateCandidateDetails(CandidatesViewModel model)
        {
            UserModel candidate = new UserModel()
            {
                UserId      = model.Id,
                FirstName   = model.FirstName,
                LastName    = model.LastName,
                CandidateId = model.CandidateId,
                Password    = model.Password
            };
            bool result = dashboardRepository.UpdateCandidateDetails(candidate);

            return(result);
        }
コード例 #13
0
        public CandidatesViewModel GetCandidateDetails(int userid)
        {
            var details = dashboardRepository.GetCandidateDetails(userid);
            CandidatesViewModel candidatedetails = new CandidatesViewModel();

            if (details != null && details.Rows.Count > 0)
            {
                candidatedetails.Id          = userid;
                candidatedetails.CandidateId = details.Rows[0]["Candidateid"] as string ?? "";
                candidatedetails.FirstName   = details.Rows[0]["FirstName"] as string ?? "";
                candidatedetails.LastName    = details.Rows[0]["LastName"] as string ?? "";
                candidatedetails.Email       = details.Rows[0]["Email"] as string ?? "";
                candidatedetails.Password    = details.Rows[0]["Password"] as string ?? "";
            }
            return(candidatedetails);
        }
コード例 #14
0
        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));
        }
コード例 #15
0
        public PartialViewResult CandidateDetail(int userid)
        {
            var user = HttpContext.Session.Get <UserViewModel>(Constants.SessionKeyUserInfo);

            user = user ?? new UserViewModel();
            CandidatesViewModel candidatedetail = null;

            try
            {
                candidatedetail = dashboardHandler.GetCandidateDetails(userid);
            }
            catch (DataNotFound ex)
            {
                Logger.Logger.WriteLog(Logger.Logtype.Error, ex.Message, user.UserId, typeof(DashboardController), ex);
            }
            return(PartialView("CandidateDetailFormPartial", candidatedetail));
        }
コード例 #16
0
        public JsonResult UpdateCandidate([FromBody] CandidatesViewModel candidate)
        {
            var user = HttpContext.Session.Get <UserViewModel>(Constants.SessionKeyUserInfo);

            user = user ?? new UserViewModel();
            bool isUpdated = true;

            try
            {
                isUpdated = dashboardHandler.UpdateCandidateDetails(candidate);
            }
            catch (DataNotFound ex)
            {
                isUpdated = false;
                Logger.Logger.WriteLog(Logger.Logtype.Error, ex.Message, user.UserId, typeof(DashboardController), ex);
            }
            return(Json(new { isUpdated }));
        }
コード例 #17
0
        public async Task <IActionResult> Edit(CandidatesViewModel view)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var path = view.ImageUrl;

                    if (view.ImageFile != null && view.ImageFile.Length > 0)
                    {
                        var guid = Guid.NewGuid().ToString();
                        var file = $"{guid}.jpg";

                        path = Path.Combine(
                            Directory.GetCurrentDirectory(),
                            "wwwroot\\images\\Candidate",
                            file);

                        using (var stream = new FileStream(path, FileMode.Create))
                        {
                            await view.ImageFile.CopyToAsync(stream);
                        }

                        path = $"~/images/Candidate/{file}";
                    }
                    var candidates = this.ToActvote(view, path);

                    await this.candidatesRepository.UpdateAsync(candidates);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!await this.candidatesRepository.ExistAsync(view.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(view));
        }
コード例 #18
0
        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));
        }
コード例 #19
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");

            }
        }
コード例 #20
0
        public ActionResult Candidates(int id, int? page)
        {
            var contestOwnerId = this.Data.Contests.All()
                .Where(c => c.Id == id)
                .Select(c => c.OwnerId)
                .FirstOrDefault();

            if (this.User.Identity.GetUserId() != contestOwnerId && !this.User.IsInRole("Administrator"))
            {
                HttpResponseMessage message = new HttpResponseMessage(HttpStatusCode.Unauthorized);
                message.Content = new StringContent(Messages.NotAuhtorized);
                throw new System.Web.Http.HttpResponseException(message);
            }

            var contestCandidates = this.Data.Contests.All()
                .Where(c => c.Id == id)
                .Select(c => c.Candidates)
                .FirstOrDefault()
                .ToPagedList(page ?? GlobalConstants.DefaultStartPage, GlobalConstants.DefaultPageSize);

            if (contestCandidates == null)
            {
                HttpResponseMessage message = new HttpResponseMessage(HttpStatusCode.NotFound);
                message.Content = new StringContent(Messages.ContestNotFound);
                throw new System.Web.Http.HttpResponseException(message);
            }

            var candidatesView = Mapper.Map<IPagedList<User>, IPagedList<BasicUserInfoViewModel>>(contestCandidates);
            var candidatesViewModel = new CandidatesViewModel
            {
                Candidates = candidatesView,
                IsContestOwner = true,
                ContestId = id
            };

            return this.View(candidatesViewModel);
        }
コード例 #21
0
        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
        }
コード例 #22
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);
        }