public static async Task<Response> PostDestination(Destination destination) { try { using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(URL.BASE); var newObject = JsonConvert.SerializeObject(destination); HttpResponseMessage result = await client.PostAsync(URL.DESTINATIONS, new StringContent(newObject, Encoding.UTF8, "application/json")); string json = await result.Content.ReadAsStringAsync(); Response data = JsonConvert.DeserializeObject<Response>(json); return data; } } catch (JsonException jex) { return new Response() { Error = "Parse Error: " + jex.ToString(), Success = false }; } catch (Exception ex) { return new Response() { Error = ex.Message.ToString(), Success = false }; } }
private async Task AddDestination_task() { if (this.NewDestination.Name == null || this.NewDestination.Name == "") { Messenger.Default.Send<Dialog>(new Dialog() { Message = "Geen naam ingevuld", Ok = "Ok", Nok = null, ViewOk = null, ViewNok = null, ParamView = false, Cb = null }); return; } if (this.NewCity == null || this.NewCity.ID == null) { Messenger.Default.Send<Dialog>(new Dialog() { Message = "Geen stad ingevuld", Ok = "Ok", Nok = null, ViewOk = null, ViewNok = null, ParamView = false, Cb = null }); return; } Destination destination = new Destination() { Cities_ID = this.NewCity.ID, Location = this.NewDestination.Location, Name = this.NewDestination.Name }; Response ok = await DestinationRepository.PostDestination(destination); if (ok.Success == true) { Messenger.Default.Send<Dialog>(new Dialog() { Message = "Bestemming toegevoegd", Ok = "Ok", Nok = null, ViewOk = typeof(Bestemmingen), ViewNok = null, ParamView = false, Cb = null }); } }