@using Front.Services
@using Shared.DTOs
@inject HttpClientController hc;
@if (Cus.ID == 0)
{
}
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()
{
if (Cus.CustomerType != null)
ItemSearchCustomertype = (int)Cus.CustomerType;
result = new ActionInResultComponent()
{
Status = ComponentStatus.fild
};
Hidealert = true;
alertMessage = "";
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()
{
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("خطایی در اجرای عملیات رخ داده");
}
public async Task OnClickUpdate()
{
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("فیلدهای قرمز باید مقدار دهی شوند");
}
public async Task OnClickAdd()
{
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("فیلدهای قرمز باید مقدار دهی شوند");
}
}