Example #1
0
        public static async Task <bool> DeleteInteractionNotes(InteractionLog il)
        {
            try
            {
                using (HttpClient httpClient = new HttpClient())
                {
                    httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", AuthorizationHeader);

                    var url = new Uri(BuildURI("interact/" + il.RemoteIdentifier));

                    var response = await httpClient.DeleteAsync(url).ConfigureAwait(false);

                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        var c = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                        GenericResponse r = JsonConvert.DeserializeObject <GenericResponse>(c);

                        return(r.success);
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("Code: " + response.StatusCode);
                    }
                }
            }
            catch
            {
            }

            return(false);
        }
        public PastInteractionPage(InteractionLog log)
        {
            InitializeComponent();

            Log = log;

            BindingContext = log;
        }
        private async void SaveInteraction()
        {
            if (SelectedTeamMember == null)
            {
                await DisplayAlert("Missing Fields!", "You must select a team member!", "OK");

                return;
            }

            if (Rating == 0)
            {
                await DisplayAlert("Missing Fields!", "A rating is required.", "OK");

                return;
            }

            var date = DateTimeOffset.UtcNow;

            date.AddSeconds(ElapsedTime * -1);

            InteractionLog il = new InteractionLog
            {
                Member      = SelectedTeamMember,
                ElapsedTime = ElapsedTime,
                Rating      = Rating,
                Note        = NotesEditor.Text,
                Date        = date,
                Shared      = LocalSettings.AutomaticallyShareNotes
            };

            var identifier = await QuantiServer.PublishInteractionResult(il).ConfigureAwait(true);

            if (identifier == null)
            {
                await DisplayAlert("Error!", "Unable to contact the QuantiDev server. This interaction will only be saved locally.", "OK");

                return;
            }
            else
            {
                il.RemoteIdentifier = identifier;
            }

            LocalRealmInstance.Write(() =>
            {
                LocalRealmInstance.Add(il);

                Navigation.PopAsync();

                System.Diagnostics.Debug.WriteLine("Saved!");
            });
        }
Example #4
0
        public static async Task <string> PublishInteractionResult(InteractionLog log)
        {
            try
            {
                using (HttpClient httpClient = new HttpClient())
                {
                    httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", AuthorizationHeader);

                    var url = new Uri(BuildURI("log"));

                    var content = new FormUrlEncodedContent(new[] {
                        new KeyValuePair <string, string>("class", "interaction"),
                        new KeyValuePair <string, string>("intervenient", log.Member.Identifier),
                        new KeyValuePair <string, string>("rating", "" + log.Rating),
                        new KeyValuePair <string, string>("duration", "" + log.ElapsedTime),
                        new KeyValuePair <string, string>("notes", log.Note),
                        new KeyValuePair <string, string>("shared", "" + (log.Shared ? 1 : 0))
                    });

                    var response = await httpClient.PostAsync(url, content).ConfigureAwait(false);

                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        var c = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                        NewInteractionResponse r = JsonConvert.DeserializeObject <NewInteractionResponse>(c);

                        return(r.identifier);
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("Code: " + response.StatusCode);
                    }
                }
            }
            catch
            {
            }

            return(null);
        }
Example #5
0
        public static async Task <bool> UpdateInteractionPrivacy(InteractionLog il)
        {
            try
            {
                using (HttpClient httpClient = new HttpClient())
                {
                    httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", AuthorizationHeader);

                    var url = new Uri(BuildURI("interact/" + il.RemoteIdentifier));

                    var content = new FormUrlEncodedContent(new[] {
                        new KeyValuePair <string, string>("shared", "" + (il.Shared ? 1 : 0))
                    });

                    var response = await httpClient.PostAsync(url, content).ConfigureAwait(false);

                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        var c = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                        GenericResponse r = JsonConvert.DeserializeObject <GenericResponse>(c);

                        return(r.success);
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("Code: " + response.StatusCode);
                    }
                }
            }
            catch
            {
            }

            return(false);
        }