Example #1
0
		private static async Task<CheckInResult> GetCheckInsDataAsync(CancellationToken token, int locationId = 0, int eventId = 0, string searchTerm = "", double latitude = 0, double longitude = 0, int radius = 0, string workingOn = "", int page = 0, int itemsPerPage = 0, bool allDay = false)
		{
			var checkInResult = new CheckInResult();
			var checkins = new ObservableCollection<CheckIn>();

			var authenticatedProfile = await Common.StorageService.RetrieveObjectAsync<Profile>("Profile");

			using (var httpClient = new HttpClient())
			{
				var apiKey = Common.StorageService.LoadSetting("ApiKey");
				var apiUrl = Common.StorageService.LoadSetting("ApiUrl");

				httpClient.DefaultRequestHeaders.Add("Accept-Encoding", "gzip");
				httpClient.DefaultRequestHeaders.Add("token", apiKey);
				httpClient.DefaultRequestHeaders.Add("api-version", "2");

				try
				{
					var criteria = new CheckInListCriteria
					{
						DateTimeStamp = Common.DateService.ToJavaScriptMilliseconds(DateTime.Now),
						ItemsPerPage = itemsPerPage,
						Latitude = latitude,
						Longitude = longitude,
						Page = page,
						Radius = radius,
						SearchTerm = searchTerm,
						WorkingOn = workingOn,
						FilterProfileId = authenticatedProfile.Id
					};

					var url = apiUrl + "/api/checkin";
					if (allDay)
					{
						url = url + "/allday";
					}
					if (locationId > 0)
					{
						url = url + "/location/" + locationId;
					}
					if (eventId > 0)
					{
						url = url + "/event/" + eventId;
					}
					if (eventId == 0)
					{
						url = url + "?" + JsonConvert.SerializeObject(criteria);
					}


					var httpResponse = await httpClient.GetAsync(new Uri(url)).AsTask(token);
					string json = await httpResponse.Content.ReadAsStringAsync().AsTask(token);
					json = json.Replace("<br>", Environment.NewLine);
					checkInResult = JsonConvert.DeserializeObject<CheckInResult>(json);
				}
				catch (Exception e) { }
			}

			return checkInResult;
		}
Example #2
0
		public static async Task GetProfileCheckInsAsync(CancellationToken token, ObservableCollection<CheckIn> checkinList)
		{
			var checkInResult = new CheckInResult();
			var checkins = new ObservableCollection<CheckIn>();

			var authenticatedProfile = await Common.StorageService.RetrieveObjectAsync<Profile>("Profile");

			using (var httpClient = new HttpClient())
			{
				var apiKey = Common.StorageService.LoadSetting("ApiKey");
				var apiUrl = Common.StorageService.LoadSetting("ApiUrl");
				var profileToken = Common.StorageService.LoadSetting("ProfileToken");

				httpClient.DefaultRequestHeaders.Add("Accept-Encoding", "gzip");
				httpClient.DefaultRequestHeaders.Add("token", apiKey);
				httpClient.DefaultRequestHeaders.Add("api-version", "2");
				httpClient.DefaultRequestHeaders.Add("profileToken", profileToken);

				try
				{
					var url = apiUrl + "/api/checkin/profile/" + authenticatedProfile.Id;

					var httpResponse = await httpClient.GetAsync(new Uri(url)).AsTask(token);
					string json = await httpResponse.Content.ReadAsStringAsync().AsTask(token);
					json = json.Replace("<br>", Environment.NewLine);
					checkInResult = JsonConvert.DeserializeObject<CheckInResult>(json);
				}
				catch (Exception e) { }
			}

			foreach (var checkin in checkins)
			{
				checkinList.Add(checkin);
			}
		}