public async Task DeleteDeck(string UID, string name) { bool isConfirmed = await JSRuntime.InvokeAsync <bool>("Confirm", "Are you sure you want to delete \"" + name + "\"?"); if (isConfirmed) { int index = -1; for (int i = 0; i < Decks.Count; i++) { if (Decks[i].UID == UID) { index = i; break; } } if (index >= 0) { ResponseCore Response = await JSRuntime.InvokeAsync <ResponseCore>("DeleteDeck", Decks[index].UID); if (Response.Success) { await JSRuntime.InvokeVoidAsync("Alert", "success", "Deck Deleted", name + " has been deleted."); Decks = await JSRuntime.InvokeAsync <List <Deck> >("Select", "decks"); StateHasChanged(); } else { await JSRuntime.InvokeVoidAsync("Alert", "error", "Error", Response.Error); } } } }
protected override async Task OnInitializedAsync() { ResponseCore UserVerificationResponse = await JSRuntime.InvokeAsync <ResponseCore>("VerifyUser"); if (!UserVerificationResponse.Success) { switch (UserVerificationResponse.StatusCode) { case 503: NavigationManager.NavigateTo("/maintenance"); return; case 502: NavigationManager.NavigateTo("/network-offline"); break; default: ViewIsReady = true; return; } } else { NavigationManager.NavigateTo("/dashboard"); } }
public async Task <bool> ManageResponseAsync(ResponseCore response, Page page, bool showUnknownError = true, bool showServerTranslatedError = true, bool handleUnauthorizedError = true) { bool sucesso = true; if (response == null || response.HTTPStatusCode == null) { await page.Alerta("Ocorreu um erro. Por favor tente novamente.", "Atenção!"); sucesso = false; } else if (!response.HTTPStatusCode.Equals(HttpStatusCode.OK)) { if (response.HTTPStatusCode.Equals(MHttpStatusCode.NO_INTERNET_CONNECTION)) { await page.Alerta("Por favor, confira a sua conexão com a internet.", "Atenção!"); sucesso = false; } else if (response.HTTPStatusCode.Equals(MHttpStatusCode.SERVER_OFFLINE)) { await page.Alerta($"Servidor está indisponível.\nPor favor tente novamente.", "Atenção!"); sucesso = false; } else if (response.HTTPStatusCode.Equals(MHttpStatusCode.TIMEOUT)) { await page.Alerta($"Por favor, tente novamente.", "Tempo expirado!"); sucesso = false; } else if (handleUnauthorizedError && response.HTTPStatusCode.Equals(HttpStatusCode.Unauthorized)) { //MotoristaController motoristaController = new MotoristaController(); //if (!await motoristaController.AtualizarToken()) //{ //await page.Alerta("Por favor, realize o login novamente.", "Atenção!"); sucesso = false; //Configuracao.SessionActive = false; Application.Current.MainPage = new NavigationPage(new Views.Login.LoginPage(true)); //} } else if (showServerTranslatedError && !string.IsNullOrEmpty(response.Error?.Message)) { await page.Alerta(response.Error?.Message, "Atenção!"); sucesso = false; } else if (showUnknownError) { await page.Alerta("Ocorreu um erro. Por favor tente novamente.", "Atenção!"); sucesso = false; } } return(await Task.FromResult(sucesso)); }
public async Task ToggleMaintenanceMode() { string ticket = await JSRuntime.InvokeAsync <string>("StartLoading"); IsUndergoingMaintenance ^= true; ResponseCore Response = await JSRuntime.InvokeAsync <ResponseCore>("SetMaintenanceMode", IsUndergoingMaintenance); if (Response.Success) { if (IsUndergoingMaintenance) { await JSRuntime.InvokeVoidAsync("Alert", "success", "Success", "The API is now in maintenance mode."); } else { await JSRuntime.InvokeVoidAsync("Alert", "success", "Success", "The API is no longer in maintenance mode."); } NavigationManager.NavigateTo(NavigationManager.Uri, true); } else { await JSRuntime.InvokeVoidAsync("Alert", "error", "Error", Response.Error); } await JSRuntime.InvokeAsync <ResponseCore>("StopLoading", ticket); }
protected override async Task OnInitializedAsync() { ResponseCore AdminVerificationResponse = await JSRuntime.InvokeAsync <ResponseCore>("VerifyAdmin"); if (!AdminVerificationResponse.Success) { NavigationManager.NavigateTo("/"); return; } await Main(); }
public async Task OnAvatarUpload(InputFileChangeEventArgs e) { ResponseCore Response = await JSRuntime.InvokeAsync <ResponseCore>("UpdateProfileAvatar"); if (Response.Success) { await JSRuntime.InvokeVoidAsync("Alert", "success", "Profile Updated", "Your profile picture has been updated."); await RefreshProfile(); } else { await JSRuntime.InvokeVoidAsync("Alert", "error", "Error", Response.Error); } StateHasChanged(); }
public async Task SendActivationEmail(User user) { string ticket = await JSRuntime.InvokeAsync <string>("StartLoading"); ResponseCore Response = await JSRuntime.InvokeAsync <ResponseCore>("SendActivationEmail", user.Uid); if (Response.Success) { await JSRuntime.InvokeVoidAsync("Alert", "success", "Success", "An account activation email has been sent to " + user.Email); } else { await JSRuntime.InvokeVoidAsync("Alert", "error", "Error", Response.Error); } await JSRuntime.InvokeAsync <ResponseCore>("StopLoading", ticket); }
public async Task PurgeImageTransforms() { string ticket = await JSRuntime.InvokeAsync <string>("StartLoading"); ResponseCore Response = await JSRuntime.InvokeAsync <ResponseCore>("PurgeImageTransforms"); if (Response.Success) { await JSRuntime.InvokeVoidAsync("Alert", "success", "Success", "Image transforms have been purged."); } else { await JSRuntime.InvokeVoidAsync("Alert", "error", "Error", Response.Error); } await JSRuntime.InvokeAsync <ResponseCore>("StopLoading", ticket); }
public async Task ClearNDJSONCache() { string ticket = await JSRuntime.InvokeAsync <string>("StartLoading"); ResponseCore Response = await JSRuntime.InvokeAsync <ResponseCore>("ClearNDJSONCache"); if (Response.Success) { await JSRuntime.InvokeVoidAsync("Alert", "success", "Success", "The NDJSON cache has been cleared."); } else { await JSRuntime.InvokeVoidAsync("Alert", "error", "Error", Response.Error); } await JSRuntime.InvokeAsync <ResponseCore>("StopLoading", ticket); }
public async Task ResendVerificationEmail() { IsSending = true; StateHasChanged(); ResponseCore Response = await JSRuntime.InvokeAsync <ResponseCore>("ResendVerificationEmail"); IsSending = false; StateHasChanged(); if (Response.Success) { await JSRuntime.InvokeVoidAsync("Alert", "success", "Success", "The verification email has been resent."); } else { await JSRuntime.InvokeVoidAsync("Alert", "error", "Error", "Failed to resend the verification email."); } }
public async Task <ResponseBase> Remove(Guid id) { var response = new ResponseCore <ProdutoModel>(); try { await _produtoRepository.Remove(id); response.OperationResult.Status = StatusOperation.OKRESULT; } catch (Exception ex) { response.OperationResult.Status = StatusOperation.ERRORRESULT; response.OperationResult.Message = ex.Message; } return(response); }
public async Task <ResponseCore <ProdutoModel> > GetById(Guid id) { var response = new ResponseCore <ProdutoModel>(); try { Produto produto = await _produtoRepository.GetById(id); response.Data = _mapper.Adapt <Produto, ProdutoModel>(produto); response.OperationResult.Status = StatusOperation.OKRESULT; } catch (Exception ex) { response.OperationResult.Status = StatusOperation.ERRORRESULT; response.OperationResult.Message = ex.Message; } return(response); }
protected IResponseCore GetResponseCoreError(Enum code, string message = null, IResponseCore response = null) { if (response == null) { response = new ResponseCore(); } response.HTTPStatusCode = code; if (!string.IsNullOrWhiteSpace(message)) { response.Error = new ResponseError { Message = message }; } return(response); }
public async Task <ResponseCore <IEnumerable <ProdutoModel> > > Get() { var response = new ResponseCore <IEnumerable <ProdutoModel> >(); try { IEnumerable <Produto> produtos = await _produtoRepository.Get(); response.Data = _mapper.Adapt <IEnumerable <Produto>, IEnumerable <ProdutoModel> >(produtos); response.OperationResult.Status = StatusOperation.OKRESULT; } catch (Exception ex) { response.OperationResult.Status = StatusOperation.ERRORRESULT; response.OperationResult.Message = ex.Message; } return(response); }
public async Task UnsuspendUser(User user) { string ticket = await JSRuntime.InvokeAsync <string>("StartLoading"); ResponseCore Response = await JSRuntime.InvokeAsync <ResponseCore>("UnsuspendUser", user.Uid); if (Response.Success) { user.Suspended = false; StateHasChanged(); await JSRuntime.InvokeVoidAsync("Alert", "success", "Account Updated", user.Name + " has been unsuspended."); } else { await JSRuntime.InvokeVoidAsync("Alert", "error", "Unsuspension Failed", Response.Error); } await JSRuntime.InvokeAsync <ResponseCore>("StopLoading", ticket); }
public async Task ActivateUser(User user) { string ticket = await JSRuntime.InvokeAsync <string>("StartLoading"); ResponseCore Response = await JSRuntime.InvokeAsync <ResponseCore>("ActivateUser", user.Uid); if (Response.Success) { user.Verified = true; StateHasChanged(); await JSRuntime.InvokeVoidAsync("Alert", "success", "Account Updated", user.Name + "'s account has been activated."); } else { await JSRuntime.InvokeVoidAsync("Alert", "error", "Activation Failed", Response.Error); } await JSRuntime.InvokeAsync <ResponseCore>("StopLoading", ticket); }
public async Task GrantAdmin(User user) { string ticket = await JSRuntime.InvokeAsync <string>("StartLoading"); ResponseCore Response = await JSRuntime.InvokeAsync <ResponseCore>("GrantAdmin", user.Uid); if (Response.Success) { user.Admin = true; StateHasChanged(); await JSRuntime.InvokeVoidAsync("Alert", "success", "Success", user.Name + " is now an admin."); } else { await JSRuntime.InvokeVoidAsync("Alert", "error", "Error", Response.Error); } await JSRuntime.InvokeAsync <ResponseCore>("StopLoading", ticket); }
protected override async Task OnInitializedAsync() { ResponseCore UserVerificationResponse = await JSRuntime.InvokeAsync <ResponseCore>("VerifyUser"); if (!UserVerificationResponse.Success) { switch (UserVerificationResponse.StatusCode) { case 503: NavigationManager.NavigateTo("/maintenance"); return; default: NavigationManager.NavigateTo("/"); return; } } await Main(); }
public async Task DeleteAccount() { bool DeleteConfirmed = await JSRuntime.InvokeAsync <bool>("Confirm", "This action cannot be undone and your data will be permanently deleted. Continue with account deletion?"); if (DeleteConfirmed) { ProfileForm.Submit(); StateHasChanged(); ResponseCore Response = await JSRuntime.InvokeAsync <ResponseCore>("DeleteAccount"); if (Response.Success) { ProfileForm.Succeed(); await JSRuntime.InvokeVoidAsync("Alert", "success", "Account Deleted", "Your account has been successfully deleted."); NavigationManager.NavigateTo("/"); } else { ProfileForm.Fail(Response.Error); await JSRuntime.InvokeVoidAsync("Alert", "error", "Error", Response.Error); } } }
protected override async Task OnInitializedAsync() { ResponseCore Response = await JSRuntime.InvokeAsync <ResponseCore>("Impersonate", Token); NavigationManager.NavigateTo("/"); }