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);
        }
        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
            });
        }
 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);
 }
Exemple #4
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();
        }
 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);
         }
     });
 }
Exemple #6
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);
        }
        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;
            }
        }
 // 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);
         }
     });
 }
Exemple #9
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);
        }
        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;
            }
        }
Exemple #11
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);
        }
 public async Task WarningAsync(string mensagem)
 {
     await Swal.FireAsync("Atenção", mensagem, "warning");
 }
 public async Task ErrorAsync(string mensagem)
 {
     await Swal.FireAsync("Atenção", mensagem, "error");
 }
 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);
 }