|
@@ -13,6 +13,7 @@ |
13 |
13 |
|
using Windows.Devices.Geolocation; |
14 |
14 |
|
using Windows.Storage; |
15 |
15 |
|
using System.Diagnostics; |
|
16 |
+ |
using Windows.Foundation; |
16 |
17 |
|
|
17 |
18 |
|
namespace SmartCharging.Net |
18 |
19 |
|
{ |
|
@@ -129,12 +130,46 @@ |
129 |
130 |
|
|
130 |
131 |
|
} |
131 |
132 |
|
|
|
133 |
+ |
public async Task<User> FacebookLogin(string fbUserId, string fbToken) |
|
134 |
+ |
{ |
|
135 |
+ |
string url = await this.GetBaseUrl(); |
|
136 |
+ |
|
|
137 |
+ |
var obj = new { fb_user = fbUserId, fb_token = fbToken }; |
|
138 |
+ |
|
|
139 |
+ |
url += "/login_facebook.php"; |
|
140 |
+ |
await this.Logout(); |
|
141 |
+ |
string responseString = await this.net.PostRequest(new Uri(url), this.CreateRequestPostData(obj)); |
|
142 |
+ |
|
|
143 |
+ |
|
|
144 |
+ |
|
|
145 |
+ |
if (responseString != null && !responseString.Equals("")) |
|
146 |
+ |
{ |
|
147 |
+ |
JObject parsed = this.tryParseJson(responseString); |
|
148 |
+ |
//login ok |
|
149 |
+ |
if (parsed != null && !String.IsNullOrEmpty( (string)parsed["email"] )) |
|
150 |
+ |
{ |
|
151 |
+ |
this.token = ((string)parsed["token"]); |
|
152 |
+ |
this.user = new User(((string)parsed["id"]), USER_TYPE.Standard); |
|
153 |
+ |
} |
|
154 |
+ |
else |
|
155 |
+ |
{ |
|
156 |
+ |
await errorHandler.showErrorMessage("FacebookLogin", ""); |
|
157 |
+ |
} |
|
158 |
+ |
} |
|
159 |
+ |
else |
|
160 |
+ |
{ |
|
161 |
+ |
await errorHandler.showErrorMessage(); |
|
162 |
+ |
} |
|
163 |
+ |
return this.user; |
|
164 |
+ |
|
|
165 |
+ |
} |
132 |
166 |
|
|
133 |
167 |
|
public async Task<bool> Logout() |
134 |
168 |
|
{ |
135 |
169 |
|
|
136 |
170 |
|
if (this.user == null) |
137 |
171 |
|
{ |
|
172 |
+ |
Debug.WriteLine("SmartChargeAPI | Logout | user not logged"); |
138 |
173 |
|
return false; |
139 |
174 |
|
} |
140 |
175 |
|
|
|
@@ -202,6 +237,7 @@ |
202 |
237 |
|
|
203 |
238 |
|
if (this.user == null) |
204 |
239 |
|
{ |
|
240 |
+ |
Debug.WriteLine("SmartChargeAPI | DeleteUserAccount | user not logged"); |
205 |
241 |
|
return false; |
206 |
242 |
|
} |
207 |
243 |
|
|
|
@@ -345,6 +381,7 @@ |
345 |
381 |
|
{ |
346 |
382 |
|
if (this.user == null) |
347 |
383 |
|
{ |
|
384 |
+ |
Debug.WriteLine("SmartChargeAPI | GetUserSites | user not logged"); |
348 |
385 |
|
return null; |
349 |
386 |
|
} |
350 |
387 |
|
|
|
@@ -474,7 +511,9 @@ |
474 |
511 |
|
{ |
475 |
512 |
|
this.addSiteDetailsFromJson(site, parsed); |
476 |
513 |
|
site.SiteImageUrls = await this.GetSiteImages(site); |
477 |
|
- |
site.IconImageUrl = await this.GetUserAvatar(site.OwnerId); |
|
514 |
+ |
|
|
515 |
+ |
site.IconImageUrl = site.SiteImageUrls.Count > 0 ? site.SiteImageUrls[0] : "ms-appx:///Assets/avatar_placeholder.png"; |
|
516 |
+ |
|
478 |
517 |
|
} |
479 |
518 |
|
else |
480 |
519 |
|
{ |
|
@@ -624,31 +663,41 @@ |
624 |
663 |
|
public async Task<bool> AddSiteImages(Site site, List<StorageFile> images) |
625 |
664 |
|
{ |
626 |
665 |
|
|
|
666 |
+ |
if (this.user == null) |
|
667 |
+ |
{ |
|
668 |
+ |
Debug.WriteLine("SmartChargeAPI | AddSiteImages | user not logged"); |
|
669 |
+ |
return false; |
|
670 |
+ |
} |
|
671 |
+ |
|
627 |
672 |
|
string url = await this.GetBaseUrl(); |
628 |
673 |
|
|
629 |
674 |
|
//upload each image |
630 |
675 |
|
List<string> uploadedImages = await this.UploadImages(images); |
631 |
676 |
|
|
632 |
|
- |
var obj = new { id = site.Id, type = "local", imgs = uploadedImages }; |
633 |
|
- |
|
634 |
|
- |
url += "/add_immagini.php"; |
635 |
|
- |
string responseString = await this.net.PostRequest(new Uri(url), this.CreateRequestPostData(obj)); |
636 |
|
- |
if (responseString != null && !responseString.Equals("")) |
|
677 |
+ |
if (uploadedImages.Count > 0) |
637 |
678 |
|
{ |
638 |
|
- |
JObject parsed = this.tryParseJson(responseString); |
639 |
|
- |
if (parsed != null && ((string)parsed["return"]).Equals("0")) |
|
679 |
+ |
var obj = new { id = site.Id, type = "local", imgs = uploadedImages, token = this.token }; |
|
680 |
+ |
|
|
681 |
+ |
url += "/add_immagini.php"; |
|
682 |
+ |
string responseString = await this.net.PostRequest(new Uri(url), this.CreateRequestPostData(obj)); |
|
683 |
+ |
if (responseString != null && !responseString.Equals("")) |
640 |
684 |
|
{ |
|
685 |
+ |
JObject parsed = this.tryParseJson(responseString); |
|
686 |
+ |
if (parsed != null && ((string)parsed["return"]).Equals("0")) |
|
687 |
+ |
{ |
641 |
688 |
|
|
642 |
|
- |
return true; |
|
689 |
+ |
return true; |
|
690 |
+ |
} |
|
691 |
+ |
else |
|
692 |
+ |
{ |
|
693 |
+ |
await errorHandler.showErrorMessage("UploadSiteImages", ((string)parsed["return"])); |
|
694 |
+ |
} |
643 |
695 |
|
} |
644 |
696 |
|
else |
645 |
697 |
|
{ |
646 |
|
- |
await errorHandler.showErrorMessage("UploadSiteImages", ((string)parsed["return"])); |
|
698 |
+ |
await errorHandler.showErrorMessage(); |
647 |
699 |
|
} |
648 |
|
- |
} |
649 |
|
- |
else |
650 |
|
- |
{ |
651 |
|
- |
await errorHandler.showErrorMessage(); |
|
700 |
+ |
|
652 |
701 |
|
} |
653 |
702 |
|
|
654 |
703 |
|
return false; |
|
@@ -721,7 +770,8 @@ |
721 |
770 |
|
|
722 |
771 |
|
|
723 |
772 |
|
var obj = new |
724 |
|
- |
{ |
|
773 |
+ |
{ |
|
774 |
+ |
local_id = site.Id, |
725 |
775 |
|
user_id = this.user.Id, |
726 |
776 |
|
nomelocale = site.Name, |
727 |
777 |
|
descrizione = site.Description, |
|
@@ -744,12 +794,11 @@ |
744 |
794 |
|
//add site ok |
745 |
795 |
|
if (parsed != null && ((string)parsed["return"]).Equals("0")) |
746 |
796 |
|
{ |
747 |
|
- |
site.Id = ((string)parsed["local_id"]); |
748 |
797 |
|
return true; |
749 |
798 |
|
} |
750 |
799 |
|
else |
751 |
800 |
|
{ |
752 |
|
- |
await errorHandler.showErrorMessage("AddSite", ((string)parsed["return"])); |
|
801 |
+ |
await errorHandler.showErrorMessage("EditSite", ((string)parsed["return"])); |
753 |
802 |
|
} |
754 |
803 |
|
} |
755 |
804 |
|
else |
|
@@ -796,6 +845,7 @@ |
796 |
845 |
|
{ |
797 |
846 |
|
if (this.user == null) |
798 |
847 |
|
{ |
|
848 |
+ |
Debug.WriteLine("SmartChargeAPI | UploadAvatar | user not logged"); |
799 |
849 |
|
return null; |
800 |
850 |
|
} |
801 |
851 |
|
string url = await this.GetBaseUrl(); |
|
@@ -923,6 +973,7 @@ |
923 |
973 |
|
Latitude = (double)siteJson["lat"], |
924 |
974 |
|
Longitude = (double)siteJson["lon"] |
925 |
975 |
|
}); |
|
976 |
+ |
s.NormalizedPoint = new Point(0.5,1); |
926 |
977 |
|
SiteType st = (await this.getSiteTypesList()).Find(t => t.Id == (string)siteJson["tipologia"]); |
927 |
978 |
|
if (st != null) |
928 |
979 |
|
{ |
|
@@ -934,10 +985,12 @@ |
934 |
985 |
|
s.Email = (string)siteJson["email"]; |
935 |
986 |
|
s.WebSite = (string)siteJson["sito"]; |
936 |
987 |
|
s.Chargers = (int)siteJson["n_punti_ricarica"]; |
|
988 |
+ |
s.Description = siteJson["descrizione"] != null ? (string)siteJson["descrizione"] : ""; |
937 |
989 |
|
return s; |
938 |
990 |
|
} |
939 |
991 |
|
catch (Exception e) |
940 |
992 |
|
{ |
|
993 |
+ |
Debug.WriteLine("Exception in SmartChargeAPI | CreateSiteFromJson"); |
941 |
994 |
|
Debug.WriteLine(e.Message); |
942 |
995 |
|
return null; |
943 |
996 |
|
} |
|
@@ -968,12 +1021,13 @@ |
968 |
1021 |
|
r.ReviewerName = (string)reviewJson["username"]; |
969 |
1022 |
|
r.Rating = (double)reviewJson["voto"]; |
970 |
1023 |
|
r.Description = (string)reviewJson["descrizione"]; |
971 |
|
- |
r.Date = (DateTime)reviewJson["data"]; |
|
1024 |
+ |
r.Date = (System.DateTime)reviewJson["data"]; |
972 |
1025 |
|
|
973 |
1026 |
|
return r; |
974 |
1027 |
|
} |
975 |
1028 |
|
catch (Exception e) |
976 |
1029 |
|
{ |
|
1030 |
+ |
Debug.WriteLine("Exception in SmartChargeAPI | CreateReviewFromJson"); |
977 |
1031 |
|
Debug.WriteLine(e.Message); |
978 |
1032 |
|
return null; |
979 |
1033 |
|
} |
|
@@ -988,6 +1042,7 @@ |
988 |
1042 |
|
ret = JObject.Parse(toBeParsed); |
989 |
1043 |
|
} |
990 |
1044 |
|
catch (Exception e){ |
|
1045 |
+ |
Debug.WriteLine("Exception in SmartChargeAPI | tryParseJson"); |
991 |
1046 |
|
Debug.WriteLine(e.Message); |
992 |
1047 |
|
} |
993 |
1048 |
|
|