Ejemplo n.º 1
0
        public async void OnDeleteItemClick(object sender, RoutedEventArgs e)
        {
            if (Selected != null)
            {
                var dialog = new Windows.UI.Popups.MessageDialog(
                    "Voulez vous supprimer la promotion ?",
                    "Attention"
                    );
                dialog.Commands.Add(new Windows.UI.Popups.UICommand("Oui")
                {
                    Id = 0
                });
                dialog.Commands.Add(new Windows.UI.Popups.UICommand("Non")
                {
                    Id = 1
                });

                dialog.DefaultCommandIndex = 0;
                dialog.CancelCommandIndex  = 1;

                var result = await dialog.ShowAsync();

                if ((int)result.Id == 0)
                {
                    try
                    {
                        if (await _api.DeleteDealWithRetryAsync(Selected.Id))
                        {
                            DealsItems.Remove(Selected);
                            Selected = DealsItems.FirstOrDefault();
                            OnPropertyChanged(nameof(IsViewState));
                        }
                        else
                        {
                            var unknowErrorDialog = new Windows.UI.Popups.MessageDialog(
                                "Une erreur est survenue",
                                "Erreur");
                            unknowErrorDialog.Commands.Add(new Windows.UI.Popups.UICommand("Ok")
                            {
                                Id = 0
                            });
                            await unknowErrorDialog.ShowAsync();
                        }
                    }
                    catch (Exception ex)
                    {
                        var errorDialog = new Windows.UI.Popups.MessageDialog(
                            ex.Message,
                            "Erreur");
                        errorDialog.Commands.Add(new Windows.UI.Popups.UICommand("Ok")
                        {
                            Id = 0
                        });
                        await errorDialog.ShowAsync();
                    }
                }
            }
        }