From d74f3dadf3fc2b061679a12306ba3eaa81fad805 Mon Sep 17 00:00:00 2001 From: mmrbnjd Date: Tue, 7 May 2024 18:17:51 +0330 Subject: [PATCH] add cus --- TaxPayerFull/CUSComponent/CustomerItem.razor | 52 ++++++++++++++++++-- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/TaxPayerFull/CUSComponent/CustomerItem.razor b/TaxPayerFull/CUSComponent/CustomerItem.razor index 00d933d..c331708 100644 --- a/TaxPayerFull/CUSComponent/CustomerItem.razor +++ b/TaxPayerFull/CUSComponent/CustomerItem.razor @@ -1,5 +1,15 @@ -@using Shared.DTOs +@using Front.Services +@using Shared.DTOs +@inject HttpClientController hc;
+ @* alert *@ +
+ + +
@@ -89,7 +99,11 @@ 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; } @@ -102,6 +116,20 @@ else } } @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); @@ -117,7 +145,23 @@ else Cus.CustomerType = (CustomerType)ItemSearchCustomertype; Cus.ID = null; - result.Action = ComponentAction.add; - await OnMultipleOfThree.InvokeAsync(result); + + 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]); + } + } } \ No newline at end of file