Esempio n. 1
0
 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();
         }
     }
 }
Esempio n. 4
0
 /// <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;
 }
Esempio n. 5
0
 public List <Poll> GetPolls()
 {
     using (var ctx = new VoteContext())
     {
         return(ctx.Polls.ToList());
     }
 }
Esempio n. 6
0
 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);
     }
 }
Esempio n. 8
0
 public int GetUserId(string name)
 {
     using (VoteContext voteContext = new VoteContext())
     {
         return(voteContext.Users.FirstOrDefault(u => u.Name == name).Id);
     }
 }
Esempio n. 9
0
        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));
        }
Esempio n. 10
0
 public int GetRegionId(int userId)
 {
     using (VoteContext voteContext = new VoteContext())
     {
         return(voteContext.Users.FirstOrDefault(u => u.Id == userId).RegionId);
     }
 }
Esempio n. 11
0
 // 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);
     }
 }
Esempio n. 12
0
 public bool IsInRegion(int regionId, int userId)
 {
     using (VoteContext voteContext = new VoteContext())
     {
         return(voteContext.Users.FirstOrDefault(u => u.Id == userId).RegionId == regionId);
     }
 }
Esempio n. 13
0
 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));
     }
 }
Esempio n. 15
0
        //        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));
            }
        }
Esempio n. 16
0
        //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());
            }
        }
Esempio n. 17
0
 /// <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;
 }
Esempio n. 18
0
 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;
 }
Esempio n. 20
0
 public Poll Get(string pollName)
 {
     using (var ctx = new VoteContext())
     {
         return(ctx.Polls.Include(x => x.Choices).FirstOrDefault(p => p.Name == pollName));
     }
 }
Esempio n. 21
0
 public List <User> GetAllUsersForRegion(int regionId)
 {
     using (VoteContext voteContext = new VoteContext())
     {
         return(voteContext.Users.ToList().Where(u => u.RegionId == regionId).ToList());
     }
 }
Esempio n. 22
0
 public Region Get(int id)
 {
     using (var ctx = new VoteContext())
     {
         return(ctx.Regions.FirstOrDefault(p => p.Id == id));
     }
 }
Esempio n. 23
0
 public void AddChoiceToPoll(Choice choice, int pollId)
 {
     using (var ctx = new VoteContext())
     {
         ctx.Polls.FirstOrDefault(p => p.Id == pollId).Choices.Add(choice);
         ctx.SaveChanges();
     }
 }
Esempio n. 24
0
 public void Create(Vote vote)
 {
     using (var ctx = new VoteContext())
     {
         ctx.Votes.Add(vote);
         ctx.SaveChanges();
     }
 }
Esempio n. 25
0
 public User GetUser(int Id)
 {
     using (VoteContext voteContext = new VoteContext())
     {
         return(voteContext.Users.
                FirstOrDefault(p => p.Id == Id));
     }
 }
Esempio n. 26
0
 public User GetUser(string PaspCode, int IndefCode)
 {
     using (VoteContext voteContext = new VoteContext())
     {
         return(voteContext.Users.
                FirstOrDefault(p => (p.PassportCode == PaspCode) && (p.IdentificationCode == IndefCode)));
     }
 }
Esempio n. 27
0
 public void CreateRegion(Region region)
 {
     using (VoteContext voteContext = new VoteContext())
     {
         voteContext.Regions.Add(region);
         voteContext.SaveChangesAsync();
     }
 }
Esempio n. 28
0
 public void CreateUser(User user)
 {
     using (VoteContext voteContext = new VoteContext())
     {
         voteContext.Users.Add(user);
         voteContext.SaveChangesAsync();
     }
 }
Esempio n. 29
0
 public void Create(Poll poll)
 {
     using (var ctx = new VoteContext())
     {
         ctx.Polls.Add(poll);
         ctx.SaveChanges();
     }
 }
Esempio n. 30
0
 public void UpdateRegion(Region region)
 {
     using (VoteContext voteContext = new VoteContext())
     {
         Region regiontemp = voteContext.Regions.FirstOrDefault(r => r.Id == region.Id);
         regiontemp = region;
         voteContext.SaveChangesAsync();
     }
 }