@page "/quotes"
Quotes
@* @if (isloading) {
Loading…
} *@ @using Microsoft.JSInterop @inject IJSRuntime JSRuntime @inject NavigationManager Navigation; @using SeaHavenIndustries.Data.IRepository; @inject IQuotesRepository _services; @using System.Text.Json @using SeaHavenIndustries.Data.Services @using SeaHavenIndustries.Helper.ViewModels @using global::Data.SeaHavenIndustries; @inject NorthwindService service @using System.Linq.Dynamic.Core @inject ChangeStepService StepService @inject PdfService pdfService @code { [Parameter] public int? id { get; set; } private int step = 0; RadzenDataGrid grid; int count; int eid; private bool ispdf = false; IEnumerable model; bool isLoading = false; bool isloading = false; protected void Edit(int id) { Navigation.NavigateTo("createquotes/" + id); } protected void view(int id) { Navigation.NavigateTo("quotesdetails/" + id); } private async Task SelectAllQuotes() { await JSRuntime.InvokeVoidAsync("selectAllQuotes"); } private async Task DeleteSweetAlert(int val) { var result = await JSRuntime.InvokeAsync("Swal.fire", new { html = "
" + "

Are you sure you want to delete

" + "

\"Nicolas Alvarado\"

", type = "warning", showCancelButton = true, customClass = new { confirmButton = "btn btn-success m-1", cancelButton = "btn btn-danger m-1" }, buttonsStyling = false, confirmButtonText = "Yes", cancelButtonText = "No" }); if (result.TryGetProperty("isConfirmed", out var isConfirmedProperty) && isConfirmedProperty.GetBoolean()) { // Call your delete API here var response = await _services.DeleteQuotes(val); if (response == "success") { await JSRuntime.InvokeVoidAsync("Swal.fire", new { icon = "success", title = "Deleted!", text = "Data has been deleted.", type = "primary", showCancelButton = false, customClass = new { confirmButton = "btn btn-success", cancelButton = "btn btn-danger" }, buttonsStyling = false, confirmButtonText = "Ok" }); model = await _services.GetQuotesqueryable(); // await JSRuntime.InvokeVoidAsync("location.reload"); } else { await JSRuntime.InvokeVoidAsync("Swal.fire", new { title = "Not Deleted!", text = "Unsuccessful! Cannot delete this.", type = "danger" }); } } } async Task LoadData(LoadDataArgs args) { isLoading = true; await Task.Yield(); // This demo is using https://dynamic-linq.net var query = await _services.GetQuotesqueryable(); if (!string.IsNullOrEmpty(args.Filter)) { // Filter via the Where method query = query.Where(args.Filter); } if (!string.IsNullOrEmpty(args.OrderBy)) { // Sort via the OrderBy method query = query.OrderBy(args.OrderBy); } // Important!!! Make sure the Count property of RadzenDataGrid is set. count = query.Count(); // Perform paging via Skip and Take. model = query.Skip(args.Skip.Value).Take(args.Top.Value).ToList(); isLoading = false; ispdf = true; } public void Export(string type) { service.Export("Quotes", type, new Query() { OrderBy = grid.Query.OrderBy, Filter = grid.Query.Filter, Select = string.Join(",", grid.ColumnsCollection.Where(c => c.GetVisible() && !string.IsNullOrEmpty(c.Property)) .Select(c => c.Property.Contains(".") ? $"{c.Property} as {c.Property.Replace(".", "_")}" : c.Property)) }); } private async Task GeneratePdf(int qid) { eid = qid; ispdf = true; isloading = true; await Task.Delay(TimeSpan.FromSeconds(4)); var htmlContent = await JSRuntime.InvokeAsync("getHtmlContent", StepService.htmlContentReference); var pdfBytes = await pdfService.GeneratePdf(htmlContent); ispdf = false; isloading = false; var pdfBase64 = Convert.ToBase64String(pdfBytes); await JSRuntime.InvokeVoidAsync("downloadFile", pdfBase64, "Quote.pdf"); } private async Task SendPdf(int qid) { eid = qid; ispdf = true; isloading = true; await Task.Delay(TimeSpan.FromSeconds(4)); var htmlContent = await JSRuntime.InvokeAsync("getHtmlContent", StepService.htmlContentReference); var pdfBytes = await pdfService.GeneratePdf(htmlContent); var result = await _services.SendEmailQuote(pdfBytes, qid); isloading = false; if (result == "success") { await ShowSweetAlert("Email send successfully", "success"); } else { await ShowSweetAlert(result, "error"); } ispdf = false; } private async Task ShowSweetAlert(string title, string icon) { // Display a SweetAlert dialog await JSRuntime.InvokeVoidAsync("Swal.fire", new { toast = true, showConfirmButton = false, timer = 3000, title = title, icon = icon, position = "top-end" }); await JSRuntime.InvokeVoidAsync("closemodal"); } }