/// <summary> /// Get the referendum from the database /// </summary> /// <returns>Returns the referendum data</returns> internal ReferendumTable GetReferendum() { ReferendumTable referendum = new ReferendumTable(); referendum = this.db.Query <ReferendumTable>("SELECT * FROM ReferendumTable")[0]; return(referendum); }
/// <summary> /// Updates the referendum in the database /// </summary> /// <param name="referendum">Model containing the referendum data to be updated</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> internal Task UpdateReferendum(ReferendumTable referendum) { this.db.DropTable <ReferendumTable>(); this.db.CreateTable <ReferendumTable>(); this.db.Insert(referendum); return(Task.FromResult(-1)); }
/// <summary> /// Updates the Voting Data in the local database from the server database /// </summary> /// <returns>A bool weather the local database was updated</returns> private async Task <bool> UpdateVoteData() { List <ElectorateTable> electorates = new List <ElectorateTable>(); List <CandidateTable> candidates = new List <CandidateTable>(); List <PartyTable> parties = new List <PartyTable>(); ReferendumTable referendum = new ReferendumTable(); electorates = await this.restAPI.GetElectorates(); candidates = await this.restAPI.GetCandidates(); parties = await this.restAPI.GetParties(); referendum = await this.restAPI.GetReferendum(); if (electorates != null || candidates != null || parties != null || referendum != null) { await this.db.UpdateElectorates(electorates); await this.db.UpdateCandidates(candidates); await this.db.UpdateParties(parties); await this.db.UpdateReferendum(referendum); return(true); } else { if (this.db.CheckData()) { return(true); } else { return(false); } } }
/// <summary> /// Initializes a new instance of the <see cref="ReferendumView"/> class. /// </summary> public ReferendumView() { this.InitializeComponent(); this.referendumVM = new ReferendumViewModel(new NavigationService()); this.DataContext = this.referendumVM; ReferendumTable referendum = this.referendumVM.Referendum; var details = JsonConvert.DeserializeObject <List <string> >(referendum.Detail); var images = JsonConvert.DeserializeObject <List <string> >(referendum.Images); Grid grid = new Grid(); grid.ColumnDefinitions.Insert(0, new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); grid.ColumnDefinitions.Insert(0, new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); if (details.Count > images.Count) { for (int i = 0; i < details.Count; i++) { grid.RowDefinitions.Insert(i, new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) }); if (i == 0) { TextBlock newText = new TextBlock() { Text = details[i], VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Stretch, TextWrapping = TextWrapping.Wrap, Margin = new Thickness(5) }; Grid.SetColumn(newText, 0); Grid.SetColumnSpan(newText, 2); Grid.SetRow(newText, i); grid.Children.Add(newText); } else { TextBlock newText = new TextBlock() { Text = details[i], VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, TextWrapping = TextWrapping.Wrap, Margin = new Thickness(20) }; if ((i - 1) < images.Count) { Image newImage = new Image() { Source = new BitmapImage(new Uri(this.BaseUri, images[i - 1])), VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, Margin = new Thickness(5), MaxHeight = 250, MaxWidth = 250 }; if (i % 2 == 0) { Grid.SetColumn(newText, 0); Grid.SetColumn(newImage, 1); } else { Grid.SetColumn(newText, 1); Grid.SetColumn(newImage, 0); } Grid.SetRow(newText, i); Grid.SetRow(newImage, i); grid.Children.Add(newText); grid.Children.Add(newImage); } else { Grid.SetColumn(newText, 0); Grid.SetColumnSpan(newText, 2); Grid.SetRow(newText, i); grid.Children.Add(newText); } } } } this.scrollView.Content = grid; }