private async void RegionEntered(object sender, MonitoredRegionEventArgs e) { using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(url); HttpResponseMessage response = await client.GetAsync($"{client.BaseAddress}Home/GetEvents/"); string result = await response.Content.ReadAsStringAsync(); string subString = "<!--"; int indexOfSubstring = result.IndexOf(subString); string[] words = result.Split(new char[] { '<', '!', '-' }); string events = ""; foreach (string existEvent in words) { events += existEvent; } if (events != String.Empty) { var eventsFromJson = JsonConvert.DeserializeObject <List <MyEvent> >(events); foreach (MyEvent existEvent in eventsFromJson) { if (eventsFromJson.Any(x => x.Beacon.UUID.Replace("-", "") == e.Region.UUID.Replace("-", "")) && existEvent.Beacon.UUID.Replace("-", "") == e.Region.UUID.Replace("-", "")) { currentUser.Event = existEvent; Device.BeginInvokeOnMainThread(() => eventInfo.Text = "Event name:\n\t" + currentUser.Event.Name + "\nDescription:\n\t" + currentUser.Event.Description); eventInfo.Text = "Event name:\n\t" + currentUser.Event.Name + "\nDescription:\n\t" + currentUser.Event.Description; string jsonStr = JsonConvert.SerializeObject(currentUser); Dictionary <string, string> dict = new Dictionary <string, string>() { { "str", jsonStr } }; FormUrlEncodedContent form = new FormUrlEncodedContent(dict); response = await client.PostAsync($"{client.BaseAddress}Home/AddToEvent/", form); } } } } }
private async void RegionLeft(object sender, MonitoredRegionEventArgs e) { using (HttpClient client = new HttpClient()) { Device.BeginInvokeOnMainThread(() => eventInfo.Text = ""); client.BaseAddress = new Uri(url); //var response = client.GetAsync(client.BaseAddress); string jsonString = JsonConvert.SerializeObject(currentUser); Dictionary <string, string> data = new Dictionary <string, string> { { "str", jsonString } }; FormUrlEncodedContent content = new FormUrlEncodedContent(data); HttpResponseMessage response = await client.PostAsync($"{client.BaseAddress}Home/RemoveFromEvent/", content); } }