public List <VotesDTO> GetAllTheVotes() { SqlConnection sqlconn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString); List <VotesDTO> list = new List <VotesDTO>(); using (sqlconn) { using (SqlCommand cmd = new SqlCommand("getAllTheVotes", sqlconn)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; sqlconn.Open(); using (SqlDataReader rdr = cmd.ExecuteReader()) { while (rdr.Read()) { VotesDTO userCampaign = new VotesDTO { UserId = rdr["UserId"].ToString(), CandidateId = rdr["CandidateID"].ToString(), CampaignID = rdr["CampaignID"].ToString() }; list.Add(userCampaign); } } } } return(list); }
public static void addVote(string siteName) { using (RecipezeEntities db = new RecipezeEntities()) { try { var numOfVotes = db.Votes.Where(a => a.siteName == siteName).ToList(); if (numOfVotes.Count == 0) { VotesDTO voting = new VotesDTO() { siteName = siteName, voteNumbers = 1 }; db.Votes.Add(CONVERTERS.VotesConverter.ConvertVoteToDAL(voting)); db.SaveChanges(); } else { var voteUpdate = db.Votes.Where ( p => siteName.Contains(p.siteName) ); foreach (Vote p in voteUpdate) { p.voteNumbers++; } db.SaveChanges(); } } catch (Exception e) { Console.WriteLine(e); } } }
public static Vote ConvertVoteToDAL(VotesDTO vote) { return(new Vote { siteName = vote.siteName, voteNumbers = vote.voteNumbers }); }
public ActionResult Scan_FingerForeVote(VotesDTO paramVotesDTO) { Candidate candidate = null; try { if (paramVotesDTO == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } else { // get logged in user id String userId = User.Identity.GetUserId(); // get user fingerprint VoteViewModel voteVM = new VoteViewModel(); ViewBag.fingerprint = voteVM.GetUserFingerprint(userId); // passing user id and finger print to the frontend ViewBag.userId = userId; var canId = paramVotesDTO.CandidateId; ViewBag.candidateID = canId; VoteViewModel vvM = new VoteViewModel(); candidate = vvM.GetCandidateDetailsById(canId); //Get the candidate details ViewBag.Name = candidate.Name; ViewBag.Surname = candidate.Surname; ViewBag.Gender = candidate.Gender; ViewBag.Picture = candidate.CandidatePic; ViewBag.CampaignID = candidate.CampaignID; } return View(); } catch (Exception ex) { ModelState.AddModelError(string.Empty, "Error: " + ex); return View(); } }