private async void AddCategory_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) { if (categoryName.Text.Length == 0) { ViewModel.ErrorMessage = "Categorie naam moet ingevuld zijn"; toevoegenJuist.IsOpen = false; toevoegenFail.IsOpen = true; } else { CategoryDTO.Create category = new CategoryDTO.Create { Name = categoryName.Text }; bool succesful = await ViewModel.AddCategoryAsync(category); if (succesful) { ViewModel.GetTripAsync(tripId); ViewModel.ErrorMessage = $"Categorie {category.Name} werd succesvol toegevoegd aan de Trip!"; toevoegenFail.IsOpen = false; toevoegenJuist.IsOpen = true; titel.Text = ""; } else { ViewModel.ErrorMessage = "Er is iets misgelopen!"; toevoegenJuist.IsOpen = false; toevoegenFail.IsOpen = true; } } }
/// <summary> /// adds and creates a catergory in the database /// </summary> /// <param name="category">the categorydto we wish to create</param> /// <param name="tripId">the tripid where we add the category </param> /// <returns>the response message (including the statuscode)</returns> public static async Task <HttpResponseMessage> AddCategoryAsync(CategoryDTO.Create category, int tripId) { var Json = JsonConvert.SerializeObject(category); var data = new StringContent(Json, Encoding.UTF8, _appJson); try { return(await _client.PostAsync(new Uri(UrlUtil.ProjectURL + $"trip/{tripId}/category"), data)); } catch (Exception e) { throw new Exception(e.Message); } }
public async Task <bool> AddCategoryAsync(CategoryDTO.Create item) { HttpResponseMessage response; //https://localhost:5001/trip/${Trip.tripId}/category response = await ItemController.AddCategoryAsync(item, Trip.TripId); if (response.IsSuccessStatusCode) { return(true); } else { return(false); } }