@page "/Customer" @using Front.Services @using Shared.DTOs @using Front.CUSComponent @using Shared.DTOs.Serch @inject HttpClientController hc; مشتری @* search *@
@* action *@
@* alert *@
@* data *@ @if (request != null) { @* pagination *@

@request?.RowCount آیتم یافت شد

} @layout PanelLayout @code { [Inject] protected PreloadService PreloadService { get; set; } = default!; public int? ItemSearchCustomertype { get; set; } ItemSerchGetCustomer itemsearch = new ItemSerchGetCustomer(); [Parameter, SupplyParameterFromQuery] public int? PageIndex { get; set; } public Shared.DTOs.PagingDto? request { get; set; } private Modal modal = default!; // alert AlertColor alertColor = AlertColor.Primary; IconName alertIconName = IconName.CheckCircleFill; bool Hidealert = true; string alertMessage = ""; protected override async Task OnParametersSetAsync() { if (PageIndex == null) PageIndex = 1; await LoadCus(PageIndex.Value); 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 LoadCus(int pi) { if (ItemSearchCustomertype > 0) itemsearch.CustomerType = (CustomerType)ItemSearchCustomertype; else itemsearch.CustomerType = null; itemsearch.PageSize = 10; itemsearch.PageIndex = pi; PreloadService.Show(SpinnerColor.Dark); var rsp = await hc.Post("Customer/GetAll", itemsearch); if (rsp.IsSuccessStatusCode) { request = await rsp.Content.ReadFromJsonAsync>(); } else if(rsp.StatusCode==System.Net.HttpStatusCode.Forbidden) { ShowDangerAlert("شما دسترسی به خواندن اطلاعات مشتری را نداربد"); } else { ShowDangerAlert("خطایی در اجرای عملیات رخ داده"); } PreloadService.Hide(); } public async Task CallBackCustomerItem(ActionInResultComponent result) { if (result.Action == ComponentAction.add) { if (result.Status==ComponentStatus.success) ShowSuccessAlert("مشتری جدید با موفقیت اضافه شد"); } else if (result.Action == ComponentAction.update) { if (result.Status == ComponentStatus.success) ShowSuccessAlert("اطلاعات مشتری با موفقیت ویرایش شد"); } else if (result.Action == ComponentAction.delete) { if (result.Status == ComponentStatus.success) ShowSuccessAlert("مشتری با موفقیت حذف شد"); } if (result.Status == ComponentStatus.success) await LoadCus(1); await modal.HideAsync(); } public async Task CustomerItem(int ID) { var parameters = new Dictionary(); if(ID == 0) parameters.Add("Cus", new RCustomer(){ID=0}); else parameters.Add("Cus", request.list.Where(w=>w.ID==ID).First().Clone()); parameters.Add("OnMultipleOfThree", EventCallback.Factory.Create(this, CallBackCustomerItem)); await modal.ShowAsync(title: ID == null ? "مشتری جدید" : "ویرایش اطلاعات", parameters: parameters); } }