This commit is contained in:
mmrbnjd
2024-05-07 18:17:51 +03:30
parent 3e11a2544c
commit d74f3dadf3

View File

@@ -1,5 +1,15 @@
@using Shared.DTOs @using Front.Services
@using Shared.DTOs
@inject HttpClientController hc;
<form> <form>
@* alert *@
<div class="row">
<Alert hidden="@Hidealert" Color="@alertColor" Dismissable="false">
<Icon Name="@alertIconName" class="me-2"></Icon>
@alertMessage
</Alert>
</div>
<div class="row g-3"> <div class="row g-3">
<div class="form-group col-md-6"> <div class="form-group col-md-6">
<label class="col-sm-4 col-form-label" style="color:red" for="inputFullName">نام کامل</label> <label class="col-sm-4 col-form-label" style="color:red" for="inputFullName">نام کامل</label>
@@ -89,7 +99,11 @@ else
@code { @code {
// alert
AlertColor alertColor = AlertColor.Primary;
IconName alertIconName = IconName.CheckCircleFill;
bool Hidealert = true;
string alertMessage = "";
[Parameter] public RCustomer Cus { get; set; } [Parameter] public RCustomer Cus { get; set; }
public int? ItemSearchCustomertype { get; set; } public int? ItemSearchCustomertype { get; set; }
[Parameter] public EventCallback<ActionInResultComponent> OnMultipleOfThree { get; set; } [Parameter] public EventCallback<ActionInResultComponent> OnMultipleOfThree { get; set; }
@@ -102,6 +116,20 @@ else
} }
} }
@functions{ @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(){ public async Task OnClickDelete(){
result.Action = ComponentAction.delete; result.Action = ComponentAction.delete;
await OnMultipleOfThree.InvokeAsync(result); await OnMultipleOfThree.InvokeAsync(result);
@@ -117,7 +145,23 @@ else
Cus.CustomerType = (CustomerType)ItemSearchCustomertype; Cus.CustomerType = (CustomerType)ItemSearchCustomertype;
Cus.ID = null; Cus.ID = null;
var rsp = await hc.Post<RCustomer>("Customer/Add", Cus);
if (rsp.IsSuccessStatusCode)
{
var request = await rsp.Content.ReadFromJsonAsync<bool>();
if (request)
{
result.Action = ComponentAction.add; result.Action = ComponentAction.add;
await OnMultipleOfThree.InvokeAsync(result); await OnMultipleOfThree.InvokeAsync(result);
} }
else ShowDangerAlert("خطایی در اجرای عملیات رخ داده");
}
else
{
var request = await rsp.Content.ReadFromJsonAsync<List<string>>();
ShowDangerAlert(request[0]);
}
}
} }