Esempio n. 1
0
		public static async Task<JsonResponse> RegisterAsync(string name, string email, string password, string studentnumber)
		{
			using (var client = new RestClient(new Uri(URL)))
			{
				try
				{
					var request = new RestRequest("register.php", Method.POST);
					request.AddBody(new { name, email, password, studentnumber });
					var result = await client.Execute(request);

					var data = Encoding.UTF8.GetString(result.RawBytes, 0, result.RawBytes.Length);
					return JsonConvert.DeserializeObject<JsonResponse>(data);
				}
				catch (Exception)
				{
					return new JsonResponse { success = 0, message = "Unknown error" };
				}
			}
		}
Esempio n. 2
0
		public static async Task<IList<AssistanceViewModel>> GetAssistance(string email)
		{
			using (var client = new RestClient(new Uri(URL)))
			{
				try
				{
					var request = new RestRequest("getAssistance.php", Method.POST);
					request.AddBody(new { email });
					var result = await client.Execute(request);

					var data = Encoding.UTF8.GetString(result.RawBytes, 0, result.RawBytes.Length);
					var response = JsonConvert.DeserializeAnonymousType(data, new { assistance = default(List<AssistanceViewModel>) });
					return response.assistance;
				}
				catch (Exception)
				{
					return new List<AssistanceViewModel>();
				}
			}
		}
Esempio n. 3
0
        private async Task CallMethodAsync(string method, string customerId, HttpMethod httpMethod, object data)
        {
            var request = new RestRequest(method)
            {
                Method = httpMethod,
                Serializer = new SerializerWrapper(this._jsonSerializer)
            };
            
            if (customerId != null)
            {
                request.AddUrlSegment(@"customer_id", customerId);
            }
            request.AddBody(data);

            var response = await this._client.Execute(request).ConfigureAwait(false);
            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new CustomerIoApiException(response.StatusCode);
            }
        }
Esempio n. 4
0
		public static async Task<JsonResponse> MarkAssistance(string email)
		{
			var day = DateTime.Now.Day;
			using (var client = new RestClient(new Uri(URL)))
			{
				try
				{
					var request = new RestRequest("updateAssistance.php", Method.POST);
					request.AddBody(new { email, day });
					var result = await client.Execute(request);

					var data = Encoding.UTF8.GetString(result.RawBytes, 0, result.RawBytes.Length);
					data = data.Substring(data.IndexOf("]}", StringComparison.Ordinal) + 2);
					var response = JsonConvert.DeserializeAnonymousType(data, new { assistance = default(List<AssistanceViewModel>) });
					return JsonConvert.DeserializeObject<JsonResponse>(data);
				}
				catch (Exception)
				{
					return new JsonResponse { success = 0, message = "Unknown error" };
				}
			}
		}
Esempio n. 5
0
		public static async Task<IDictionary<string, IList<TrainingPlanViewModel>>> GetTrainingPlans(string email)
		{
			using (var client = new RestClient(new Uri(URL)))
			{
				try
				{
					var request = new RestRequest("getPlan.php", Method.POST);
					request.AddBody(new { email });
					var result = await client.Execute(request);

					var data = Encoding.UTF8.GetString(result.RawBytes, 0, result.RawBytes.Length);
					return JsonConvert.DeserializeObject<IDictionary<string, IList<TrainingPlanViewModel>>>(data);
				}
				catch (Exception)
				{
					return new Dictionary<string, IList<TrainingPlanViewModel>>();
				}
			}
		}
        /// <summary>
        /// Toggles the like of the current post on the api.
        /// </summary>
        public async Task LikePostAsync(Post post)
        {
            var like = new Like
            {
                PostId = post.Id,
                UserIdentifier = DeviceUtils.DeviceId
            };

            using (var client = new RestClient("http://localhost:55298/api/"))
            {
                var request = new RestRequest("likes", Method.POST);
                request.AddBody(like);

                var result = await client.Execute(request);

                if (result.StatusCode == System.Net.HttpStatusCode.Created)
                {
                    post.Likes++;
                }
                else
                {
                    post.Likes--;
                }
            }
        }