Commessa Edit
This commit is contained in:
@ -50,6 +50,13 @@
|
||||
<RadzenDataGridColumn Property="@nameof(CommessaViewModel.DataConsegnaPrevista)" FormatString="{0:dd/MM/yyyy}" Title="Data consegna effettiva" Width="200px"/>
|
||||
<RadzenDataGridColumn Property="@nameof(CommessaViewModel.DataConsegna)" FormatString="{0:dd/MM/yyyy}" Title="Data consegna richiesta" Width="200px"/>
|
||||
<RadzenDataGridColumn Property="@nameof(CommessaViewModel.Stato)" Title="Stato" Width="200px"/>
|
||||
|
||||
<RadzenDataGridColumn Context="commessa" Filterable="false" Sortable="false" TextAlign="TextAlign.Right" Width="250px">
|
||||
<Template Context="commessa">
|
||||
<RadzenButton Visible="canEdit" Icon="edit" ButtonStyle="ButtonStyle.Light" Variant="Variant.Flat" Size="ButtonSize.Medium" class="rz-my-1 rz-ms-1" Click="@(args => EditRow(commessa))" @onclick:stopPropagation="true" MouseEnter="@(args => ShowTooltip(args, new TooltipOptions() { Text = "Modifica commessa" }))" />
|
||||
<RadzenButton Visible="canDelete" Icon="delete" ButtonStyle="ButtonStyle.Danger" Variant="Variant.Flat" Size="ButtonSize.Medium" Shade="Shade.Lighter" class="rz-my-1 rz-ms-1" Click="@(args => DeleteRow(commessa))" @onclick:stopPropagation="true" MouseEnter="@(args => ShowTooltip(args, new TooltipOptions() { Text = "Rimuovi commessa" }))" />
|
||||
</Template>
|
||||
</RadzenDataGridColumn>
|
||||
</Columns>
|
||||
</RadzenDataGrid>
|
||||
</div>
|
||||
@ -65,6 +72,9 @@
|
||||
public List<CommessaViewModel> CommesseList { get; set; } = new();
|
||||
RadzenDataGrid<CommessaViewModel> 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);
|
||||
}
|
||||
@ -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
|
||||
|
||||
<PageTitle>Commesse</PageTitle>
|
||||
<Breadcrumb Items="BreadcrumbList" />
|
||||
|
||||
<main role="main">
|
||||
<div class="container-fluid h-100 mt-5">
|
||||
<div class="row justify-content-start">
|
||||
<div class="row row-cards">
|
||||
<div class="col-lg-12">
|
||||
<RadzenTabs TabPosition="TabPosition.Top" RenderMode="TabRenderMode.Client" >
|
||||
<Tabs>
|
||||
<RadzenTabsItem Text="Info generali">
|
||||
<Commesse_Edit_InfoGenerali Model="@Model"/>
|
||||
</RadzenTabsItem>
|
||||
|
||||
<RadzenTabsItem Text="OE">
|
||||
<Commesse_Edit_OE />
|
||||
</RadzenTabsItem>
|
||||
</Tabs>
|
||||
</RadzenTabs>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
@code {
|
||||
[Parameter] public Guid? CommessaId { get; set; }
|
||||
|
||||
public List<BreadcrumbViewModel> 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");
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,6 @@
|
||||
@using TecniStamp.Model.Commesse
|
||||
<h3>@Model.CodiceCommessa</h3>
|
||||
|
||||
@code {
|
||||
[Parameter] public CommessaViewModel Model { get; set; } = new();
|
||||
}
|
||||
@ -0,0 +1,6 @@
|
||||
@using TecniStamp.Model.Commesse
|
||||
<h3>Commesse_Edit_OE</h3>
|
||||
|
||||
@code {
|
||||
[Parameter] public CommessaViewModel Model { get; set; } = new();
|
||||
}
|
||||
@ -18,5 +18,6 @@
|
||||
@inject IManagerService _managerService
|
||||
|
||||
@inject DialogService _dialogService
|
||||
@inject TooltipService _tooltipService
|
||||
@inject NavigationManager _navManager
|
||||
@inject AuthenticationStateProvider _auth
|
||||
@ -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<bool> 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user