imprvements, fixes, etc...

This commit is contained in:
Loretta 2024-07-05 15:39:14 +02:00
parent 4507f69f9e
commit 0bce3c9fd2
13 changed files with 151 additions and 62 deletions

View File

@ -31,6 +31,7 @@ using DevExpress.Data.Linq.Helpers;
using TIAM.Database.DbSets.Drivers;
using AyCode.Entities.Server.LogItems;
using AyCode.Interfaces.Entities;
using TIAM.Models.Dtos.Users;
namespace TIAM.Database.DataLayers.Admins
{
@ -41,7 +42,6 @@ namespace TIAM.Database.DataLayers.Admins
}
#region Car
public Task<List<Car>> GetAllCarsAsync() => SessionAsync(ctx => ctx.Cars.OrderBy(x => x.Manufacture).ThenBy(x => x.CarModel).ToList());
public Task<List<Car>> GetAllCarsbyProductIdAsync(Guid productId) => SessionAsync(ctx => ctx.Cars.Where(x => x.UserProductMapping.ProductId == productId).OrderBy(x => x.Manufacture).ThenBy(x => x.CarModel).ToList());
public Car? GetCarById(Guid carId) => Session(ctx => ctx.Cars.FirstOrDefault(x => x.Id == carId));
@ -217,9 +217,11 @@ namespace TIAM.Database.DataLayers.Admins
public Task<bool> UpdateUserAsync(User user) => TransactionAsync(ctx => ctx.UpdateUser(user));
public Task<bool> RemoveUserAsync(Guid userId) => TransactionAsync(ctx => ctx.RemoveUser(userId));
#region Product
public Product? GetProductById(Guid contextId, bool includeUsers = true) => Session(ctx => ctx.GetProductById(contextId, includeUsers));
public Task<Product?> GetProductByIdAsync(Guid contextId, bool includeUsers = true) => SessionAsync(ctx => ctx.GetProductById(contextId, includeUsers));
public Task<List<ProductModelDtoName>> GetProductModelDtoNamesAsync() => SessionAsync(ctx => ctx.Products.Select(x => new ProductModelDtoName(x)).ToList());
public string GetProductsJson(bool includeUsers = true) => Session(ctx => ctx.ProductsWithUserRelations(includeUsers).ToJson());
public List<Product> GetProductsByServiceProviderId(Guid serviceProviderId, bool includeUsers = true) => Session(ctx => ctx.GetProductsByCompanyId(serviceProviderId, includeUsers).ToList());
public string GetProductsJsonByServiceProviderId(Guid serviceProviderId, bool includeUsers = true) => Session(ctx => ctx.GetProductsByCompanyId(serviceProviderId, includeUsers).ToJson());
@ -228,6 +230,7 @@ namespace TIAM.Database.DataLayers.Admins
public Task<Product?> UpdateProductAsync(Product product) => UpdateSafeAsync(product, (ctx, safeProduct) => ctx.UpdateProduct(safeProduct));
public Task<bool> RemoveProductAsync(Product product) => RemoveProductAsync(product.Id);
public Task<bool> RemoveProductAsync(Guid productId) => TransactionAsync(ctx => ctx.RemoveProduct(productId));
#endregion Product
public UserProductMapping? GetUserProductMappingById(Guid userProductMappingId, bool autoInclude = true) => Session(ctx => ctx.GetUserProductMappingById(userProductMappingId, autoInclude));
public Task<UserProductMapping?> GetUserProductMappingByIdAsync(Guid userProductMappingId, bool autoInclude = true) => SessionAsync(ctx => ctx.GetUserProductMappingById(userProductMappingId, autoInclude));

View File

@ -6,6 +6,7 @@ using TIAM.Entities.Emails;
using TIAM.Entities.Profiles;
using TIAM.Entities.ServiceProviders;
using TIAM.Entities.Users;
using TIAM.Models.Dtos.Users;
namespace TIAM.Database.DataLayers.Users
{
@ -20,6 +21,8 @@ namespace TIAM.Database.DataLayers.Users
{
}
public Task<List<UserModelDtoEmail>> GetUserModelDtoEmailsAsync() => SessionAsync(ctx => ctx.Users.Select(x => new UserModelDtoEmail(x)).ToList());
public async Task<bool> CreateUserAsync(User user)
{
Context.Users.Add(user);

View File

@ -0,0 +1,21 @@
using AyCode.Interfaces;
using TIAM.Entities.Products;
namespace TIAM.Models.Dtos.Products;
public class ProductModelDtoName : IAcModelDtoBase
{
public Guid Id { get; set; }
public string Name { get; set; }
public ProductModelDtoName()
{ }
public ProductModelDtoName(Product product) : this(product.Id, product.Name)
{ }
public ProductModelDtoName(Guid id, string name) : this()
{
Id = id;
Name = name;
}
}

View File

@ -1,5 +1,6 @@
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
using AyCode.Core.Interfaces;
using AyCode.Interfaces;
using AyCode.Models.Users;
using TIAM.Entities.Products;

View File

@ -0,0 +1,22 @@
using AyCode.Interfaces;
using AyCode.Interfaces.Users;
using TIAM.Entities.Users;
namespace TIAM.Models.Dtos.Users;
public class UserModelDtoEmail : IAcEmailAddress, IAcModelDtoBase
{
public Guid Id { get; set; }
public string EmailAddress { get; set; }
public UserModelDtoEmail()
{ }
public UserModelDtoEmail(User user) : this(user.Id, user.EmailAddress)
{ }
public UserModelDtoEmail(Guid id, string emailAddress) : this()
{
Id = id;
EmailAddress = emailAddress;
}
}

View File

@ -85,6 +85,8 @@ public class SignalRTags : AcSignalRTags
public const int RemoveProduct = 75;
public const int GetProductsById = 76;
public const int GetAllProducts = 77;
public const int GetAllProductModelDtoNames = 78;
public const int GetTransferDestinationById = 80;
public const int GetAllTransferDestinations = 81;
@ -101,6 +103,7 @@ public class SignalRTags : AcSignalRTags
public const int GetTransferDestinationToProductsByTransferDestinationId = 96;
public const int GetAllUsers = 120;
public const int GetAllUserModelDtoEmails = 125;
public const int GetAllLogItemsByFilterText = 1000;
}

View File

@ -168,7 +168,7 @@
_takeCount = value;
_contextParams[0] = _takeCount;
await _logViewerGrid.LoadDataSourceAsync();
await _logViewerGrid.ReloadDataSourceAsync();
}
private async Task OnValueChangedStartDate(DateTime value)
@ -181,7 +181,7 @@
_contextParams[1] = _fromDate;
if (_fromDate.Date > _toDate.Date) return;
await _logViewerGrid.LoadDataSourceAsync();
await _logViewerGrid.ReloadDataSourceAsync();
}
private async Task OnValueChangedEndDate(DateTime value)
@ -192,7 +192,7 @@
_contextParams[2] = _toDate;
if (_fromDate.Date > _toDate.Date) return;
await _logViewerGrid.LoadDataSourceAsync();
await _logViewerGrid.ReloadDataSourceAsync();
}
void Grid_CustomizeElement(GridCustomizeElementEventArgs e)

View File

@ -146,11 +146,41 @@
_logger.Info($"DetailGridData: {ParentData.TransferToDrivers.Count}");
await base.OnInitializedAsync();
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
LoadComboBoxItems().Forget();
}
await base.OnAfterRenderAsync(firstRender);
}
void CustomizeEditModel(GridCustomizeEditModelEventArgs e)
{
if (!e.IsNew) return;
var newDriver = (TransferToDriver)e.EditModel;
newDriver.Id = Guid.NewGuid();
newDriver.CarId = Guid.Empty;
newDriver.LicencePlate = "";
newDriver.Car = new Car();
newDriver.Price = 0;
newDriver.TransferId = ParentData.Id;
}
private Task LoadComboBoxItems()
{
// _cars.AddRange((await AdminSignalRClient.GetAllAsync<List<Car>>(SignalRTags.GetAllCarsByProductId, [TiamConstClient.TransferProductId])) ?? []);
// _drivers.AddRange(_cars.DistinctBy(x => x.UserProductMappingId).Select(x => x.UserProductMapping));
//AdminSignalRClient.GetAllIntoAsync<Car>(_cars, SignalRTags.GetAllCarsByProductId, [TiamConstClient.TransferProductId])
AdminSignalRClient.GetAllAsync<List<Car>>(SignalRTags.GetAllCarsByProductId, async response =>
//TODO: CarModelDtoMin-t megcsinálni és azt lekérni a ComboBox-hoz! - J.
return AdminSignalRClient.GetAllAsync<List<Car>>(SignalRTags.GetAllCarsByProductId, async response =>
{
if (response.Status != SignalResponseStatus.Success || response.ResponseData == null)
{
@ -159,35 +189,13 @@
}
_cars.Clear();
_drivers.Clear();
_cars.AddRange(response.ResponseData);
_drivers.Clear();
_drivers.AddRange(_cars.DistinctBy(x => x.UserProductMappingId).Select(x => x.UserProductMapping));
await InvokeAsync(StateHasChanged);
}, [TiamConstClient.TransferProductId]).Forget();
await base.OnInitializedAsync();
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
// _transferToDriversGrid.BeginUpdate();
// _cars.AddRange((await AdminSignalRClient.GetAllAsync<List<Car>>(SignalRTags.GetAllCars))!);
// _transferToDriversGrid.EndUpdate();
// AdminSignalRClient.GetAllAsync<List<Car>>(SignalRTags.GetAllCars, response =>
// {
// if (response is { Status: SignalResponseStatus.Success, ResponseData: not null })
// _cars.AddRange(response.ResponseData);
// return Task.CompletedTask;
// }).Forget();
}
await base.OnAfterRenderAsync(firstRender);
}, [TiamConstClient.TransferProductId]);
}
private void DataItemChanged(GridDataItemChangedEventArgs<TransferToDriver> args)
@ -222,17 +230,4 @@
{
_logger.Debug($"DataItemDeleting");
}
void CustomizeEditModel(GridCustomizeEditModelEventArgs e)
{
if (!e.IsNew) return;
var newDriver = (TransferToDriver)e.EditModel;
newDriver.Id = Guid.NewGuid();
newDriver.CarId = Guid.Empty;
newDriver.LicencePlate = "";
newDriver.Car = new Car();
newDriver.Price = 0;
newDriver.TransferId = ParentData.Id;
}
}

View File

@ -17,6 +17,7 @@
@using AyCode.Models.Users
@using AyCode.Services.SignalRs
@using TIAM.Core.Consts
@using TIAM.Models.Dtos.Products
@inject IServiceProviderDataService ServiceProviderDataService
@inject IEnumerable<IAcLogWriterClientBase> LogWriters
@inject AdminSignalRClient AdminSignalRClient
@ -24,6 +25,7 @@
<UserProductMappingGrid Logger="_logger"
ContextIds="ContextIds?.Cast<object>().ToArray()"
DataSource="_userProductMapping"
GetAllMessageTag="GetAllTag"
SignalRClient="AdminSignalRClient"
PageSize="10"
@ -47,7 +49,7 @@
var userProductMappingEditModel = (UserProductMapping)context.EditModel;
}
<DxComboBox Data="@_products" TextFieldName="Name" ValueFieldName="Id" @bind-Value="userProductMappingEditModel.ProductId" ReadOnly="@(!_isNewState!.Value)"
<DxComboBox Data="@_productModelDtoNames" TextFieldName="Name" ValueFieldName="Id" @bind-Value="userProductMappingEditModel.ProductId" ReadOnly="@(!_isNewState!.Value)"
SearchFilterCondition="ListSearchFilterCondition.Contains" SearchMode="ListSearchMode.AutoSearch">
</DxComboBox>
</CellEditTemplate>
@ -62,7 +64,7 @@
var userProductMappingEditModel = (UserProductMapping)context.EditModel;
}
<DxComboBox Data="@_users" TextFieldName="EmailAddress" ValueFieldName="Id" @bind-Value="userProductMappingEditModel.UserId" ReadOnly="@(!_isNewState!.Value)"
<DxComboBox Data="@_userModelDtoEmails" TextFieldName="EmailAddress" ValueFieldName="Id" @bind-Value="userProductMappingEditModel.UserId" ReadOnly="@(!_isNewState!.Value)"
SearchFilterCondition="ListSearchFilterCondition.Contains" SearchMode="ListSearchMode.AutoSearch">
</DxComboBox>
</CellEditTemplate>
@ -99,22 +101,32 @@
private bool? _isNewState = null;
private LoggerClient<UserProductMappingGridComponent> _logger;
private static List<User> _users = [];
private static List<Product> _products = [];
private List<UserProductMapping> _userProductMapping = []; //TODO: kell a UserProductMappingDetailGridComponent és utána ez is static lehet! - J.
private static List<UserModelDtoEmail> _userModelDtoEmails = [];
private static List<ProductModelDtoName> _productModelDtoNames = [];
protected override async Task OnInitializedAsync()
{
_logger = new LoggerClient<UserProductMappingGridComponent>(LogWriters.ToArray());
AdminSignalRClient.GetAllIntoAsync(_products, SignalRTags.GetAllProducts).Forget();
AdminSignalRClient.GetAllIntoAsync(_users, SignalRTags.GetAllUsers).Forget();
await base.OnInitializedAsync();
}
protected override void OnAfterRender(bool firstRender)
{
if (firstRender)
{
AdminSignalRClient.GetAllIntoAsync(_userModelDtoEmails, SignalRTags.GetAllUserModelDtoEmails).Forget();
AdminSignalRClient.GetAllIntoAsync(_productModelDtoNames, SignalRTags.GetAllProductModelDtoNames).Forget();
}
base.OnAfterRender(firstRender);
}
void CustomizeEditModel(GridCustomizeEditModelEventArgs e)
{
_isNewState = e.IsNew;
if (!e.IsNew) return;
// var newProductMapping = new UserProductMapping

View File

@ -85,7 +85,13 @@ namespace TIAMSharedUI.Shared.Components.Cards
return _dataSource!;
}
set => _dataSourceParam = value;
set
{
_dataSourceParam = value;
if (_dataSource != null! && _dataSourceParam is List<TDataItem> workingReferenceList)
_dataSource.SetWorkingReferenceList(workingReferenceList);
}
}
protected override async Task OnInitializedAsync()
@ -125,7 +131,7 @@ namespace TIAMSharedUI.Shared.Components.Cards
if (firstRender)
{
if (_dataSourceParam.Count > 0) await _dataSource.LoadDataSource(_dataSourceParam);
if (_dataSourceParam != null!) await _dataSource.LoadDataSource(_dataSourceParam, true, true);
else _dataSource.LoadDataSourceAsync(true).Forget();
}
}

View File

@ -46,7 +46,7 @@ namespace TIAMSharedUI.Shared.Components.Grids
if (_dataSource != null! && _dataSource.FilterText != value)
{
_dataSource.FilterText = value;
LoadDataSourceAsync().Forget();
ReloadDataSourceAsync().Forget();
}
}
}
@ -89,7 +89,13 @@ namespace TIAMSharedUI.Shared.Components.Grids
return _dataSource!;
}
set => _dataSourceParam = value;
set
{
_dataSourceParam = value;
if (_dataSource != null! && _dataSourceParam is List<TDataItem> workingReferenceList)
_dataSource.SetWorkingReferenceList(workingReferenceList);
}
}
protected override async Task OnInitializedAsync()
@ -142,13 +148,13 @@ namespace TIAMSharedUI.Shared.Components.Grids
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
if (firstRender)
{
if (_dataSourceParam.Count > 0) await _dataSource.LoadDataSource(_dataSourceParam);
if (_dataSourceParam != null!) await _dataSource.LoadDataSource(_dataSourceParam, true, true);
else _dataSource.LoadDataSourceAsync(true).Forget();
}
await base.OnAfterRenderAsync(firstRender);
}
public Task AddDataItem(TDataItem dataItem)
@ -326,7 +332,7 @@ namespace TIAMSharedUI.Shared.Components.Grids
return _dataSource.Remove(dataItem, true);
}
public Task LoadDataSourceAsync()
public Task ReloadDataSourceAsync()
{
return _dataSource.LoadDataSourceAsync(false);
}

View File

@ -19,6 +19,8 @@ using AyCode.Utils.Extensions;
using TIAM.Entities.Drivers;
using TIAM.Services;
using TIAM.Entities.Products;
using TIAM.Models.Dtos.Products;
using TIAM.Models.Dtos.Users;
namespace TIAMWebApp.Server.Controllers
{
@ -455,6 +457,15 @@ namespace TIAMWebApp.Server.Controllers
return products;
}
[NonAction]
[SignalR(SignalRTags.GetAllProductModelDtoNames)]
public async Task<List<ProductModelDtoName>> GetProductModelDtoNames()
{
_logger.Info("GetUserModelDtoEmails called");
return await adminDal.GetProductModelDtoNamesAsync();
}
[AllowAnonymous]
[HttpPost]
[Route(APIUrls.GetProductByIdRouteName)]

View File

@ -371,11 +371,17 @@ namespace TIAMWebApp.Server.Controllers
public async Task<List<User>> GetAllUsers()
{
_logger.Info("GetAllUsers called");
//var users = await _userDal.Ctx.Users.ToListAsync();//.GetUsersAsync();
//return users;
return await userDal.GetUsersAsync();
}
[NonAction]
[SignalR(SignalRTags.GetAllUserModelDtoEmails)]
public async Task<List<UserModelDtoEmail>> GetUserModelDtoEmails()
{
_logger.Info("GetUserModelDtoEmails called");
return await userDal.GetUserModelDtoEmailsAsync();
}
[AllowAnonymous]
[HttpGet]
[Route(APIUrls.GetUserByEmailRouteName + "/{email}")]