@using Front.Services @using Shared.DTOs @inject HttpClientController hc;
@* alert *@
@if (Cus.ID==-1) { } else { } @code { // alert AlertColor alertColor = AlertColor.Primary; IconName alertIconName = IconName.CheckCircleFill; bool Hidealert = true; string alertMessage = ""; [Parameter] public RCustomer Cus { get; set; } public int? ItemSearchCustomertype { get; set; } [Parameter] public EventCallback OnMultipleOfThree { get; set; } public ActionInResultComponent result { get; set; } protected override Task OnParametersSetAsync() { result = new ActionInResultComponent(); return 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 OnClickDelete(){ result.Action = ComponentAction.delete; await OnMultipleOfThree.InvokeAsync(result); } public async Task OnClickUpdate() { result.Action = ComponentAction.update; await OnMultipleOfThree.InvokeAsync(result); } public async Task OnClickAdd() { 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.Action = ComponentAction.add; await OnMultipleOfThree.InvokeAsync(result); } else ShowDangerAlert("خطایی در اجرای عملیات رخ داده"); } else { var request = await rsp.Content.ReadFromJsonAsync>(); ShowDangerAlert(request[0]); } } }