TourIAm/TIAMSharedUI/Pages/User/SysAdmins/CompaniesNestedUserProductM...

116 lines
3.5 KiB
Plaintext

@using TIAM.Entities.ServiceProviders
@using TIAM.Entities.Users
@using TIAM.Models.Dtos.Users
@using TIAMWebApp.Shared.Application.Interfaces
@using TIAMWebApp.Shared.Application.Utility
@using AyCode.Services.Loggers
@using TIAM.Core.Loggers
@inject IServiceProviderDataService ServiceProviderDataService
@inject IEnumerable<IAcLogWriterClientBase> LogWriters
<div class="mb-2">
UserProductMapping
</div>
<DxGrid Data="_detailGridData"
PageSize="5"
AutoExpandAllGroupRows="true"
KeyboardNavigationEnabled="KeyboardNavigationEnabled"
KeyFieldName="Id"
ValidationEnabled="false"
CustomizeEditModel="CustomizeEditModel"
EditModelSaving="EditModelSaving"
DataItemDeleting="DataItemDeleting"
EditMode="GridEditMode.EditForm"
ColumnResizeMode="GridColumnResizeMode.NextColumn"
ShowFilterRow="true">
<Columns>
<DxGridCommandColumn NewButtonVisible="true" Width="8%" FixedPosition="GridColumnFixedPosition.Left" />
<DxGridDataColumn FieldName="Id" GroupIndex="0" />
<DxGridDataColumn FieldName="UserId" />
<DxGridDataColumn FieldName="ServiceProviderId" Width="40%" />
@* <DxGridDataColumn FieldName="Permissions" /> *@
</Columns>
<EditFormTemplate Context="EditFormContext">
@{
var transfer2 = (UserToCompany)EditFormContext.EditModel;
}
<DxFormLayout CssClass="w-100">
<DxFormLayoutItem Caption="UserId" ColSpanMd="4">
@EditFormContext.GetEditor("UserId")
</DxFormLayoutItem>
<DxFormLayoutItem Caption="User:" ColSpanMd="4">
<DxComboBox Data="@_availableUsers" TextFieldName="Name" @bind-Value="((UserToCompany)EditFormContext.EditModel).UserId" />
</DxFormLayoutItem>
@* <DxFormLayoutItem Caption="Permissions" ColSpanMd="4">
@EditFormContext.GetEditor("Permissions")
</DxFormLayoutItem> *@
</DxFormLayout>
</EditFormTemplate>
</DxGrid>
@code {
[Parameter]
public bool KeyboardNavigationEnabled { get; set; }
[Parameter]
public Company CurrentCompany { get; set; }
List<UserToCompany> _detailGridData;
List<User> _availableUsers;
public UserModelDtoDetail UserInfo;
ILogger _logger;
protected override async Task OnInitializedAsync()
{
_logger = new LoggerClient<CompaniesNestedUserProductMapping>(LogWriters.ToArray());
_detailGridData = CurrentCompany.UserToServiceProviders ?? new List<UserToCompany>();
_logger.Info($"DetailGridData: {_detailGridData.Count}");
}
void CustomizeEditModel(GridCustomizeEditModelEventArgs e)
{
if (!e.IsNew) return;
var newProductMapping = new UserToCompany
{
ServiceProviderId = CurrentCompany.Id,
UserId = Guid.Empty
};
e.EditModel = newProductMapping;
}
async Task EditModelSaving(GridEditModelSavingEventArgs e)
{
if (e.IsNew)
//add new orderData to orderData array
_logger.Info("New user added to the company");
else
_logger.Info("orderData updated");
await UpdateDataAsync();
}
async Task DataItemDeleting(GridDataItemDeletingEventArgs e)
{
//remove orderData from orderData array
_logger.Info("orderData deleted");
//await UpdateDataAsync();
}
async Task UpdateDataAsync()
{
//refresh grid
_logger.Info("orderData grid refreshed");
}
}