コード例 #1
0
        public async Task <bool> QuestionAsync(string mensagem)
        {
            var objResult           = false;
            SweetAlertResult result = await Swal.FireAsync(new SweetAlertOptions
            {
                Title             = mensagem,
                Text              = "Verifique os dados corretamente!",
                Icon              = SweetAlertIcon.Question,
                ShowCancelButton  = true,
                ConfirmButtonText = "Confirmar",
                CancelButtonText  = "Cancelar"
            });

            if (!string.IsNullOrEmpty(result.Value))
            {
                objResult = true;
            }
            else if (result.Dismiss == DismissReason.Cancel)
            {
                await Swal.FireAsync(
                    "Cancelada",
                    "Operação CANCELADA pelo USUÁRIO!",
                    SweetAlertIcon.Error
                    );
            }
            return(objResult);
        }
コード例 #2
0
 public void Rollback()
 {
     for (int i = Operations.Count - 1; i >= 0; i--)
     {
         Swal.low(() => Operations[i].Revert());
     }
 }
コード例 #3
0
 void ICleanupUtilities.Cleanup(Guid projectGuid)
 {
     foreach (var directory in Directory.GetDirectories(BaseDirectory,
                                                        "CodeElements.UpdateSystem.Backup*"))
     {
         Swal.low(() => Directory.Delete(directory, true));
     }
 }
コード例 #4
0
        void ICleanupUtilities.NoUpdatesFoundCleanup(Guid projectGuid)
        {
            //cleanup temp directory
            var tempDirectory = new DirectoryInfo(Path.Combine(Path.GetTempPath(), $"CodeElements.UpdateSystem.{projectGuid:D}"));

            if (tempDirectory.Exists)
            {
                Swal.low(() => tempDirectory.Delete(true));
            }
        }
コード例 #5
0
 public async Task InfoAsync(string mensagem)
 {
     var alert = new SweetAlertOptions
     {
         Title             = "Informação",
         Text              = mensagem,
         Icon              = SweetAlertIcon.Success,
         ShowConfirmButton = false,
         Timer             = 1500
     };
     await Swal.FireAsync(alert);
 }
コード例 #6
0
        public async Task UpdateSettingAsync(string settingId)
        {
            await HttpClient.PutAsJsonAsync($"api/settings/{settingId}", Settings[settingId]);

            await Swal.FireAsync(new SweetAlertOptions($"Successfully updated {settingId} to {Settings[settingId].SettingValue}!")
            {
                Position          = SweetAlertPosition.TopEnd,
                Icon              = SweetAlertIcon.Success,
                ShowConfirmButton = false,
                Timer             = 1000
            });
        }
コード例 #7
0
 private async Task ShowDialog()
 {
     await Dialog.Show(new DialogOption()
     {
         Title        = "测试弹窗",
         BodyTemplate = builder =>
         {
             builder.AddContent(0, BootstrapDynamicComponent.CreateComponent <Button>(new Dictionary <string, object?>
             {
                 [nameof(Button.Text)] = "Toast",
                 [nameof(Button.OnClickWithoutRender)] = async() =>
                 {
                     await Toast.Show(new ToastOption()
                     {
                         Title      = "Toast",
                         Content    = "Dialog 中弹窗 Toast 测试成功",
                         IsAutoHide = false
                     });
                 }
             }).Render());
             builder.AddContent(0, BootstrapDynamicComponent.CreateComponent <Button>(new Dictionary <string, object?>
             {
                 ["class"]             = "ms-3",
                 [nameof(Button.Text)] = "Message",
                 [nameof(Button.OnClickWithoutRender)] = async() =>
                 {
                     await Message.Show(new MessageOption()
                     {
                         Content = "Dialog 中弹窗 Message 测试成功"
                     });
                 }
             }).Render());
             builder.AddContent(0, BootstrapDynamicComponent.CreateComponent <Button>(new Dictionary <string, object?>
             {
                 ["class"]             = "ms-3",
                 [nameof(Button.Text)] = "Swal",
                 [nameof(Button.OnClickWithoutRender)] = async() =>
                 {
                     await Swal.Show(new SwalOption()
                     {
                         Category = SwalCategory.Success,
                         Title    = "Sweet Alert",
                         Content  = "Dialog 中弹窗 Swal 测试成功"
                     });
                 }
             }).Render());
         }
     });
 }
コード例 #8
0
        public async Task BuyProductAsync(BuyProductEventArgs args)
        {
            var response = await HttpClient.PostAsync($"api/products/{args.Product.Id}/buy?serverId={args.SelectedServer.Id}", null);

            switch (response.StatusCode)
            {
            case HttpStatusCode.OK:
                await Swal.FireAsync("OK", $"You successfully bought {args.Product.Title} for ${args.Product.Price}!", SweetAlertIcon.Success);

                await BalanceService.UpdateBalanceAsync();

                break;

            case HttpStatusCode.NotFound:
                await Swal.FireAsync("Not Found", "The product you are trying to buy could not be found", SweetAlertIcon.Error);

                break;

            case HttpStatusCode.Gone:
                await Swal.FireAsync("Gone", "The product you are trying to buy is disabled", SweetAlertIcon.Error);

                break;

            case HttpStatusCode.Conflict:
                await Swal.FireAsync("Conflict", "You have already bought maximum amount of this product", SweetAlertIcon.Error);

                break;

            case HttpStatusCode.Unauthorized:
                await Swal.FireAsync("Unauthorized", "You have to sign in to be able to buy", SweetAlertIcon.Error);

                break;

            case HttpStatusCode.ServiceUnavailable:
                await Swal.FireAsync("Service Unavailable", "Failed to communicate with game server, try again later", SweetAlertIcon.Error);

                break;

            case HttpStatusCode.InternalServerError:
                await Swal.FireAsync("Internal Server Error", "Something went wrong, try again later");

                break;
            }

            await PreviewModal.ToggleModalAsync();
        }
コード例 #9
0
 private async Task ConfirmRemoveItemAsync(MarketItem marketItem)
 {
     await Swal.FireAsync(new SweetAlertOptions()
     {
         Title             = "Are you sure?",
         Text              = $"{marketItem.Id} ({marketItem.ItemName}) will be moved to your buyings",
         Icon              = SweetAlertIcon.Warning,
         ShowCancelButton  = true,
         ConfirmButtonText = "Yes, remove it!"
     }).ContinueWith(async(swalTask) =>
     {
         if (Convert.ToBoolean(swalTask.Result.Value))
         {
             await RemoveItemAsync(marketItem);
         }
     });
 }
コード例 #10
0
        protected async Task <bool> MessageBoxModal(string titulo, string conteudo, string icone, string textoConfirma = "Confirma", string textoCancela = "Cancela", bool isConfirmed = true, bool isHtml = false)
        {
            // _ = BlazoredModal.Close().ConfigureAwait(false);

            bool choice  = false;
            var  myicone = (SweetAlertIcon)icone;

            if (!isConfirmed)
            {
                textoConfirma = "Ok";
            }

            await Swal.FireAsync(new SweetAlertOptions
            {
                Title             = titulo,
                Html              = isHtml ? conteudo : null,
                Text              = conteudo,
                AllowEnterKey     = true,
                Icon              = myicone,
                ShowCancelButton  = isConfirmed,
                ConfirmButtonText = textoConfirma,
                CancelButtonText  = textoCancela,
                CancelButtonColor = "error",
                AllowEscapeKey    = true
            }).ContinueWith(swalTask =>
            {
                SweetAlertResult result = swalTask.Result;

                if (result.Dismiss != DismissReason.Cancel)
                {
                    choice = true;
                }
                else if (result.Dismiss == DismissReason.Cancel)
                {
                    Swal.FireAsync(
                        "Oops!!!!!",
                        "Ação Cancelada!",
                        SweetAlertIcon.Error
                        );
                }
            });

            return(choice);
        }
コード例 #11
0
        private async Task RemoveItemAsync(MarketItem marketItem)
        {
            var response = await HttpClient.PutAsync("api/marketitems/" + marketItem.Id, null);

            switch (response.StatusCode)
            {
            case HttpStatusCode.OK:
                marketItem.IsSold   = true;
                marketItem.BuyerId  = PlayersService.CurrentUserInfo.SteamId;
                marketItem.SoldDate = DateTime.UtcNow;
                BuyerData.AddToOrigin(marketItem);
                await Swal.FireAsync("OK", $"Successfully moved {marketItem.Id} ({marketItem.ItemName}) to your buyings!",
                                     SweetAlertIcon.Success);

                break;

            case HttpStatusCode.MethodNotAllowed:
                await Swal.FireAsync("Method Not Allowed", "Taking down items is disabled", SweetAlertIcon.Error);

                break;

            case HttpStatusCode.NotFound:
                await Swal.FireAsync("Not Found", $"Failed to find item {marketItem.Id} ({marketItem.ItemName})",
                                     SweetAlertIcon.Error);

                break;

            case HttpStatusCode.Gone:
                await Swal.FireAsync("Gone", $"Item {marketItem.Id} ({marketItem.ItemName}) is already sold",
                                     SweetAlertIcon.Error);

                break;

            case HttpStatusCode.Forbidden:
                await Swal.FireAsync("Forbidden", $"You are not a seller of this item", SweetAlertIcon.Error);

                break;

            case HttpStatusCode.InternalServerError:
                await Swal.FireAsync("Internal Server Error", $"There was an error, try again later", SweetAlertIcon.Error);

                break;
            }
        }
コード例 #12
0
 // TODO: when upgraded to newest blazor check if this works
 private async Task ConfirmChangeItemPriceAsync(MarketItem marketItem)
 {
     await Swal.FireAsync(new SweetAlertOptions
     {
         Title             = $"Change Price",
         Text              = $"Input new price for listing {marketItem.Id} ({marketItem.ItemName})",
         Icon              = SweetAlertIcon.Warning,
         Input             = SweetAlertInputType.Number,
         ShowCancelButton  = true,
         ConfirmButtonText = "Yes, change price!"
     }).ContinueWith(async(swalTask) =>
     {
         var result = swalTask.Result;
         if (!string.IsNullOrEmpty(result.Value) && decimal.TryParse(result.Value, out decimal newPrice))
         {
             await ChangeItemPriceAsync(marketItem, newPrice);
         }
     });
 }
コード例 #13
0
        /// <summary>
        /// Exibe uma janela modal de confirmação ou informação
        /// </summary>
        /// <param name="titulo">Título da Messagebox</param>
        /// <param name="mensagem">mensagem do corpo da Messagebox</param>
        /// <param name="icone">Ícone utilizar: info,question,error ou warning</param>
        /// <param name="textoConfirma">texto do botão confirma</param>
        /// <param name="textoCancela">texto do botão cancela</param>
        /// <param name="isConfirmed">Se true exibe o botão cancelar</param>
        /// <returns></returns>
        protected async Task <bool> MessageBox(string titulo, string conteudo, string icone, string textoConfirma = "Confirma", string textoCancela = "Cancela", bool isConfirmed = true, bool isHtml = false)
        {
            // async/await

            bool choice  = false;
            var  myicone = (SweetAlertIcon)icone;

            if (!isConfirmed)
            {
                textoConfirma = "Ok";
            }

            var result = await Swal.FireAsync(new SweetAlertOptions
            {
                Title             = titulo,
                Html              = isHtml ? conteudo : null,
                Text              = conteudo,
                AllowEnterKey     = true,
                Icon              = myicone,
                ShowCancelButton  = isConfirmed,
                ConfirmButtonText = textoConfirma,
                CancelButtonText  = textoCancela,
                CancelButtonColor = "error",
                AllowEscapeKey    = true
            });

            if (result.Dismiss == DismissReason.Cancel)
            {
                await Swal.FireAsync(
                    "Oops!",
                    "Ação cancelada.",
                    SweetAlertIcon.Error
                    );
            }
            else
            {
                choice = true;
            }
            return(choice);
        }
コード例 #14
0
        private async Task ChangeItemPriceAsync(MarketItem marketItem, decimal newPrice)
        {
            var msg = new HttpRequestMessage(new HttpMethod("PATCH"), $"api/marketitems/{marketItem.Id}");

            msg.Content = new StringContent(newPrice.ToString());
            var response = await HttpClient.SendAsync(msg);

            switch (response.StatusCode)
            {
            case HttpStatusCode.OK:
                await Swal.FireAsync("OK", $"Successfully changed the price of {marketItem.Id} ({marketItem.ItemName}) " +
                                     $"to {newPrice:C}!", SweetAlertIcon.Success);

                marketItem.Price = newPrice;
                break;

            case HttpStatusCode.NotFound:
                await Swal.FireAsync("Not Found", $"Failed to find item {marketItem.Id} ({marketItem.ItemName})",
                                     SweetAlertIcon.Error);

                break;

            case HttpStatusCode.Gone:
                await Swal.FireAsync("Gone", $"Item {marketItem.Id} ({marketItem.ItemName}) is already sold",
                                     SweetAlertIcon.Error);

                break;

            case HttpStatusCode.Forbidden:
                await Swal.FireAsync("Forbidden", $"You are not a seller of this item", SweetAlertIcon.Error);

                break;

            case HttpStatusCode.InternalServerError:
                await Swal.FireAsync("Internal Server Error", $"There was an error, try again later", SweetAlertIcon.Error);

                break;
            }
        }
コード例 #15
0
        protected async Task <bool> PopUp(string html, string titulo, string textButtonConfirm = "Sim", string textButtonCancel = "Não")
        {
            var result = await Swal.FireAsync(new SweetAlertOptions
            {
                Html              = html,
                Title             = titulo,
                Icon              = SweetAlertIcon.Warning,
                ShowCancelButton  = true,
                ConfirmButtonText = textButtonConfirm,
                CancelButtonText  = textButtonCancel
            }).ConfigureAwait(true);

            if (result.Dismiss == DismissReason.Cancel)
            {
                await Swal.FireAsync(
                    "Cancelado!",
                    "Ação Cancelada!",
                    SweetAlertIcon.Error
                    );
            }

            return(result.IsConfirmed);
        }
コード例 #16
0
 public async Task WarningAsync(string mensagem)
 {
     await Swal.FireAsync("Atenção", mensagem, "warning");
 }
コード例 #17
0
 public async Task ErrorAsync(string mensagem)
 {
     await Swal.FireAsync("Atenção", mensagem, "error");
 }
コード例 #18
0
 private async Task ShowClaimAsync(MarketItem marketItem)
 {
     await Swal.FireAsync("Claim Information", $"To claim {marketItem.Id} ({marketItem.ItemName}) " +
                          $"use in-game: <code>/claim {marketItem.Id}</code>", SweetAlertIcon.Info);
 }