public List <Poll> GetPolls() { using (var ctx = new VoteContext()) { return(ctx.Polls.Include(r => r.Choices).ToList()); } }
public User GetUser(int Id) { using (VoteContext voteContext = new VoteContext()) { return(voteContext.Users.Include(x => x.UserPolicies).FirstOrDefault(p => p.Id == Id)); } }
public void CastVote(VoteForm vote) { using (var questions = new VoteContext()) { var currQuest = questions.AskedQuestions.SingleOrDefault(x => x.Question == vote.Question); var hasAsked = questions.UserVotes.SingleOrDefault(x => x.QuestionsId == currQuest.Id && x.UserId == vote.UserId); if (hasAsked == null) { var addVoteToDB = new UserVote() { UserId = vote.UserId, QuestionsId = currQuest.Id, Vote = vote.Vote }; questions.UserVotes.Add(addVoteToDB); if (vote.Vote == "Yes") { currQuest.For += 1; } else { currQuest.Against += 1; } currQuest.Votes += 1; questions.SaveChanges(); } } }
/// <summary> /// Initializes a new instance of the <see cref="UserManager" /> class. /// </summary> /// <param name="assignProxyVM"></param> /// <param name="dataContext">data context</param> /// <param name="_kernel"></param> public UserManager(IAssignProxyVM assignProxyVM, VoteContext dataContext, IKernel kernel) { this.dataContext = dataContext; this.assignProxyVM = assignProxyVM; applicationPath = ConfigurationManager.AppSettings["AppPath"]; this._kernel = kernel; }
public List <Poll> GetPolls() { using (var ctx = new VoteContext()) { return(ctx.Polls.ToList()); } }
public User GetUser(string email) { using (VoteContext voteContext = new VoteContext()) { return(voteContext.Users.FirstOrDefault(u => u.Email == email)); } }
public int GetRegiondIdByName(string name) { using (VoteContext voteContext = new VoteContext()) { return(voteContext.Regions.FirstOrDefault(r => r.Name == name).Id); } }
public int GetUserId(string name) { using (VoteContext voteContext = new VoteContext()) { return(voteContext.Users.FirstOrDefault(u => u.Name == name).Id); } }
public async Task <IActionResult> Vote([FromBody] VoteCandidate vote, [FromServices] VoteContext voteContext) { var votingId = await ValidateGuidVoting(vote.VortingGuid); if (votingId > 0) { try { var voteCandidate = new VotesCandidate { CandidateId = vote.CandidateId, VotingId = votingId }; await voteContext.VotesCandidates.AddAsync(voteCandidate); await voteContext.SaveChangesAsync(); await CountCandidatesVotes(vote.VortingGuid, votingId); return(Ok()); } catch (Exception ex) { return(BadRequest(ex.Message)); } } return(Ok(vote)); }
public int GetRegionId(int userId) { using (VoteContext voteContext = new VoteContext()) { return(voteContext.Users.FirstOrDefault(u => u.Id == userId).RegionId); } }
// this is because you might want to get an ID without the whole aggregate - do it public int?GetPollId(string pollName) { using (var ctx = new VoteContext()) { return(ctx.Polls.FirstOrDefault(p => p.Name == pollName)?.Id); } }
public bool IsInRegion(int regionId, int userId) { using (VoteContext voteContext = new VoteContext()) { return(voteContext.Users.FirstOrDefault(u => u.Id == userId).RegionId == regionId); } }
public List <UserPolicy> GetAllAccessPolicies(int userId) { using (VoteContext voteContext = new VoteContext()) { return(voteContext.UserPolicies.Where(u => (u.user.Id == userId) && (u.PolicyType == (PolicyType)0)).ToList()); } }
public Region Get(int id) { using (var ctx = new VoteContext()) { return(ctx.Regions.Include(r => r.RegionPolicies).FirstOrDefault(r => r.Id == id)); } }
// public void Update(Vote vote) // { // using (var ctx = new VoteContext()) // { // ctx.Votes.FirstOrDefault(vote => vote.Id == vote.Id).voteStart = vote.voteStart; // ctx.Votes.FirstOrDefault(vote => vote.Id == vote.Id).voteEnd = vote.voteEnd; // ctx.Votes.FirstOrDefault(vote => vote.Id == vote.Id).choiceId = vote.choiceId; // } // } public bool ExistingUser(int userId) { using (var ctx = new VoteContext()) { return(ctx.Votes.Any(u => u.UserId == userId)); } }
//public List<Vote> GetAllForUser(int userId) //{ // throw new NotImplementedException(); //} public List <Vote> GetAllForUser(int userId) { using (var ctx = new VoteContext()) { return(ctx.Votes.Where(u => u.UserId == userId).ToList()); } }
/// <summary> /// Initializes a new instance of the <see cref="ChartManager" /> class. /// </summary> /// <param name="voteResultChartVM">voteResultChart view model</param> /// <param name="dataContext">data context</param> /// <param name="ipollManager">poll manager</param> /// <param name="kernel">DI kernel</param> public ChartManager(IVoteResultChartVM voteResultChartVM, VoteContext dataContext, IPollManager ipollManager, IKernel kernel) { this.voteResultChartVM = voteResultChartVM; this.context = dataContext; this.ipollManager = ipollManager; this.krnel = kernel; }
public async Task <IActionResult> Get() { using (var db = new VoteContext()) { return(Ok(db.Vote.ToList())); } }
/// <summary> /// Initializes a new instance of the <see cref="ExportDataManager" /> class. /// </summary> /// <param name="dataContext">data context</param> /// <param name="userManager">user manager business</param> /// <param name="kernel">DI kernel</param> /// <param name="pollManager">Poll manager business</param> public ExportDataManager(VoteContext dataContext, IUserManager userManager, IKernel kernel, IPollManager pollManager) { this.context = dataContext; this.userManager = userManager; this.kernel = kernel; this.pollManager = pollManager; }
public Poll Get(string pollName) { using (var ctx = new VoteContext()) { return(ctx.Polls.Include(x => x.Choices).FirstOrDefault(p => p.Name == pollName)); } }
public List <User> GetAllUsersForRegion(int regionId) { using (VoteContext voteContext = new VoteContext()) { return(voteContext.Users.ToList().Where(u => u.RegionId == regionId).ToList()); } }
public Region Get(int id) { using (var ctx = new VoteContext()) { return(ctx.Regions.FirstOrDefault(p => p.Id == id)); } }
public void AddChoiceToPoll(Choice choice, int pollId) { using (var ctx = new VoteContext()) { ctx.Polls.FirstOrDefault(p => p.Id == pollId).Choices.Add(choice); ctx.SaveChanges(); } }
public void Create(Vote vote) { using (var ctx = new VoteContext()) { ctx.Votes.Add(vote); ctx.SaveChanges(); } }
public User GetUser(int Id) { using (VoteContext voteContext = new VoteContext()) { return(voteContext.Users. FirstOrDefault(p => p.Id == Id)); } }
public User GetUser(string PaspCode, int IndefCode) { using (VoteContext voteContext = new VoteContext()) { return(voteContext.Users. FirstOrDefault(p => (p.PassportCode == PaspCode) && (p.IdentificationCode == IndefCode))); } }
public void CreateRegion(Region region) { using (VoteContext voteContext = new VoteContext()) { voteContext.Regions.Add(region); voteContext.SaveChangesAsync(); } }
public void CreateUser(User user) { using (VoteContext voteContext = new VoteContext()) { voteContext.Users.Add(user); voteContext.SaveChangesAsync(); } }
public void Create(Poll poll) { using (var ctx = new VoteContext()) { ctx.Polls.Add(poll); ctx.SaveChanges(); } }
public void UpdateRegion(Region region) { using (VoteContext voteContext = new VoteContext()) { Region regiontemp = voteContext.Regions.FirstOrDefault(r => r.Id == region.Id); regiontemp = region; voteContext.SaveChangesAsync(); } }