diff --git a/TecniStamp/TecniStamp/Components/Pages/Commesse/Commesse.razor b/TecniStamp/TecniStamp/Components/Pages/Commesse/Commesse.razor
index ae01a79..d41cfc0 100644
--- a/TecniStamp/TecniStamp/Components/Pages/Commesse/Commesse.razor
+++ b/TecniStamp/TecniStamp/Components/Pages/Commesse/Commesse.razor
@@ -50,6 +50,13 @@
+
+
+
+
+
+
+
@@ -65,6 +72,9 @@
public List CommesseList { get; set; } = new();
RadzenDataGrid commesseGrid;
+ private bool canEdit = false;
+ private bool canDelete = false;
+
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
@@ -76,5 +86,29 @@
includi:x => x.Include(y => y.Cliente).ThenInclude(z => z.Comune).ThenInclude(w => w.ProvinciaIstat)
.Include(x => x.Posizioni)))
.Select(x => (CommessaViewModel)x).ToList();
+ canEdit = await MembershipUtils.CheckPermission(_auth, _managerService, "Commesse_Edit");
+ canDelete = await MembershipUtils.CheckPermission(_auth, _managerService, "Commesse_Delete");
}
+
+ private async Task EditRow(CommessaViewModel commessa)
+ {
+ _navManager.NavigateTo($"/commesse/modifica/{commessa.Id}");
+ }
+
+ private async Task DeleteRow(CommessaViewModel commessa)
+ {
+ var ok = await _dialogService.Confirm($"Vuoi davvero eliminare la commessa {commessa.CodiceCommessa}?", "Conferma eliminazione", new ConfirmOptions { OkButtonText = "Sì", CancelButtonText = "No", Width = "400px" });
+
+ if (ok == true)
+ {
+ await _managerService.CommessaService.Elimina(commessa.Id, await MembershipUtils.GetUserId(_auth));
+ CommesseList = (await _managerService.CommessaService.RicercaQueryable(
+ x => x.Eliminato == false,
+ includi:x => x.Include(y => y.Cliente).ThenInclude(z => z.Comune).ThenInclude(w => w.ProvinciaIstat)
+ .Include(x => x.Posizioni)))
+ .Select(x => (CommessaViewModel)x).ToList();
+ }
+ }
+
+void ShowTooltip(ElementReference elementReference, TooltipOptions options = null) => _tooltipService.Open(elementReference, options.Text, options);
}
\ No newline at end of file
diff --git a/TecniStamp/TecniStamp/Components/Pages/Commesse/Commesse_Edit.razor b/TecniStamp/TecniStamp/Components/Pages/Commesse/Commesse_Edit.razor
new file mode 100644
index 0000000..0edd4c6
--- /dev/null
+++ b/TecniStamp/TecniStamp/Components/Pages/Commesse/Commesse_Edit.razor
@@ -0,0 +1,55 @@
+@page "/commesse/modifica"
+@page "/commesse/modifica/{CommessaId:guid}"
+
+@rendermode InteractiveServer
+
+@using Microsoft.EntityFrameworkCore
+@using TecniStamp.Model.Commesse
+@using TecniStamp.Model.Common
+@using TecniStamp.Utils
+
+Commesse
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+@code {
+ [Parameter] public Guid? CommessaId { get; set; }
+
+ public List BreadcrumbList { get; set; } = new();
+
+ public CommessaViewModel Model { get; set; } = new();
+
+ protected override async Task OnInitializedAsync()
+ {
+ await base.OnInitializedAsync();
+
+ Model = CommessaId.GetValueOrDefault() == Guid.Empty
+ ? new CommessaViewModel()
+ : await _managerService.CommessaService.RicercaPer(x => x.Id == CommessaId,
+ includi:x => x.Include(y => y.Cliente).Include(y => y.Posizioni));
+
+ BreadcrumbList = await BreadcrumbUtils.BuildBreadcrumbByFeature(_managerService, "Commesse_Info", "Modifica", "/commesse");
+ }
+
+}
\ No newline at end of file
diff --git a/TecniStamp/TecniStamp/Components/Pages/Commesse/Commesse_Edit_InfoGenerali.razor b/TecniStamp/TecniStamp/Components/Pages/Commesse/Commesse_Edit_InfoGenerali.razor
new file mode 100644
index 0000000..56ca312
--- /dev/null
+++ b/TecniStamp/TecniStamp/Components/Pages/Commesse/Commesse_Edit_InfoGenerali.razor
@@ -0,0 +1,6 @@
+@using TecniStamp.Model.Commesse
+@Model.CodiceCommessa
+
+@code {
+ [Parameter] public CommessaViewModel Model { get; set; } = new();
+}
\ No newline at end of file
diff --git a/TecniStamp/TecniStamp/Components/Pages/Commesse/Commesse_Edit_OE.razor b/TecniStamp/TecniStamp/Components/Pages/Commesse/Commesse_Edit_OE.razor
new file mode 100644
index 0000000..512b43a
--- /dev/null
+++ b/TecniStamp/TecniStamp/Components/Pages/Commesse/Commesse_Edit_OE.razor
@@ -0,0 +1,6 @@
+@using TecniStamp.Model.Commesse
+Commesse_Edit_OE
+
+@code {
+ [Parameter] public CommessaViewModel Model { get; set; } = new();
+}
\ No newline at end of file
diff --git a/TecniStamp/TecniStamp/Components/_Imports.razor b/TecniStamp/TecniStamp/Components/_Imports.razor
index c064d65..ac8a8a8 100644
--- a/TecniStamp/TecniStamp/Components/_Imports.razor
+++ b/TecniStamp/TecniStamp/Components/_Imports.razor
@@ -18,5 +18,6 @@
@inject IManagerService _managerService
@inject DialogService _dialogService
+@inject TooltipService _tooltipService
@inject NavigationManager _navManager
@inject AuthenticationStateProvider _auth
\ No newline at end of file
diff --git a/TecniStamp/TecniStamp/Utils/MembershipUtils.cs b/TecniStamp/TecniStamp/Utils/MembershipUtils.cs
index 8491cba..dbdc289 100644
--- a/TecniStamp/TecniStamp/Utils/MembershipUtils.cs
+++ b/TecniStamp/TecniStamp/Utils/MembershipUtils.cs
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Components.Authorization;
+using TecniStamp.Service.Interfaces;
namespace TecniStamp.Utils;
@@ -19,4 +20,16 @@ public static class MembershipUtils
return Guid.Parse(idClaim ?? Guid.Empty.ToString());
}
+
+ public static async Task CheckPermission(AuthenticationStateProvider auth, IManagerService managerService, string featureName)
+ {
+ var state = await auth.GetAuthenticationStateAsync();
+ var idClaim = state.User.FindFirst("RoleId")?.Value;
+
+ var parsed = Guid.Parse(idClaim ?? Guid.Empty.ToString());
+
+ var perm = await managerService.RuoloService.RicercaPer(x =>
+ x.Id == parsed && x.Permessi.Any(y => y.Feature.Nome == featureName && y.Eliminato == false) && x.Eliminato == false);
+ return perm != null;
+ }
}