public static async System.Threading.Tasks.Task <System.Collections.Generic.List <Models.Expo> > FetchUserExposAsync(Models.User u) { // Create an HTTP web request using the URL: System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(new Uri(url1 + "UserExpos?email=" + u.Email)); request.ContentType = "application/json"; request.Method = "GET"; // Send the request to the server and wait for the response: using (System.Net.WebResponse response = await request.GetResponseAsync()) { // Get a stream representation of the HTTP web response: using (Stream stream = response.GetResponseStream()) { // Use this stream to build a JSON document object: System.Json.JsonValue jsonDoc = await System.Threading.Tasks.Task.Run(() => System.Json.JsonObject.Load(stream)); Console.Out.WriteLine("Response: {0}", jsonDoc.ToString()); // Return the JSON document: System.Collections.Generic.List <Models.Expo> lista = new System.Collections.Generic.List <Models.Expo>(); for (int i = 0; i != jsonDoc.Count; i++) { Models.Expo e = new Models.Expo { Name_Expo = jsonDoc[i]["Name_Expo"], Id = Int32.Parse(jsonDoc[i]["Id"].ToString()), Photo = jsonDoc[i]["Photo"], MapPhoto = jsonDoc[i]["MapPhoto"], Adres = jsonDoc[i]["Adres"], Description = jsonDoc[i]["Description"] }; var start = double.Parse(jsonDoc[i]["ExpoStartData"].ToString().Replace('/', ' ').Replace('"', ' ').Replace(')', ' ').Replace("Date(", "").Trim()); TimeSpan time = TimeSpan.FromMilliseconds(start); DateTime startdate = new DateTime(1970, 1, 1) + time; e.DataTargowStart = startdate; var end = double.Parse(jsonDoc[i]["ExpoEndData"].ToString().Replace('/', ' ').Replace('"', ' ').Replace(')', ' ').Replace("Date(", "").Trim()); TimeSpan time1 = TimeSpan.FromMilliseconds(end); DateTime enddate = new DateTime(1970, 1, 1) + time1; e.DataTargowEnd = enddate; lista.Add(e); } return(lista); } } }
public static async System.Threading.Tasks.Task <Boolean> FetchCompanyJoinExpoAsync(Models.Company us, Models.Expo e) { Uri u = new Uri(url1 + "insertCExpo?Expoid=" + e.Id + "&Companyid=" + us.Id); System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(u); request.ContentType = "application/json"; request.Method = "GET"; // Send the request to the server and wait for the response: using (System.Net.WebResponse response = await request.GetResponseAsync()) { // Get a stream representation of the HTTP web response: using (Stream stream = response.GetResponseStream()) { // Use this stream to build a JSON document object: System.Json.JsonValue jsonDoc = await System.Threading.Tasks.Task.Run(() => System.Json.JsonObject.Load(stream)); Console.Out.WriteLine("Response: {0}", jsonDoc.ToString()); if (Boolean.Parse(jsonDoc["JoinedC"].ToString()) == true) { return(true); } else { return(false); } } } return(false); }
private async Task ParseAndReturnAsync() { Models.Expo e = new Models.Expo(); e.Id = this.Intent.GetIntExtra("eid", 0); e.Name_Expo = this.Intent.GetStringExtra("ename"); e.Photo = this.Intent.GetStringExtra("ephoto"); e.MapPhoto = this.Intent.GetStringExtra("emapphoto"); e.Description = this.Intent.GetStringExtra("eopis"); e.DataTargowStart = DateTime.Parse(this.Intent.GetStringExtra("eDS")); e.DataTargowEnd = DateTime.Parse(this.Intent.GetStringExtra("eDE")); e.Adres = this.Intent.GetStringExtra("eadres"); TextView ExpoName = FindViewById <TextView>(Resource.Id.expo_name); ExpoName.Text = e.Name_Expo; TextView ProductsAbout = FindViewById <TextView>(Resource.Id.expo_adres); ProductsAbout.Text = e.Adres; TextView ExpoDescription = FindViewById <TextView>(Resource.Id.expo_description); ExpoDescription.Text = e.Description; TextView ExpoStart = FindViewById <TextView>(Resource.Id.expo_data_start); ExpoStart.Text = e.DataTargowStart.ToString(); TextView ExpoEnd = FindViewById <TextView>(Resource.Id.expo_data_end); ExpoEnd.Text = e.DataTargowEnd.ToString(); ImageView ExpoPhoto = FindViewById <ImageView>(Resource.Id.expo_image); ExpoPhoto.SetImageBitmap(DbConnection.GetImageBitmapFromUrl(this, "http://expotest.somee.com/Images/Expo/" + e.Photo)); Button btn = FindViewById <Button>(Resource.Id.expo_join); btn.Click += async delegate { LDbConnection.InsertUExpo(e); if (LDbConnection.getUserType() == "Uczestnik") { if (await DbConnection.FetchUserJoinExpoAsync(LDbConnection.GetUser(), e)) { Toast.MakeText(this, "Dołączono", ToastLength.Short).Show(); } else { Toast.MakeText(this, "Brak połączenia", ToastLength.Short).Show(); } } else if (LDbConnection.getUserType() == "Wystawca") { if (await DbConnection.FetchCompanyJoinExpoAsync(LDbConnection.GetCompany(), e)) { Toast.MakeText(this, "Dołączono", ToastLength.Short).Show(); } else { Toast.MakeText(this, "Brak połączenia", ToastLength.Short).Show(); } } }; Button btn1 = FindViewById <Button>(Resource.Id.ExpoMap); btn1.Click += async delegate { var NxtAct = new Intent(this, typeof(MapActivity)); NxtAct.PutExtra("mapphoto", e.MapPhoto); StartActivity(NxtAct); }; }