/// <summary> /// Initializes a new instance of the <see cref="VoteSubmittedViewModel"/> class. /// </summary> /// <param name="navigationService">Passes the Navigation Property from the View to the ViewModel</param> /// <param name="user">Receives the user data from the view</param> public VoteSubmittedViewModel(INavigationService navigationService, UserVoteTable user) { this.navigation = navigationService; this.user = user; this.resource = new ResourceLoader(); this.Title = this.resource.GetString("SubmittedTitle"); this.VoteText = this.resource.GetString("VoteText"); this.ElectorateText = this.resource.GetString("ElectorateText"); this.CandidateText = this.resource.GetString("CandidateText"); this.PartyText = this.resource.GetString("PartyText"); this.ReferendumText = this.resource.GetString("ReferendumText"); this.SubmittedText = this.resource.GetString("SubmittedText"); this.LoginButton = this.resource.GetString("VoteButton"); this.ConnectionText = this.resource.GetString("ConnectionText"); this.LoginCommand = new CommandService(this.Login); ElectorateTable electorateData = new ElectorateTable(); List <CandidateTable> candidateData = new List <CandidateTable>(); PartyTable partyData = new PartyTable(); List <string> candidateList = JsonConvert.DeserializeObject <List <string> >(this.user.CandidateIds); electorateData = this.db.GetElectorateFromId(this.user.ElectorateId); foreach (string item in candidateList) { int id = int.Parse(item); CandidateTable candidate = new CandidateTable(); candidate = this.db.GetCandidateFromId(id); candidateData.Add(candidate); } partyData = this.db.GetPartyFromId(this.user.PartyId); this.Electorate = electorateData.Name; string candidateNames = string.Empty; foreach (CandidateTable item in candidateData) { if (candidateNames == string.Empty) { candidateNames = item.Name; } else { candidateNames = string.Join(Environment.NewLine, candidateNames, item.Name); } } this.Candidates = candidateNames; this.Party = partyData.Name; this.Referendum = this.user.Referendum.ToString(); }
/// <summary> /// Saves the electorate chosen to the user /// </summary> /// <param name="sender">Model containing the electorate vote result</param> /// <returns>Returns a -1 for a fail result and a 1 for a success result</returns> internal int AddElectorateVote(ElectorateTable sender) { List <UserVoteTable> users = new List <UserVoteTable>(); users = this.db.Query <UserVoteTable>("SELECT * FROM UserVoteTable WHERE Active = 1"); if (users.Count != 1) { return(-1); } UserVoteTable user = new UserVoteTable(); user = users[0]; user.ElectorateId = sender.Id; this.db.Update(user); return(1); }