commit
This commit is contained in:
@ -141,8 +141,8 @@
|
|||||||
|
|
||||||
model.RuoloId = Model.RuoloId;
|
model.RuoloId = Model.RuoloId;
|
||||||
|
|
||||||
await _managerService.UtenteService.Salva(model, Guid.Parse(idClaim));
|
var operatoreSalvato = await _managerService.UtenteService.Salva(model, Guid.Parse(idClaim));
|
||||||
_navManager.NavigateTo($"/Anagrafiche/Operatori/Modifica/{Model.Id}");
|
_navManager.NavigateTo($"/Anagrafiche/Operatori/Modifica/{operatoreSalvato.Id}");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
@using Microsoft.EntityFrameworkCore
|
@using Microsoft.EntityFrameworkCore
|
||||||
@using TecniStamp.Model
|
@using TecniStamp.Model
|
||||||
|
|
||||||
|
@rendermode InteractiveServer
|
||||||
<PageTitle>Ruoli</PageTitle>
|
<PageTitle>Ruoli</PageTitle>
|
||||||
|
|
||||||
<div class="page-wrapper">
|
<div class="page-wrapper">
|
||||||
@ -64,10 +65,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Apre la pagina di modifica per il cliente selezionato.
|
/// Apre la pagina di modifica per il ruolo selezionato.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private async Task EditRow(RuoloViewModel ruolo)
|
private async Task EditRow(RuoloViewModel ruolo)
|
||||||
{
|
{
|
||||||
_navManager.NavigateTo($"/Anagrafiche/Ruoli/Modifica/{ruolo.Id}");
|
_navManager.NavigateTo($"/Anagrafiche/ruoli/Modifica/{ruolo.Id}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,8 +4,10 @@
|
|||||||
@using Microsoft.EntityFrameworkCore
|
@using Microsoft.EntityFrameworkCore
|
||||||
@using TecniStamp.Domain
|
@using TecniStamp.Domain
|
||||||
@using TecniStamp.Model
|
@using TecniStamp.Model
|
||||||
|
@using TecniStamp.Utils
|
||||||
|
|
||||||
@rendermode InteractiveServer
|
@rendermode InteractiveServer
|
||||||
|
@inject AuthenticationStateProvider auth
|
||||||
|
|
||||||
<PageTitle>@pageTitle</PageTitle>
|
<PageTitle>@pageTitle</PageTitle>
|
||||||
|
|
||||||
@ -24,6 +26,7 @@
|
|||||||
<!-- BEGIN PAGE BODY -->
|
<!-- BEGIN PAGE BODY -->
|
||||||
<div class="page-body">
|
<div class="page-body">
|
||||||
<div class="container-xl">
|
<div class="container-xl">
|
||||||
|
|
||||||
<div class="row row-cards">
|
<div class="row row-cards">
|
||||||
<div class="col-lg-12">
|
<div class="col-lg-12">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
@ -60,6 +63,28 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="advanced-table">
|
||||||
|
<div class="table-responsive">
|
||||||
|
<RadzenDataGrid @ref="permessiGrid" AllowFiltering="true" AllowColumnResize="true" AllowAlternatingRows="false" FilterMode="FilterMode.CheckBoxList" AllowSorting="true" PageSize="25"
|
||||||
|
AllowPaging="true" PagerHorizontalAlign="HorizontalAlign.Left" ShowPagingSummary="true" AllowGrouping="true"
|
||||||
|
Data="@permessi" LogicalFilterOperator="LogicalFilterOperator.Or" SelectionMode="DataGridSelectionMode.Single" Render="@OnRender">
|
||||||
|
<Columns>
|
||||||
|
<RadzenDataGridColumn Property="@nameof(PermissionRowViewModel.Selected)" Filterable="true" Width="200px" TextAlign="TextAlign.Center">
|
||||||
|
<Template Context="permesso">
|
||||||
|
<RadzenCheckBox TValue="bool" Value="@permesso.Selected" Change=@(args => onSelected(args, permesso))></RadzenCheckBox>
|
||||||
|
</Template>
|
||||||
|
</RadzenDataGridColumn>
|
||||||
|
<RadzenDataGridColumn Property="@nameof(PermissionRowViewModel.Ordinamento)" Visible="false" SortOrder="SortOrder.Ascending" />
|
||||||
|
<RadzenDataGridColumn Property="@nameof(PermissionRowViewModel.OrdinamentoFeature)" Visible="false" SortOrder="SortOrder.Ascending" />
|
||||||
|
<RadzenDataGridColumn Property="@nameof(PermissionRowViewModel.Nome)" Groupable="true" GroupProperty="Nome" Filterable="true" Width="200px" TextAlign="TextAlign.Center" />
|
||||||
|
<RadzenDataGridColumn Property="@nameof(PermissionRowViewModel.NomeFeature)" Title="Nome" Width="250px" />
|
||||||
|
<RadzenDataGridColumn Property="@nameof(PermissionRowViewModel.DescrizioneFeature)" Title="Descrizione" Width="250px" />
|
||||||
|
</Columns>
|
||||||
|
</RadzenDataGrid>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -69,16 +94,26 @@
|
|||||||
[Parameter] public Guid? RuoloId { get; set; }
|
[Parameter] public Guid? RuoloId { get; set; }
|
||||||
|
|
||||||
public RuoloViewModel Model { get; set; } = new();
|
public RuoloViewModel Model { get; set; } = new();
|
||||||
|
private List<PermissionRowViewModel> permessi { get; set; } = new();
|
||||||
|
private RadzenDataGrid<PermissionRowViewModel> permessiGrid { get; set; }
|
||||||
|
|
||||||
private string pageTitle => Model?.Id == Guid.Empty ? "Nuovo Ruolo" : $"Modifica Ruolo {Model}";
|
private string pageTitle => Model?.Id == Guid.Empty ? "Nuovo Ruolo" : $"Modifica Ruolo {Model}";
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
await base.OnInitializedAsync();
|
await base.OnInitializedAsync();
|
||||||
|
|
||||||
Model = RuoloId.GetValueOrDefault() == Guid.Empty
|
Model = RuoloId.GetValueOrDefault() == Guid.Empty
|
||||||
? new RuoloViewModel()
|
? new RuoloViewModel()
|
||||||
: await _managerService.RuoloService.RicercaPer(x => x.Id == RuoloId);
|
: await _managerService.RuoloService.RicercaPer(x => x.Id == RuoloId);
|
||||||
|
|
||||||
|
var sections = (await
|
||||||
|
_managerService.SezioneService.RicercaQueryable(x => x.Eliminato == false, includi: x => x.Include(y => y.Features))).ToList();
|
||||||
|
var permissions = await _managerService.PermissionService.RicercaQueryable(x => x.Ruolo.Id == Model.Id && x.Eliminato == false);
|
||||||
|
|
||||||
|
permessi = [];
|
||||||
|
foreach (var section in sections)
|
||||||
|
permessi.AddRange(section.Features.Where(x => !x.Eliminato).Select(x => new PermissionRowViewModel(section, x, permissions)).ToList());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -88,29 +123,74 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private async Task onRuoloSave()
|
private async Task onRuoloSave()
|
||||||
{
|
{
|
||||||
var state = await _auth.GetAuthenticationStateAsync();
|
try
|
||||||
var idClaim = state.User.FindFirst("UserId")?.Value;
|
|
||||||
if (string.IsNullOrEmpty(idClaim))
|
|
||||||
{
|
{
|
||||||
// gestisci errore (utente non autenticato o claim mancante)
|
var state = await _auth.GetAuthenticationStateAsync();
|
||||||
return;
|
var idClaim = state.User.FindFirst("UserId")?.Value;
|
||||||
|
if (string.IsNullOrEmpty(idClaim))
|
||||||
|
{
|
||||||
|
// gestisci errore (utente non autenticato o claim mancante)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var model = Model.Id == Guid.Empty
|
||||||
|
? new Ruolo()
|
||||||
|
: await _managerService.RuoloService.RicercaPer(x => x.Id == Model.Id, solaLettura: false);
|
||||||
|
|
||||||
|
model = Model.Map(model);
|
||||||
|
|
||||||
|
var ruoloSalvato = await _managerService.RuoloService.Salva(model, Guid.Parse(idClaim));
|
||||||
|
_navManager.NavigateTo($"/Anagrafiche/ruoli/Modifica/{ruoloSalvato.Id}");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
await _dialogService.Alert("Si è verificato un'errore", "Errore", new AlertOptions() { OkButtonText = "Continua" });
|
||||||
}
|
}
|
||||||
|
|
||||||
var model = Model.Id == Guid.Empty
|
|
||||||
? new Ruolo()
|
|
||||||
: await _managerService.RuoloService.RicercaPer(x => x.Id == Model.Id, solaLettura: false);
|
|
||||||
|
|
||||||
model = Model.Map(model);
|
|
||||||
|
|
||||||
await _managerService.RuoloService.Salva(model, Guid.Parse(idClaim));
|
|
||||||
_navManager.NavigateTo($"/Anagrafiche/ruoli/Modifica/{Model.Id}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Torna all’elenco utenti senza applicare altre azioni.
|
/// Torna all’elenco ruoli senza applicare altre azioni.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void backToHome()
|
private void backToHome()
|
||||||
{
|
{
|
||||||
_navManager.NavigateTo("/Anagrafiche/ruoli");
|
_navManager.NavigateTo("/Anagrafiche/ruoli");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OnRender(DataGridRenderEventArgs<PermissionRowViewModel> args)
|
||||||
|
{
|
||||||
|
if (!args.FirstRender) return;
|
||||||
|
args.Grid.Groups.Add(new GroupDescriptor() { Property = "Nome", SortOrder = SortOrder.Descending });
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="selected"></param>
|
||||||
|
/// <param name="permissionRow"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private async Task onSelected(bool selected, PermissionRowViewModel permissionRow)
|
||||||
|
{
|
||||||
|
var idClaim = await MembershipUtils.GetUserId(auth);
|
||||||
|
|
||||||
|
var ruoloPermission = await _managerService.PermissionService.RicercaPer(
|
||||||
|
x => x.RuoloId == Model.Id && x.IdFeature == permissionRow.IdFeature && x.Eliminato == false,
|
||||||
|
includi: x => x.Include(y => y.Ruolo).Include(y => y.Feature),
|
||||||
|
solaLettura: false);
|
||||||
|
|
||||||
|
if (ruoloPermission == null && selected)
|
||||||
|
{
|
||||||
|
var permission = new Permission()
|
||||||
|
{
|
||||||
|
RuoloId = Model.Id,
|
||||||
|
IdFeature = permissionRow.IdFeature
|
||||||
|
};
|
||||||
|
await _managerService.PermissionService.Salva(permission, idClaim);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await _managerService.PermissionService.Elimina(ruoloPermission?.Id ?? Guid.Empty, idClaim);
|
||||||
|
}
|
||||||
|
permissionRow.Selected = selected;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
26
TecniStamp/TecniStamp/Model/PermissionRowViewModel.cs
Normal file
26
TecniStamp/TecniStamp/Model/PermissionRowViewModel.cs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
using TecniStamp.Domain;
|
||||||
|
|
||||||
|
namespace TecniStamp.Model;
|
||||||
|
|
||||||
|
public class PermissionRowViewModel
|
||||||
|
{
|
||||||
|
public PermissionRowViewModel(Sezione section, Feature feature, IQueryable<Permission> permissions)
|
||||||
|
{
|
||||||
|
Nome = section.Nome;
|
||||||
|
IdSezione = section.Id;
|
||||||
|
NomeFeature = feature.Nome;
|
||||||
|
DescrizioneFeature = feature.Descrizione;
|
||||||
|
IdFeature = feature.Id;
|
||||||
|
Ordinamento = section.Ordinamento;
|
||||||
|
OrdinamentoFeature = feature.Ordinamento;
|
||||||
|
Selected = permissions.Any(y => y.Feature.Id == feature.Id);
|
||||||
|
}
|
||||||
|
public Guid IdSezione { get; set; }
|
||||||
|
public string Nome { get; set; }
|
||||||
|
public Guid IdFeature { get; set; }
|
||||||
|
public string NomeFeature { get; set; }
|
||||||
|
public string DescrizioneFeature { get; set; }
|
||||||
|
public int Ordinamento { get; set; }
|
||||||
|
public int OrdinamentoFeature { get; set; }
|
||||||
|
public bool Selected { get; set; }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user