Cancellazione attività
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
@using System.Globalization
|
||||
@using CommunityToolkit.Mvvm.Messaging
|
||||
@using Template.Shared.Core.Dto
|
||||
@using Template.Shared.Components.Layout
|
||||
@using Template.Shared.Core.Entity
|
||||
@using Template.Shared.Core.Interface
|
||||
@using Template.Shared.Components.Layout.Overlay
|
||||
@using Template.Shared.Components.SingleElements.BottomSheet
|
||||
@using Template.Shared.Core.Messages.Activity.Copy
|
||||
@inject IManageDataService ManageData
|
||||
@inject INetworkService NetworkService
|
||||
@inject IIntegryApiService IntegryApiService
|
||||
@inject IMessenger Messenger
|
||||
|
||||
<MudDialog Class="customDialog-form">
|
||||
<DialogContent>
|
||||
@@ -30,12 +33,19 @@
|
||||
<div class="form-container">
|
||||
<span class="disable-full-width">Commessa</span>
|
||||
|
||||
<MudSelectExtended FullWidth="true" ReadOnly="@(IsView || Commesse.IsNullOrEmpty())" T="string?" Variant="Variant.Text" @bind-Value="ActivityModel.CodJcom" @bind-Value:after="OnCommessaChanged" Class="customIcon-select" AdornmentIcon="@Icons.Material.Filled.Code">
|
||||
@foreach (var com in Commesse)
|
||||
{
|
||||
<MudSelectItemExtended Class="custom-item-select" Value="@com.CodJcom">@($"{com.CodJcom} - {com.Descrizione}")</MudSelectItemExtended>
|
||||
}
|
||||
</MudSelectExtended>
|
||||
@if (Commesse.IsNullOrEmpty())
|
||||
{
|
||||
<span class="warning-text">Nessuna commessa presente</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudSelectExtended FullWidth="true" ReadOnly="@(IsView || Commesse.IsNullOrEmpty())" T="string?" Variant="Variant.Text" @bind-Value="ActivityModel.CodJcom" @bind-Value:after="OnCommessaChanged" Class="customIcon-select" AdornmentIcon="@Icons.Material.Filled.Code">
|
||||
@foreach (var com in Commesse)
|
||||
{
|
||||
<MudSelectItemExtended Class="custom-item-select" Value="@com.CodJcom">@($"{com.CodJcom} - {com.Descrizione}")</MudSelectItemExtended>
|
||||
}
|
||||
</MudSelectExtended>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -105,7 +115,44 @@
|
||||
<div class="input-card">
|
||||
<MudTextField ReadOnly="IsView" T="string?" Placeholder="Note" Variant="Variant.Text" Lines="4" @bind-Value="ActivityModel.Note" @bind-Value:after="OnAfterChangeValue" DebounceInterval="500" OnDebounceIntervalElapsed="OnAfterChangeValue"/>
|
||||
</div>
|
||||
|
||||
@if (!IsNew)
|
||||
{
|
||||
<div class="container-button">
|
||||
<MudButton Class="button-settings gray-icon"
|
||||
FullWidth="true"
|
||||
StartIcon="@Icons.Material.Filled.ContentCopy"
|
||||
Size="Size.Medium"
|
||||
OnClick="Duplica"
|
||||
Variant="Variant.Outlined">
|
||||
Duplica
|
||||
</MudButton>
|
||||
|
||||
<div class="divider"></div>
|
||||
|
||||
<MudButton Class="button-settings red-icon"
|
||||
FullWidth="true"
|
||||
StartIcon="@Icons.Material.Outlined.Delete"
|
||||
Size="Size.Medium"
|
||||
OnClick="DeleteActivity"
|
||||
Variant="Variant.Outlined">
|
||||
Elimina
|
||||
</MudButton>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<MudMessageBox @ref="ConfirmDelete" Class="c-messageBox" Title="Attenzione!" CancelText="Annulla">
|
||||
<MessageContent>
|
||||
Confermi la cancellazione dell'attività corrente?
|
||||
</MessageContent>
|
||||
<YesButton>
|
||||
<MudButton Size="Size.Small" Variant="Variant.Filled" Color="Color.Error"
|
||||
StartIcon="@Icons.Material.Filled.DeleteForever">
|
||||
Cancella
|
||||
</MudButton>
|
||||
</YesButton>
|
||||
</MudMessageBox>
|
||||
</DialogContent>
|
||||
</MudDialog>
|
||||
|
||||
@@ -117,6 +164,7 @@
|
||||
[CascadingParameter] private IMudDialogInstance MudDialog { get; set; }
|
||||
|
||||
[Parameter] public string? Id { get; set; }
|
||||
[Parameter] public ActivityDTO? ActivityCopied { get; set; }
|
||||
|
||||
private ActivityDTO OriginalModel { get; set; } = new();
|
||||
private ActivityDTO ActivityModel { get; set; } = new();
|
||||
@@ -139,6 +187,8 @@
|
||||
|
||||
private bool OpenEsito { get; set; } = false;
|
||||
|
||||
private MudMessageBox ConfirmDelete { get; set; }
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
_ = LoadData();
|
||||
@@ -148,6 +198,11 @@
|
||||
if (!Id.IsNullOrEmpty())
|
||||
ActivityModel = (await ManageData.GetActivity(x => x.ActivityId.Equals(Id))).Last();
|
||||
|
||||
if (ActivityCopied != null)
|
||||
{
|
||||
ActivityModel = ActivityCopied.Clone();
|
||||
}
|
||||
|
||||
if (IsNew)
|
||||
{
|
||||
ActivityModel.EstimatedTime = DateTime.Today.Add(TimeSpan.FromHours(DateTime.Now.Hour));
|
||||
@@ -200,11 +255,7 @@
|
||||
Clienti = await ManageData.GetTable<AnagClie>(x => x.FlagStato.Equals("A"));
|
||||
Pros = await ManageData.GetTable<PtbPros>();
|
||||
ActivityType = await ManageData.GetTable<StbActivityType>(x => x.FlagTipologia.Equals("A"));
|
||||
|
||||
if (IsNew)
|
||||
{
|
||||
await LoadCommesse();
|
||||
}
|
||||
await LoadCommesse();
|
||||
}
|
||||
|
||||
private async Task LoadCommesse() =>
|
||||
@@ -218,11 +269,11 @@
|
||||
var listToReturn = new List<string>();
|
||||
|
||||
listToReturn.AddRange(
|
||||
Clienti.Where(x => x.RagSoc.Contains(value, StringComparison.OrdinalIgnoreCase)).Select(x => x.RagSoc)
|
||||
Clienti.Where(x => x.RagSoc.Contains(value, StringComparison.OrdinalIgnoreCase)).Select(x => $"{x.CodAnag} - {x.RagSoc}")
|
||||
);
|
||||
|
||||
listToReturn.AddRange(
|
||||
Pros.Where(x => x.RagSoc.Contains(value, StringComparison.OrdinalIgnoreCase)).Select(x => x.RagSoc)
|
||||
Pros.Where(x => x.RagSoc.Contains(value, StringComparison.OrdinalIgnoreCase)).Select(x => $"{x.CodPpro} - {x.RagSoc}")
|
||||
);
|
||||
|
||||
return listToReturn;
|
||||
@@ -231,6 +282,7 @@
|
||||
private async Task OnClienteChanged()
|
||||
{
|
||||
string? codAnag = null;
|
||||
ActivityModel.CodJcom = null;
|
||||
|
||||
var cliente = Clienti.LastOrDefault(x => ActivityModel.Cliente != null && x.RagSoc.Contains(ActivityModel.Cliente, StringComparison.OrdinalIgnoreCase));
|
||||
if (cliente is null)
|
||||
@@ -278,4 +330,42 @@
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task DeleteActivity()
|
||||
{
|
||||
var result = await ConfirmDelete.ShowAsync();
|
||||
|
||||
if (result is true)
|
||||
{
|
||||
VisibleOverlay = true;
|
||||
StateHasChanged();
|
||||
|
||||
try
|
||||
{
|
||||
await IntegryApiService.DeleteActivity(ActivityModel.ActivityId);
|
||||
ActivityModel.Deleted = true;
|
||||
|
||||
SuccessAnimation = true;
|
||||
StateHasChanged();
|
||||
|
||||
await Task.Delay(1250);
|
||||
|
||||
MudDialog.Close(ActivityModel);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
VisibleOverlay = false;
|
||||
StateHasChanged();
|
||||
Snackbar.Add("Impossibile cancellare l'attività", Severity.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Duplica()
|
||||
{
|
||||
var activityCopy = ActivityModel.Clone();
|
||||
|
||||
MudDialog.Cancel();
|
||||
Messenger.Send(new CopyActivityMessage(activityCopy));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user