コード例 #1
0
        private void DeleteDownvote_Click(object sender, RoutedEventArgs e)
        {
            VoteDetails vote = (VoteDetails)((FrameworkElement)sender).DataContext;

            using SQLiteCommand cmd = GlobalFunction.OpenDbConnection();
            cmd.CommandText         = $"DELETE FROM votes WHERE voteId = @voteId";
            cmd.Parameters.AddWithValue("voteId", vote.ID);
            cmd.Prepare();
            cmd.ExecuteNonQuery();

            DownvoteList.Remove(DownvoteList.Where(i => i.ID == vote.ID).Single());
        }
コード例 #2
0
        private ObservableCollection <VoteDetails> ParseVoteList(List <VotesInfo> votesList)
        {
            ObservableCollection <VoteDetails> newListVote = new ObservableCollection <VoteDetails>();

            foreach (VotesInfo vote in votesList)
            {
                int         voteTimestamp = vote.creationDate;
                DateTime    voteDateTime  = DateTimeOffset.FromUnixTimeSeconds(voteTimestamp).LocalDateTime;
                VoteDetails voteDetails   = new VoteDetails()
                {
                    ID      = vote.voteId,
                    Content = vote.description,
                    Date    = voteDateTime.ToString("g", GlobalVariable.culture)
                };
                newListVote.Add(voteDetails);
            }
            return(newListVote);
        }
コード例 #3
0
        public HttpResponseMessage PostVote([FromUri] int codeJewelId, [FromBody] Vote vote)
        {
            return(this.ProcessAndHandleExceptions(() =>
            {
                Validator.ValidateVote(vote);

                var dbContext = new CodeJewelsDb();
                var codeJewel = dbContext.CodeJewels.Include("Category").FirstOrDefault(cj => cj.Id == codeJewelId);

                if (codeJewel == null)
                {
                    throw new ArgumentOutOfRangeException("No such Code jewel found - invalid vote");
                }

                vote.CodeJewel = codeJewel;
                dbContext.Votes.Add(vote);
                dbContext.SaveChanges();

                var voteDetails = new VoteDetails
                {
                    Id = vote.Id,
                    CodeJewel = new CodeJewelModel
                    {
                        Id = codeJewel.Id,
                        Category = codeJewel.Category.Name,
                        Code = codeJewel.Code.Length >= 20 ? codeJewel.Code.Substring(0, 20) : codeJewel.Code,
                    },
                    IsUpVote = vote.IsUpVote,
                };

                var response = this.Request.CreateResponse(HttpStatusCode.Created, voteDetails);
                var location = new Uri(this.Url.Link("CodeJewelVoteApi", new { id = vote.Id }));
                response.Headers.Location = location;

                return response;
            }));
        }
コード例 #4
0
 // *********************************************************************
 //  Vote
 //
 /// <summary>
 // Get Poll Details reads the XML file (or cache)
 // and fills an instance class with details
 /// </summary>
 // ***********************************************************************/
 public Vote(int postID, string postSubject, string postBody)
 {
     this.postID = postID;
     voteResults = Votes.GetVoteResults(postID);
     voteDetails = new VoteDetails(postID, postSubject, postBody);
 }
コード例 #5
0
        private static string GetStatusText(XPathNavigator root, XPathNavigator status, out object details)
        {
            try {
                bool isCurrentSession = true;         // default
                // this doesn't work on index nodes
                if (root.GetAttribute("session", "") != "")
                {
                    int session = int.Parse(root.GetAttribute("session", ""));
                    isCurrentSession = (session == Util.CurrentSession);
                }

                BillStatus s = EnumsConv.BillStatusFromString(status.Name);
                switch (s)
                {
                case BillStatus.Introduced:
                    /*if ((string)status.Evaluate("name(parent::*)") == "status")
                     *      details = new IntroducedDetails(int.Parse((string)root.Evaluate("string(/bill/sponsor/@id)")));
                     * else if ((string)status.Evaluate("name(parent::*)") == "statusxml")
                     *      details = null;
                     * else
                     *      details = new IntroducedDetails(int.Parse((string)status.Evaluate("string(@sponsor)")));*/
                    details = null;
                    if (isCurrentSession)
                    {
                        return("Introduced");
                    }
                    else
                    {
                        return("Dead");
                    }

                case BillStatus.Calendar:
                    details = null;
                    if (isCurrentSession)
                    {
                        return("Reported by Committee");
                    }
                    else
                    {
                        return("Dead");
                    }

                case BillStatus.Vote:
                case BillStatus.Vote2:
                    if (status.GetAttribute("how", "") == "roll")
                    {
                        string info = "";
                        try {
                            DateTime date = Util.DTToDateTime(status.GetAttribute("date", ""));
                            string   file = GetRollFileName(status.GetAttribute("where", ""), date, int.Parse(status.GetAttribute("roll", ""))) + ".txt";
                            info = Util.LoadFileString(Util.SessionFromDateTime(date), "gen.rolls-pca" + Path.DirectorySeparatorChar + file);
                        } catch (Exception e) { }
                        details = new VoteDetails(
                            status.GetAttribute("where", "") == "h" ? Chamber.House : Chamber.Senate,
                            Util.DTToDateTime(status.GetAttribute("datetime", "")),
                            int.Parse(status.GetAttribute("roll", "")),
                            status.GetAttribute("result", "") == "pass",
                            info
                            );
                    }
                    else
                    {
                        details = null;
                    }
                    string result = status.GetAttribute("result", "");
                    if (result == "pass")
                    {
                        result = "Passed";
                    }
                    else if (result == "fail")
                    {
                        result = "Failed";
                    }
                    else
                    {
                        throw new InvalidOperationException("Invalid vote result: " + result);
                    }
                    Chamber chamber = EnumsUtil.BillTypeChamber(EnumsConv.BillTypeFromString(status.GetAttribute("where", "")));
                    if (s == BillStatus.Vote)
                    {
                        return(result + " " + EnumsConv.ChamberNameShort(chamber));
                    }
                    else
                    {
                        return("Passed " + EnumsConv.ChamberNameShort(EnumsUtil.Other(chamber))
                               + ", " + result + " " + EnumsConv.ChamberNameShort(chamber));
                    }

                case BillStatus.Conference:
                    details = "";
                    return("Resolving Differences");

                case BillStatus.ToPresident:
                    details = null;
                    return("Sent to President");

                case BillStatus.Signed:
                    details = null;
                    return("Signed by President");

                case BillStatus.Veto:
                    details = null;
                    return("Vetoed by President");

                case BillStatus.Override:
                    details = null;
                    string result1 = status.GetAttribute("result", "");
                    if (result1 == "pass")
                    {
                        result1 = "Succeeded";
                    }
                    else if (result1 == "fail")
                    {
                        result1 = "Failed";
                    }
                    return("Veto Override " + result1);

                case BillStatus.Enacted:
                    details = null;
                    return("Enacted");
                }
                throw new InvalidOperationException();
            } catch (Exception e) {
                details = null;
                return("Unknown");
            }
        }