@using Front.Services @using Shared.DTOs @inject HttpClientController hc;
@* alert *@
@if (Cus.ID != 0) {
نکته:
}
@if (Cus.ID == 0 || !_UsedInTheInvoice) { } else { }
@if (Cus.ID == 0) { } else { @if (_UsedInTheInvoice) { } }
@code { public bool SpinnerVisible { get; set; } = false; // alert AlertColor alertColor = AlertColor.Primary; IconName alertIconName = IconName.CheckCircleFill; bool Hidealert = true; bool _UsedInTheInvoice = false; string alertMessage = ""; [Parameter] public RCustomer Cus { get; set; } public int? ItemSearchCustomertype { get; set; } [Parameter] public EventCallback OnMultipleOfThree { get; set; } private ConfirmDialog dialog = default!; public ActionInResultComponent result { get; set; } protected override async Task OnParametersSetAsync() { if (Cus.CustomerType != null) ItemSearchCustomertype = (int)Cus.CustomerType; result = new ActionInResultComponent() { Status = ComponentStatus.fild }; Hidealert = true; alertMessage = ""; await UsedInTheInvoice(); SpinnerVisible = false; await base.OnParametersSetAsync(); } } @functions { private void ShowSuccessAlert(string msg) { Hidealert = false; alertColor = AlertColor.Success; alertIconName = IconName.CheckCircleFill; alertMessage = msg; } private void ShowDangerAlert(string msg) { Hidealert = false; alertColor = AlertColor.Danger; alertIconName = IconName.ExclamationTriangleFill; alertMessage = msg; } public async Task OnClickGoToInvoice() { hc._nav.NavigateTo($"Invoice/{"cus:"+Cus.ID}"); } public async Task OnClickDelete() { SpinnerVisible = !SpinnerVisible; var rsp = await hc.Delete($"Customer/Delete/{Cus.ID}"); if (rsp.IsSuccessStatusCode) { var request = await rsp.Content.ReadFromJsonAsync(); if (request) { result.Status = ComponentStatus.success; result.Action = ComponentAction.delete; await OnMultipleOfThree.InvokeAsync(result); } else ShowDangerAlert("خطایی در اجرای عملیات رخ داده"); } else if (rsp.StatusCode == System.Net.HttpStatusCode.NotFound) { ShowDangerAlert("مشتری با این شناسه یافت نشد"); } else ShowDangerAlert("خطایی در اجرای عملیات رخ داده"); SpinnerVisible = !SpinnerVisible; } public async Task OnClickUpdate() { SpinnerVisible = !SpinnerVisible; if (ItemSearchCustomertype > 0 && !string.IsNullOrEmpty(Cus.FullName)) { if (ItemSearchCustomertype > 0) Cus.CustomerType = (CustomerType)ItemSearchCustomertype; var rsp = await hc.Put("Customer/Update", Cus); if (rsp.IsSuccessStatusCode) { var request = await rsp.Content.ReadFromJsonAsync(); if (request) { result.Status = ComponentStatus.success; result.Action = ComponentAction.update; await OnMultipleOfThree.InvokeAsync(result); } else ShowDangerAlert("خطایی در اجرای عملیات رخ داده"); } else { var request = await rsp.Content.ReadFromJsonAsync>(); ShowDangerAlert(request[0]); } } else ShowDangerAlert("فیلدهای قرمز باید مقدار دهی شوند"); SpinnerVisible = !SpinnerVisible; } public async Task OnClickCheckEconomicCode() { SpinnerVisible = !SpinnerVisible; if (!string.IsNullOrEmpty(Cus.EconomicCode)) { var rsp = await hc.Get($"TaxPayer/EconomicCodeInformation?item={Cus.EconomicCode}"); if (rsp.IsSuccessStatusCode) { var request = await rsp.Content.ReadFromJsonAsync(); // dialog.ShowAsync( // title: $"کد اقتصادی به نام {request.NameTrade}", // message1: $"وضعیت {request.TaxpayerStatus}"); } else if(rsp.StatusCode==System.Net.HttpStatusCode.NotFound) { ShowDangerAlert("یافت نشد"); } else { ShowDangerAlert("خطایی در اجرای عملیات رخ داده"); } } else ShowDangerAlert("کد اقعصادی را مشخص کنید"); SpinnerVisible = !SpinnerVisible; } public async Task OnClickAdd() { SpinnerVisible = !SpinnerVisible; if (ItemSearchCustomertype > 0 && !string.IsNullOrEmpty(Cus.FullName)) { if (ItemSearchCustomertype > 0) Cus.CustomerType = (CustomerType)ItemSearchCustomertype; Cus.ID = null; var rsp = await hc.Post("Customer/Add", Cus); if (rsp.IsSuccessStatusCode) { var request = await rsp.Content.ReadFromJsonAsync(); if (request) { result.Status = ComponentStatus.success; result.Action = ComponentAction.add; await OnMultipleOfThree.InvokeAsync(result); } else ShowDangerAlert("خطایی در اجرای عملیات رخ داده"); } else { var request = await rsp.Content.ReadFromJsonAsync>(); ShowDangerAlert(request[0]); } } else ShowDangerAlert("فیلدهای قرمز باید مقدار دهی شوند"); SpinnerVisible = !SpinnerVisible; } public async Task UsedInTheInvoice() { SpinnerVisible = !SpinnerVisible; if (Cus.ID!=0) { var rsp = await hc.Get($"Customer/UsedInTheInvoice/{Cus.ID}"); if (rsp.IsSuccessStatusCode) _UsedInTheInvoice = await rsp.Content.ReadFromJsonAsync(); else _UsedInTheInvoice = false; } SpinnerVisible = !SpinnerVisible; } private async Task ShowConfirmationDeleteAsync() { if (Cus.ID.HasValue && Cus.ID.Value > 0) { var confirmation = await dialog.ShowAsync( title: "عملیات حذف مشتری", message1: $"از حذف مشتری {Cus.FullName}", message2: "اطمینان دارید?"); if (confirmation) await OnClickDelete(); } } }