|
@@ -122,42 +122,64 @@ |
122 |
122 |
|
|
123 |
123 |
|
private async void SubmitButton_Tapped(object sender, TappedRoutedEventArgs e) |
124 |
124 |
|
{ |
125 |
|
- |
bool isValid = ValidateFields(); |
126 |
|
- |
if (isValid) |
127 |
|
- |
{ //register user |
128 |
|
- |
User newUser = new User() |
129 |
|
- |
{ |
130 |
|
- |
Name = this.UsernameInput.Text, |
131 |
|
- |
Surname = this.SurnameInput.Text, |
132 |
|
- |
Email = this.EmailInput.Text, |
133 |
|
- |
CellphoneNumber = this.PhoneNumberInput.Text, |
134 |
|
- |
UserType = this.UserTypeToggleSwitch.IsOn ? USER_TYPE.Owner : USER_TYPE.Standard |
135 |
|
- |
}; |
136 |
|
- |
this.showLoading(); |
137 |
|
- |
bool registrationResult = await this.SMA.RegisterUser(newUser, this.AvatarPicker.storageFile, this.UsernameInput.Text, this.PasswordInput.Password); |
138 |
|
- |
|
139 |
|
- |
if (this.UserTypeToggleSwitch.IsOn) |
140 |
|
- |
{ |
141 |
|
- |
//register site |
142 |
|
- |
if (SiteImagePicker.images.Count > 0) |
|
125 |
+ |
try |
|
126 |
+ |
{ |
|
127 |
+ |
bool isValid = ValidateFields(); |
|
128 |
+ |
if (isValid) |
|
129 |
+ |
{ //register user |
|
130 |
+ |
User newUser = new User() |
143 |
131 |
|
{ |
144 |
|
- |
|
145 |
|
- |
// bool uploadResult = await this.SMA.UploadSiteImages(s, this.SiteImagePicker.images.ToList()); |
146 |
|
- |
|
|
132 |
+ |
Name = this.UsernameInput.Text, |
|
133 |
+ |
Surname = this.SurnameInput.Text, |
|
134 |
+ |
Email = this.EmailInput.Text, |
|
135 |
+ |
CellphoneNumber = this.PhoneNumberInput.Text, |
|
136 |
+ |
UserType = this.UserTypeToggleSwitch.IsOn ? USER_TYPE.Owner : USER_TYPE.Standard |
|
137 |
+ |
}; |
|
138 |
+ |
this.showLoading(); |
|
139 |
+ |
bool registrationResult = await this.SMA.RegisterUser(newUser, this.AvatarPicker.storageFile, this.UsernameInput.Text, this.PasswordInput.Password); |
|
140 |
+ |
|
|
141 |
+ |
if (registrationResult && this.UserTypeToggleSwitch.IsOn) |
|
142 |
+ |
{//register site |
|
143 |
+ |
|
|
144 |
+ |
|
|
145 |
+ |
Site newSite = new Site() |
|
146 |
+ |
{ |
|
147 |
+ |
Name = this.SiteNameInput.Text, |
|
148 |
+ |
Description = this.SiteDescriptionInput.Text, |
|
149 |
+ |
Type = this.selectedSiteType, |
|
150 |
+ |
Position = this.SitePositionSelector.siteLocation.Point, |
|
151 |
+ |
Address = this.SitePositionSelector.addressString, |
|
152 |
+ |
PhoneNumber = this.PhoneNumberInput.Text, |
|
153 |
+ |
Email = this.EmailInput.Text, |
|
154 |
+ |
WebSite = this.SiteWebsiteTextBox.Text, |
|
155 |
+ |
Chargers = System.Text.RegularExpressions.Regex.IsMatch(this.NumberOfChargersTextBox.Text, "[^0-9]") ? int.Parse(this.NumberOfChargersTextBox.Text) : 0 |
|
156 |
+ |
|
|
157 |
+ |
}; |
|
158 |
+ |
|
|
159 |
+ |
bool siteAdditionResult = await this.SMA.AddSite(newSite, this.SiteImagePicker.images.ToList()); |
|
160 |
+ |
if (siteAdditionResult) |
|
161 |
+ |
{ |
|
162 |
+ |
this.goToUserPage(); |
|
163 |
+ |
} |
|
164 |
+ |
|
|
165 |
+ |
} |
|
166 |
+ |
else if (registrationResult) |
|
167 |
+ |
{ |
|
168 |
+ |
this.goToUserPage(); |
147 |
169 |
|
} |
148 |
170 |
|
|
|
171 |
+ |
this.hideLoading(); |
149 |
172 |
|
} |
150 |
|
- |
else |
151 |
|
- |
{ |
152 |
|
- |
this.goToUserPage(); |
153 |
|
- |
} |
154 |
|
- |
|
|
173 |
+ |
} |
|
174 |
+ |
catch (Exception ex){ |
155 |
175 |
|
this.hideLoading(); |
|
176 |
+ |
string s = ex.Message; |
156 |
177 |
|
} |
157 |
178 |
|
|
158 |
179 |
|
|
159 |
180 |
|
|
160 |
181 |
|
|
|
182 |
+ |
|
161 |
183 |
|
} |
162 |
184 |
|
|
163 |
185 |
|
private bool ValidateFields() |
|
@@ -169,13 +191,16 @@ |
169 |
191 |
|
this.EmailInput.BorderBrush = this.EmailInput.Text == "" || !this.IsValidEmailAddress(this.EmailInput.Text) ? red : white; |
170 |
192 |
|
this.PasswordInput.BorderBrush = this.PasswordInput.Password == "" ? red : white; |
171 |
193 |
|
|
|
194 |
+ |
|
172 |
195 |
|
bool userOk = !this.UsernameInput.BorderBrush.Equals(red) && !this.PasswordInput.BorderBrush.Equals(red) && !this.EmailInput.BorderBrush.Equals(red); |
173 |
196 |
|
bool ownerOK = false; |
174 |
197 |
|
if (this.UserTypeToggleSwitch.IsOn) |
175 |
198 |
|
{ |
176 |
199 |
|
this.SiteNameInput.BorderBrush = this.SiteNameInput.Text == "" ? red : white; |
177 |
200 |
|
this.SiteTypeButton.BorderBrush = selectedSiteType == null ? red : white; |
178 |
|
- |
ownerOK = !this.SiteNameInput.BorderBrush.Equals(red) && !this.SiteTypeButton.BorderBrush.Equals(red); |
|
201 |
+ |
this.SitePositionSelectorBorder.BorderBrush = this.SitePositionSelector.townLocation == null ? red : white; |
|
202 |
+ |
this.NumberOfChargersTextBox.BorderBrush = !this.NumberOfChargersTextBox.Text.Equals("") && System.Text.RegularExpressions.Regex.IsMatch(this.NumberOfChargersTextBox.Text, "[^0-9]") ? red : white; |
|
203 |
+ |
ownerOK = !this.SiteNameInput.BorderBrush.Equals(red) && !this.SiteTypeButton.BorderBrush.Equals(red) && !this.SitePositionSelectorBorder.BorderBrush.Equals(red); |
179 |
204 |
|
} |
180 |
205 |
|
|
181 |
206 |
|
|
|
@@ -230,5 +255,6 @@ |
230 |
255 |
|
} |
231 |
256 |
|
} |
232 |
257 |
|
|
|
258 |
+ |
|
233 |
259 |
|
} |
234 |
260 |
|
} |