Subversion Repository Public Repository

Nextrek

Diff Revisions 659 vs 660 for /Android/SmartCharging/SmartCharging_WP/SmartCharging/NewReviewPage.xaml.cs

Diff revisions: vs.
  @@ -1,13 +1,17 @@
1 1 using SmartCharging.Common;
2 2 using SmartCharging.DataModel;
3 + using SmartCharging.Net;
3 4 using System;
4 5 using System.Collections.Generic;
5 6 using System.IO;
6 7 using System.Linq;
7 8 using System.Runtime.InteropServices.WindowsRuntime;
9 + using Windows.ApplicationModel.Resources;
8 10 using Windows.Foundation;
9 11 using Windows.Foundation.Collections;
10 12 using Windows.Graphics.Display;
13 + using Windows.UI;
14 + using Windows.UI.Popups;
11 15 using Windows.UI.ViewManagement;
12 16 using Windows.UI.Xaml;
13 17 using Windows.UI.Xaml.Controls;
  @@ -28,6 +32,9 @@
28 32 {
29 33 private NavigationHelper navigationHelper;
30 34 private ObservableDictionary defaultViewModel = new ObservableDictionary();
35 + private SmartChargeAPI SMA;
36 + private ErrorHandler errorHandler;
37 + private ResourceLoader resourceLoader;
31 38
32 39 public NewReviewPage()
33 40 {
  @@ -36,6 +43,9 @@
36 43 this.navigationHelper = new NavigationHelper(this);
37 44 this.navigationHelper.LoadState += this.NavigationHelper_LoadState;
38 45 this.navigationHelper.SaveState += this.NavigationHelper_SaveState;
46 + this.SMA = SmartChargeAPI.Instance;
47 + this.errorHandler = new ErrorHandler();
48 + this.resourceLoader = ResourceLoader.GetForCurrentView("Resources");
39 49 }
40 50
41 51 /// <summary>
  @@ -109,5 +119,56 @@
109 119 }
110 120
111 121 #endregion
122 +
123 + private async void SubmitReviewButton_Tapped(object sender, TappedRoutedEventArgs e)
124 + {
125 + if (this.ValidateFields())
126 + {
127 + Site s = LayoutRoot.DataContext as Site;
128 + Review newReview = new Review() { Description = this.ReviewDescriptionTextBox.Text, Rating = this.RatingControl.Value, Date = DateTime.Now };
129 + this.showLoading();
130 + bool result = await this.SMA.AddSiteComment(s, newReview);
131 + this.hideLoading();
132 + if (result)
133 + {
134 + MessageDialog dialogbox = new MessageDialog(resourceLoader.GetString("ReviewSent"));
135 +
136 +
137 + //OK Button
138 + UICommand okBtn = new UICommand(resourceLoader.GetString("OK"));
139 + okBtn.Invoked = (arg) =>
140 + {
141 + Frame.GoBack();
142 + };
143 + dialogbox.Commands.Add(okBtn);
144 +
145 +
146 + //Show message
147 + await dialogbox.ShowAsync();
148 + }
149 +
150 + }
151 + }
152 +
153 + private bool ValidateFields()
154 + {
155 + SolidColorBrush red = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
156 + SolidColorBrush white = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255));
157 +
158 + this.ReviewDescriptionTextBox.BorderBrush = this.ReviewDescriptionTextBox.Text == "" ? red : white;
159 +
160 +
161 + return !this.ReviewDescriptionTextBox.BorderBrush.Equals(red);
162 + }
163 +
164 + private void showLoading()
165 + {
166 + this.Loader.Visibility = Visibility.Visible;
167 + }
168 +
169 + private void hideLoading()
170 + {
171 + this.Loader.Visibility = Visibility.Collapsed;
172 + }
112 173 }
113 174 }