예제 #1
0
        private async void AddItem_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            ItemType type = ItemType.ToDo;

            if ((bool)todoTo.IsChecked && !(bool)topack.IsChecked)
            {
                type = ItemType.ToDo;
            }
            else if ((bool)topack.IsChecked && !(bool)todoTo.IsChecked)
            {
                type = ItemType.ToPack;
            }
            else
            {
                ViewModel.ErrorMessage = "Je moet één van de twee opties aanduiden!(to do/ to pack)";
                toevoegenJuist.IsOpen  = false;
                toevoegenFail.IsOpen   = true;
                return;
            }

            string   categ     = (string)categorieënBox.SelectedItem;
            Category catbasic  = ViewModel.Trip.Categories.Find(c => c.Name == categ);
            bool     succesful = false;

            try
            {
                if (categ == null || titel == null)
                {
                    ViewModel.ErrorMessage = "Het toevoegen van de item is niet gelukt! Zijn alle parameters ingevuld?";
                    toevoegenJuist.IsOpen  = false;
                    toevoegenFail.IsOpen   = true;
                }
                else
                {
                    ItemDTO.Create item = new ItemDTO.Create
                    {
                        CategoryId = catbasic.CategoryId,
                        Name       = titel.Text,
                        ItemType   = (int)type
                    };

                    succesful = await ViewModel.AddItemAsync(item, tripId);
                }
            }
            catch
            {
                ViewModel.ErrorMessage = "Het toevoegen van de item is niet gelukt! Zijn alle parameters ingevuld?";
                toevoegenJuist.IsOpen  = false;
                toevoegenFail.IsOpen   = true;
            }
            if (succesful)
            {
                ViewModel.GetTripAsync(tripId);
                ViewModel.ErrorMessage = $"{titel.Text} werd succesvol toegevoegd!";
                toevoegenFail.IsOpen   = false;
                toevoegenJuist.IsOpen  = true;
                titel.Text             = "";
            }
        }
        /// <summary>
        /// makes a new item in the database for a trip and a person
        /// </summary>
        /// <param name="item">the itemdto we wisht to create and save </param>
        /// <param name="tripId">the tripid where we add the item</param>
        /// <returns>the response message (including the statuscode)</returns>
        public static async Task <HttpResponseMessage> AddItemAsync(ItemDTO.Create item, int tripId)
        {
            var Json = JsonConvert.SerializeObject(item);

            var data = new StringContent(Json, Encoding.UTF8, _appJson);

            try
            {
                return(await _client.PostAsync(new Uri(UrlUtil.ProjectURL + $"trip/{tripId}/item"), data));
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
예제 #3
0
        public async Task <bool> AddItemAsync(ItemDTO.Create item, int tripId)
        {
            HttpResponseMessage response;

            //https://localhost:5001/trip/${tripId}/item
            response = await ItemController.AddItemAsync(item, tripId);

            if (response.IsSuccessStatusCode)
            {
                GotDataNotSuccesfull = false;
                return(true);
            }
            else
            {
                GotDataNotSuccesfull = true;
                return(false);
            }
        }