示例#1
0
        public async void PostRating()
        {
            ////////////////////////////////////////////////////////////////////////////////////////////////////  to check if already rated
            CheckExisting.Clear();
            CheckExisting.Clear();
            HttpClient         client  = new HttpClient();
            HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, "https://api.parse.com/1/classes/EmployeeRating?" + WebUtility.UrlEncode("where=" + JsonConvert.SerializeObject(new DataParserForEmployees()
            {
                Name = TheNameToComment, Username = usernameToComment
            })));

            message.Headers.Clear();
            message.Headers.Add("X-Parse-Application-Id", "2kWwje4PWZ980GmHQBk4EneY7DkENmlikDEZdwKt");
            message.Headers.Add("X-Parse-REST-API-Key", "3cZnB4kNlPYCChLXEp90tjuBbioTBcycnkMtV9qC");

            try
            {
                HttpResponseMessage response = await client.SendAsync(message);

                string content = await response.Content.ReadAsStringAsync();

                DataToListForEmployeesForRating2 a = JsonConvert.DeserializeObject <DataToListForEmployeesForRating2>(content);
                foreach (var item in a.GetStringList())
                {
                    CheckExisting.Add(item);
                }

                if (CheckExisting.Count == 0)
                {
////////////////////////////////////////////////////////////////////////////////////////////////////  to post new rating
                    HttpClient         client2  = new HttpClient();
                    HttpRequestMessage message2 = new HttpRequestMessage(HttpMethod.Post, "https://api.parse.com/1/classes/EmployeeRating");
                    message2.Headers.Clear();
                    message2.Headers.Add("X-Parse-Application-Id", "2kWwje4PWZ980GmHQBk4EneY7DkENmlikDEZdwKt");
                    message2.Headers.Add("X-Parse-REST-API-Key", "3cZnB4kNlPYCChLXEp90tjuBbioTBcycnkMtV9qC");
                    string json = JsonConvert.SerializeObject(new DataParserForUserRating()
                    {
                        Name = TheNameToComment, Username = usernameToComment, Rating = Rating.SelectedIndex + 1
                    });
                    message2.Content = new StringContent(json, Encoding.UTF8, "application/json");
                    message2.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                    HttpResponseMessage response2 = await client2.SendAsync(message2);
                    await DisplayAlert("Success", " * Your evaluation has been posted", "ok");
                }
                else
                {
                    ////////////////////////////////////////////////////////////////////////////////////////////////////  to modify current rating
                    HttpClient         client1  = new HttpClient();
                    HttpRequestMessage message1 = new HttpRequestMessage(HttpMethod.Put, "https://api.parse.com/1/classes/EmployeeRating/" + CheckExisting[0]);
                    message1.Headers.Clear();
                    message1.Headers.Add("X-Parse-Application-Id", "2kWwje4PWZ980GmHQBk4EneY7DkENmlikDEZdwKt");
                    message1.Headers.Add("X-Parse-REST-API-Key", "3cZnB4kNlPYCChLXEp90tjuBbioTBcycnkMtV9qC");
                    string json2 = JsonConvert.SerializeObject(new DataParserForUserRating()
                    {
                        Rating = Rating.SelectedIndex + 1
                    });
                    message1.Content = new StringContent(json2, Encoding.UTF8, "application/json");
                    message1.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                    HttpResponseMessage response1 = await client1.SendAsync(message1);

                    await DisplayAlert("Success", " * Your original post has been modified", "ok");
                }
            }
            catch (Exception e1)
            {
            }
        }
示例#2
0
        async void SubmitComment(object sender, EventArgs args)
        {
            Cover.IsVisible = true;

            if (Comment.Text.Length <= 50)
            {
                if (Comment.Text.Length >= 1)
                {
                    ////////////////////////////////////////////////////////////////////////////////////////////////////  to check if already commented

                    CheckExisting.Clear();
                    HttpClient         client  = new HttpClient();
                    HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, "https://api.parse.com/1/classes/EmployeeRating?" + WebUtility.UrlEncode("where=" + JsonConvert.SerializeObject(new DataParserForEmployees()
                    {
                        Name = TheNameToComment, Username = usernameToComment
                    })));
                    message.Headers.Clear();
                    message.Headers.Add("X-Parse-Application-Id", "2kWwje4PWZ980GmHQBk4EneY7DkENmlikDEZdwKt");
                    message.Headers.Add("X-Parse-REST-API-Key", "3cZnB4kNlPYCChLXEp90tjuBbioTBcycnkMtV9qC");

                    try
                    {
                        HttpResponseMessage response = await client.SendAsync(message);

                        string content = await response.Content.ReadAsStringAsync();

                        DataToListForEmployeesForRating2 a = JsonConvert.DeserializeObject <DataToListForEmployeesForRating2>(content);
                        foreach (var item in a.GetStringList())
                        {
                            CheckExisting.Add(item);
                        }

                        if (CheckExisting.Count == 0)
                        {
                            ////////////////////////////////////////////////////////////////////////////////////////////////////  to post new rating
                            HttpClient         client2  = new HttpClient();
                            HttpRequestMessage message2 = new HttpRequestMessage(HttpMethod.Post, "https://api.parse.com/1/classes/EmployeeRating");
                            message2.Headers.Clear();
                            message2.Headers.Add("X-Parse-Application-Id", "2kWwje4PWZ980GmHQBk4EneY7DkENmlikDEZdwKt");
                            message2.Headers.Add("X-Parse-REST-API-Key", "3cZnB4kNlPYCChLXEp90tjuBbioTBcycnkMtV9qC");
                            string json = JsonConvert.SerializeObject(new DataParserForUserRating()
                            {
                                Name = TheNameToComment, Username = usernameToComment, Comments = Comment.Text
                            });
                            message2.Content = new StringContent(json, Encoding.UTF8, "application/json");
                            message2.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                            HttpResponseMessage response2 = await client2.SendAsync(message2);
                            await DisplayAlert("Success", " * Your comment has been posted", "ok");

                            Cover.IsVisible = false;
                        }
                        else
                        {
                            ////////////////////////////////////////////////////////////////////////////////////////////////////  to modify current rating
                            HttpClient         client1  = new HttpClient();
                            HttpRequestMessage message1 = new HttpRequestMessage(HttpMethod.Put, "https://api.parse.com/1/classes/EmployeeRating/" + CheckExisting[0]);
                            message1.Headers.Clear();
                            message1.Headers.Add("X-Parse-Application-Id", "2kWwje4PWZ980GmHQBk4EneY7DkENmlikDEZdwKt");
                            message1.Headers.Add("X-Parse-REST-API-Key", "3cZnB4kNlPYCChLXEp90tjuBbioTBcycnkMtV9qC");
                            string json2 = JsonConvert.SerializeObject(new DataParserForUserRating()
                            {
                                Comments = Comment.Text
                            });
                            message1.Content = new StringContent(json2, Encoding.UTF8, "application/json");
                            message1.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                            HttpResponseMessage response1 = await client1.SendAsync(message1);

                            await DisplayAlert("Success", " * Your original post has been modified", "ok");

                            Cover.IsVisible = false;
                        }
                    }
                    catch (Exception e1)
                    {
                    }
                }
                else
                {
                    await DisplayAlert("Empty comment", "you have not written anything", "ok");
                }
            }
            else
            {
                await DisplayAlert("Too long !", " Your Comment must be equal or less than 50 characters", "ok");
            }
        }