Exemplo n.º 1
0
        private async void BtnUpdate_OnClick(object sender, RoutedEventArgs e)
        {
            if (!isCreate)
            {
                var stewardessInput = ReadTextBoxesData();
                if (stewardessInput != null && _selectedStewardess != null)
                {
                    try
                    {
                        await Service.Update(stewardessInput, _selectedStewardess.Id);
                    }
                    catch
                    {
                        Info.Text = "Server error!";
                    }

                    var itemIndex = Stewardesses.ToList().FindIndex(x => x.Id == _selectedStewardess.Id);
                    var item      = Stewardesses.ToList().ElementAt(itemIndex);
                    Stewardesses.RemoveAt(itemIndex);
                    item    = stewardessInput;
                    item.Id = _selectedStewardess.Id;
                    Stewardesses.Insert(itemIndex, item);
                    TbId.Text    = "Stewardess Id :" + item.Id;
                    TbFName.Text = "First name : " + item.FirstName;
                    TbLName.Text = "Last name : " + item.LastName;
                    TbBirth.Text = "Birth : " + item.DateOfBirth;
                }
            }
        }
        private async void AddStewardess()
        {
            try
            {
                var result = await _service.AddAsync(SelectedStewardess);

                Stewardesses.Insert(0, result);
            }
            catch (System.InvalidOperationException ex)
            {
                await _dialogService.ShowMessage(ex.Message, "Error");
            }
        }