// POST: api/Register public string Post(RegisterUser val) { string status = "failure"; using (RegisterDataAccess.votingdbEntities entities = new RegisterDataAccess.votingdbEntities()) { RegisterDataAccess.RegisterUser users = new RegisterDataAccess.RegisterUser(); users.User_Id = val.User_Id; var y = entities.RegisterUsers.ToList(); RegisterDataAccess.RegisterUser registerUser = new RegisterDataAccess.RegisterUser(); foreach (RegisterDataAccess.RegisterUser u in y) { if (decrypt(val.Email) == u.Email && val.PIN == u.PIN && u.DeviceId == null) { // var pass = decrypt(val.User_Password); // u.User_Password = pass; u.User_Password = val.User_Password; var d_deviceid = decrypt(val.DeviceId); u.DeviceId = d_deviceid; status = "success"; } } entities.SaveChanges(); } return(status); }
public IEnumerable <RegisterUser> Get() { using (RegisterDataAccess.votingdbEntities entities = new RegisterDataAccess.votingdbEntities()) { var x = entities.RegisterUsers.ToList(); foreach (RegisterUser u in x) { var uid = u.User_Id; var email = u.Email; var pass = u.User_Password; var vid = u.VoterId; var pin = u.PIN; var deviceid = u.DeviceId; var status = u.Voting_Status; RegisterUser user = new RegisterUser(); user.User_Id = uid; user.Email = email; user.User_Password = pass; user.VoterId = vid; user.PIN = pin; user.DeviceId = deviceid; user.Voting_Status = status; data.Add(user); } } return(data); }
public void Post(CastedVote val) { using (votedbEntities entities = new votedbEntities()) { var x = entities.Votes.ToList(); Vote vote = new Vote(); vote.CandidateId = val.CandidateId; var cname = decrypt(val.CandidateName); vote.CandidateName = cname; foreach (VoteDataAccess.Vote c in x) { if (val.CandidateId == c.CandidateId) { var currentVotes = c.Votes; currentVotes += 1; // Updating for adding a new vote c.Votes = currentVotes; } } using (RegisterDataAccess.votingdbEntities uentities = new RegisterDataAccess.votingdbEntities()) { var y = uentities.RegisterUsers.ToList(); RegisterDataAccess.RegisterUser users = new RegisterDataAccess.RegisterUser(); foreach (RegisterDataAccess.RegisterUser u in y) { if (val.UserEmail == u.Email) { u.Voting_Status = true; } } uentities.SaveChanges(); SendEmail(val.UserEmail); } // entities.Votes.Add(vote); entities.SaveChanges(); } }
public String Post(RegisterUser val) { var result = "Failure"; // DateTime startdate = new DateTime(2021, 05, 01, 12, 00, 00); // DateTime enddate = new DateTime(2021, 05, 15, 11, 00, 00); DateTime currentdate = DateTime.Now; using (ElectionStartEndDataAccess.startenddbEntities startenddbEntities = new ElectionStartEndDataAccess.startenddbEntities()) { ElectionStartEndDataAccess.ElectionStartEnd startEnd = new ElectionStartEndDataAccess.ElectionStartEnd(); var y = startenddbEntities.ElectionStartEnds.ToList(); foreach (ElectionStartEndDataAccess.ElectionStartEnd a in y) { if (currentdate > a.EndDate) { result = "election_over"; } else { result = "check_later"; } // } // } if (currentdate >= a.StartDate && currentdate <= a.EndDate) { using (RegisterDataAccess.votingdbEntities entities = new RegisterDataAccess.votingdbEntities()) { RegisterDataAccess.RegisterUser registerUser = new RegisterDataAccess.RegisterUser(); var x = entities.RegisterUsers.ToList(); foreach (RegisterDataAccess.RegisterUser u in x) { if (decrypt(val.Email) == u.Email && val.User_Password == u.User_Password && decrypt(val.DeviceId) == u.DeviceId) { result = "Success"; if (u.Voting_Status == true) { result = "Voted"; break; } } } } } } } /* * else * { * if(currentdate >= enddate) * { * result = "election_over"; * } * else * { * result = "check_later"; * } * } * */ return(result); }