diff --git a/salesbook.Shared/Components/SingleElements/Modal/ActivityForm.razor b/salesbook.Shared/Components/SingleElements/Modal/ActivityForm.razor index e35b0bd..8443d96 100644 --- a/salesbook.Shared/Components/SingleElements/Modal/ActivityForm.razor +++ b/salesbook.Shared/Components/SingleElements/Modal/ActivityForm.razor @@ -1,6 +1,7 @@ @using System.Globalization @using System.Text.RegularExpressions @using CommunityToolkit.Mvvm.Messaging +@using Java.Util.Jar @using salesbook.Shared.Core.Dto @using salesbook.Shared.Components.Layout @using salesbook.Shared.Core.Entity @@ -123,9 +124,18 @@ { foreach (var item in AttachedList!.Select((p, index) => new { p, index })) { - - @item.p.Name - + @if (item.p.Type == AttachedDTO.TypeAttached.Position) + { + + @item.p.Description + + } + else + { + + @item.p.Name + + } } } @@ -183,11 +193,23 @@ + StartIcon="@Icons.Material.Rounded.DeleteForever"> Cancella + + + + + + + + Salva + + + @@ -195,7 +217,7 @@ + StartIcon="@Icons.Material.Rounded.Check"> Crea @@ -241,9 +263,12 @@ //MessageBox private MudMessageBox ConfirmDelete { get; set; } private MudMessageBox ConfirmMemo { get; set; } + private MudMessageBox AddNamePosition { get; set; } //Attached private List? AttachedList { get; set; } + private string? NamePosition { get; set; } + private bool CanAddPosition { get; set; } = true; protected override async Task OnInitializedAsync() { @@ -479,12 +504,25 @@ private async Task OpenAddAttached() { - var result = await ModalHelpers.OpenAddAttached(Dialog); + var result = await ModalHelpers.OpenAddAttached(Dialog, CanAddPosition); if (result is { Canceled: false, Data: not null } && result.Data.GetType() == typeof(AttachedDTO)) { + var attached = (AttachedDTO)result.Data; + + if (attached.Type == AttachedDTO.TypeAttached.Position) + { + CanAddPosition = false; + + var resultNamePosition = await AddNamePosition.ShowAsync(); + + if (resultNamePosition is true) + attached.Description = NamePosition; + attached.Name = NamePosition!; + } + AttachedList ??= []; - AttachedList.Add((AttachedDTO)result.Data); + AttachedList.Add(attached); LabelSave = "Aggiorna"; } @@ -495,6 +533,11 @@ if (AttachedList is null || index < 0 || index >= AttachedList.Count) return; + var attached = AttachedList[index]; + + if (attached.Type == AttachedDTO.TypeAttached.Position) + CanAddPosition = true; + AttachedList.RemoveAt(index); StateHasChanged(); } diff --git a/salesbook.Shared/Components/SingleElements/Modal/AddAttached.razor b/salesbook.Shared/Components/SingleElements/Modal/AddAttached.razor index 0bb7aa2..16f5e69 100644 --- a/salesbook.Shared/Components/SingleElements/Modal/AddAttached.razor +++ b/salesbook.Shared/Components/SingleElements/Modal/AddAttached.razor @@ -16,10 +16,13 @@ - - + + @if (CanAddPosition) + { + + } @@ -29,6 +32,8 @@ @code { [CascadingParameter] private IMudDialogInstance MudDialog { get; set; } + [Parameter] public bool CanAddPosition { get; set; } + //Overlay for save private bool VisibleOverlay { get; set; } private bool SuccessAnimation { get; set; } diff --git a/salesbook.Shared/Core/Helpers/ModalHelpers.cs b/salesbook.Shared/Core/Helpers/ModalHelpers.cs index 52e11fe..fa199f6 100644 --- a/salesbook.Shared/Core/Helpers/ModalHelpers.cs +++ b/salesbook.Shared/Core/Helpers/ModalHelpers.cs @@ -67,11 +67,14 @@ public class ModalHelpers return await modal.Result; } - public static async Task OpenAddAttached(IDialogService dialog) + public static async Task OpenAddAttached(IDialogService dialog, bool canAddPosition) { var modal = await dialog.ShowAsync( "Add attached", - new DialogParameters(), + new DialogParameters + { + { x => x.CanAddPosition, canAddPosition} + }, new DialogOptions { FullScreen = false,