TransferToDriver ComboBox, improvements, fixes, etc...
This commit is contained in:
parent
7c45e07899
commit
0a02411eaf
|
|
@ -2,6 +2,11 @@
|
|||
|
||||
namespace TIAM.Core.Consts;
|
||||
|
||||
public static class TiamConstClient
|
||||
{
|
||||
public static Guid TransferProductId = Guid.Parse("814b5495-c2e9-4f1d-a73f-37cd5d353078");
|
||||
}
|
||||
|
||||
public class TiamConst : AcConst
|
||||
{
|
||||
public static string ProjectIdString = "684f34d1-163a-4077-918f-a9d9df5ce789";
|
||||
|
|
|
|||
|
|
@ -34,9 +34,10 @@ 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));
|
||||
public List<Car> GetCarByUserProductMappingId(Guid userProductMappingId) => Session(ctx => ctx.Cars.Where(x => x.UserProductMappingId == userProductMappingId).ToList());
|
||||
public Task<List<Car>> GetCarByUserProductMappingIdAsync(Guid userProductMappingId) => SessionAsync(ctx => ctx.Cars.Where(x => x.UserProductMappingId == userProductMappingId).ToList());
|
||||
public Task<List<Car>> GetCarsByUserProductMappingIdAsync(Guid userProductMappingId) => SessionAsync(ctx => ctx.Cars.Where(x => x.UserProductMappingId == userProductMappingId).ToList());
|
||||
public Task<bool> AddCarAsync(Car car) => TransactionAsync(ctx => ctx.Cars.Add(car).State == EntityState.Added);
|
||||
public Task<bool> UpdateCarAsync(Car car) => TransactionAsync(ctx => ctx.Cars.Update(car).State == EntityState.Modified);
|
||||
public Task<bool> RemoveCarAsync(Car car) => TransactionAsync(ctx => ctx.Cars.Remove(car).State == EntityState.Deleted);
|
||||
|
|
@ -86,10 +87,31 @@ namespace TIAM.Database.DataLayers.Admins
|
|||
public Task<List<TransferToDriver>> GetTransferToDriversByTransferIdAsync(Guid transferId, bool autoInclude = false) => SessionAsync(ctx => ctx.TransferToDrivers.Where(x => x.TransferId == transferId).ToList());
|
||||
|
||||
public Task<bool> AddTransferToDriverAsync(TransferToDriver transferToDriver) => TransactionAsync(ctx => ctx.TransferToDrivers.Add(transferToDriver).State == EntityState.Added);
|
||||
public Task<bool> UpdateTransferToDriverAsync(TransferToDriver transferToDriver) => TransactionAsync(ctx => ctx.TransferToDrivers.Update(transferToDriver).State == EntityState.Modified);
|
||||
public async Task<TransferToDriver?> UpdateTransferToDriverAsync(TransferToDriver transferToDriver)
|
||||
{
|
||||
var transferToDriverId = transferToDriver.Id;
|
||||
var result = await TransactionAsync(ctx =>
|
||||
{
|
||||
var transferToDriver2 = ctx.TransferToDrivers.FirstOrDefault(x => x.Id == transferToDriverId)!;
|
||||
transferToDriver2.CarId = transferToDriver.CarId;
|
||||
transferToDriver2.LicencePlate = transferToDriver.LicencePlate;
|
||||
transferToDriver2.UserProductMappingId = transferToDriver.UserProductMappingId;
|
||||
transferToDriver2.TransferId = transferToDriver.TransferId;
|
||||
|
||||
return ctx.TransferToDrivers.Update(transferToDriver2).State == EntityState.Modified;
|
||||
});
|
||||
|
||||
return result ? transferToDriver : null;
|
||||
}
|
||||
|
||||
public Task<bool> RemoveTransferToDriverAsync(TransferToDriver transferToDriver) => TransactionAsync(ctx => ctx.TransferToDrivers.Remove(transferToDriver).State == EntityState.Deleted);
|
||||
#endregion TransferToDriver
|
||||
|
||||
#region Drivers
|
||||
|
||||
public Task<List<UserProductMapping>> GetTAllDrivers() => SessionAsync(ctx => ctx.UserProductMappings.Where(x => ctx.Cars.Any(car => car.UserProductMappingId == x.Id)).ToList());
|
||||
public Task<List<UserProductMapping>> GetTAllDriversByProductId(Guid productId) => SessionAsync(ctx => ctx.UserProductMappings.Where(x => x.ProductId == productId && ctx.Cars.Any(car => car.UserProductMappingId == x.Id)).ToList());
|
||||
#endregion Drivers
|
||||
#region TransferDestinationToProduct
|
||||
public TransferDestinationToProduct? GetTransferDestinationToProductById(Guid transferDestinationToProductId) => Session(ctx=>ctx.GetTransferDestinationToProductById(transferDestinationToProductId));
|
||||
public Task<TransferDestinationToProduct?> GetTransferDestinationToProductByIdAsync(Guid transferDestinationToProductId) => SessionAsync(ctx=>ctx.GetTransferDestinationToProductById(transferDestinationToProductId));
|
||||
|
|
|
|||
|
|
@ -26,18 +26,19 @@ public class SignalRTags : AcSignalRTags
|
|||
public const int RemoveCompany = 18;
|
||||
|
||||
public const int GetTransferDriver = 22;
|
||||
//public const int GetTransferToDrivers = 23;
|
||||
public const int GetTransferDriversByTransferId = 24;
|
||||
public const int AddTransferToDriver = 25;
|
||||
public const int UpdateTransferToDriver = 26;
|
||||
public const int RemoveTransferToDriver = 27;
|
||||
public const int GetAllDrivers = 23;
|
||||
public const int GetAllDriversByProductId = 24;
|
||||
public const int GetTransferDriversByTransferId = 25;
|
||||
public const int AddTransferToDriver = 26;
|
||||
public const int UpdateTransferToDriver = 27;
|
||||
public const int RemoveTransferToDriver = 28;
|
||||
|
||||
public const int GetAddress = 28;
|
||||
//public const int GetAddresses = 29;
|
||||
public const int GetAddressesByContextId = 30;
|
||||
public const int UpdateAddress = 31;
|
||||
//public const int AddAddress = 32;
|
||||
//public const int RemoveAddress = 33;
|
||||
public const int GetAddress = 29;
|
||||
//public const int GetAddresses = 30;
|
||||
public const int GetAddressesByContextId = 31;
|
||||
public const int UpdateAddress = 32;
|
||||
//public const int AddAddress = 33;
|
||||
//public const int RemoveAddress = 34;
|
||||
|
||||
public const int GetProfileById = 35;
|
||||
//public const int GetProfiles = 36;
|
||||
|
|
@ -61,6 +62,7 @@ public class SignalRTags : AcSignalRTags
|
|||
public const int UpdateCar = 52;
|
||||
public const int DeleteCar = 53;
|
||||
public const int GetAllCars = 54;
|
||||
public const int GetAllCarsByProductId = 55;
|
||||
|
||||
public const int GetMessagesByContextId = 60;
|
||||
public const int GetAllMessages = 61;
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
@using TIAMWebApp.Shared.Application.Models.PageModels
|
||||
@using TIAMWebApp.Shared.Application.Utility
|
||||
@using AyCode.Services.Loggers
|
||||
@using TIAM.Core.Consts
|
||||
@layout AdminLayout
|
||||
@inject IEnumerable<IAcLogWriterClientBase> LogWriters
|
||||
@inject IStringLocalizer<TIAMResources> Localizer
|
||||
|
|
@ -37,7 +38,7 @@
|
|||
Click="ColumnChooserButton_Click" />
|
||||
</div>
|
||||
|
||||
<DriverGridComponent DetailExpandButtonDisplayMode="GridDetailExpandButtonDisplayMode.Auto" ContextId="Guid.Parse(TransferProductId)" GetAllTag="SignalRTags.GetUserProductMappingsByProductId"></DriverGridComponent>
|
||||
<DriverGridComponent DetailExpandButtonDisplayMode="GridDetailExpandButtonDisplayMode.Auto" ContextId="TiamConstClient.TransferProductId" GetAllTag="SignalRTags.GetUserProductMappingsByProductId"></DriverGridComponent>
|
||||
|
||||
</div>
|
||||
|
||||
|
|
@ -54,9 +55,7 @@
|
|||
@code {
|
||||
private LoggerClient<ManageUserProductMappings> _logger;
|
||||
//public UserModelDtoDetail UserModelDtoDetail = new();
|
||||
|
||||
private string TransferProductId = "814b5495-c2e9-4f1d-a73f-37cd5d353078";
|
||||
|
||||
|
||||
|
||||
IGrid Grid { get; set; }
|
||||
//object? MasterGridData { get; set; }
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@
|
|||
@using AyCode.Core
|
||||
@using AyCode.Core.Helpers
|
||||
@using AyCode.Services.SignalRs
|
||||
@using AyCode.Utils.Extensions
|
||||
@using TIAM.Core.Consts
|
||||
@using TIAM.Entities.Users
|
||||
@using TIAM.Services
|
||||
@inject IUserDataService UserDataService
|
||||
|
|
@ -20,7 +22,7 @@
|
|||
@inject AdminSignalRClient AdminSignalRClient;
|
||||
|
||||
<TransferToDriversDetailGrid @ref="_transferToDriversGrid"
|
||||
ContextIds="@(ContextId.IsNullOrEmpty() ? throw new InvalidDataException($"ContextId.IsNullOrEmpty(); ContextId: {ContextId}") : [ContextId.Value])"
|
||||
ContextIds="@(ContextId.IsNullOrEmpty() ? throw new InvalidDataException($"ContextId.IsNullOrEmpty(); ContextId: {ContextId}") : [ContextId])"
|
||||
DataSource="ParentData.TransferToDrivers"
|
||||
Logger="_logger"
|
||||
SignalRClient="AdminSignalRClient"
|
||||
|
|
@ -33,26 +35,99 @@
|
|||
ColumnResizeMode="GridColumnResizeMode.NextColumn">
|
||||
<Columns>
|
||||
<DxGridCommandColumn Width="150" MinWidth="150" FixedPosition="GridColumnFixedPosition.Left" />
|
||||
<DxGridDataColumn FieldName="CarId" />
|
||||
@*<DxGridDataColumn FieldName="CarId">
|
||||
<DxGridDataColumn FieldName="Id" ShowInColumnChooser="AcDomain.IsDeveloperVersion" Visible="AcDomain.IsDeveloperVersion" DisplayFormat="N" />
|
||||
@{
|
||||
var userEmailFieldName = $"{nameof(TransferToDriver.UserProductMapping)}.{nameof(UserProductMapping.User)}.{nameof(User.EmailAddress)}";
|
||||
var userEmailFieldName2 = $"{nameof(UserProductMapping.User)}.{nameof(User.EmailAddress)}";
|
||||
}
|
||||
<DxGridDataColumn FieldName="@userEmailFieldName" Caption="Driver" SortIndex="0">
|
||||
<CellEditTemplate>
|
||||
@{
|
||||
var transferToDriverDataItem = (TransferToDriver)context.DataItem;
|
||||
var transferToDriverEditModel = (TransferToDriver)context.EditModel;
|
||||
}
|
||||
|
||||
<DxComboBox Data="@_drivers.Where(x => x.ProductId == (transferToDriverDataItem?.UserProductMapping.ProductId ?? TiamConstClient.TransferProductId))"
|
||||
TData="@UserProductMapping"
|
||||
TValue="@UserProductMapping"
|
||||
TextFieldName="@userEmailFieldName2"
|
||||
Value="@_drivers.FirstOrDefault(x => x.Id == transferToDriverEditModel.UserProductMappingId)"
|
||||
ValueChanged="v => transferToDriverEditModel.UserProductMappingId = v.Id"
|
||||
SearchFilterCondition="ListSearchFilterCondition.Contains"
|
||||
SearchMode="ListSearchMode.AutoSearch">
|
||||
<Columns>
|
||||
@* <DxListEditorColumn FieldName="Id"/> *@
|
||||
<DxListEditorColumn FieldName="@userEmailFieldName2" Caption="Driver email" />
|
||||
</Columns>
|
||||
</DxComboBox>
|
||||
|
||||
</CellEditTemplate>
|
||||
</DxGridDataColumn>
|
||||
|
||||
<DxGridDataColumn FieldName="CarId" Caption="Car">
|
||||
<CellDisplayTemplate>
|
||||
@{
|
||||
var transferToDriver = (TransferToDriver)context.DataItem;
|
||||
<text>@_cars.FirstOrDefault(x => x.Id == transferToDriver.CarId)?.LicencePlate</text>
|
||||
}
|
||||
</CellDisplayTemplate>
|
||||
<CellEditTemplate>
|
||||
@{
|
||||
var transferToDriverEditModel = (TransferToDriver)context.EditModel;
|
||||
}
|
||||
|
||||
<DxComboBox Data="@_cars.Where(x=>x.UserProductMappingId == transferToDriverEditModel.UserProductMappingId)"
|
||||
TData="@Car"
|
||||
TValue="@Car"
|
||||
TextFieldName="LicencePlate"
|
||||
Value="@_cars.FirstOrDefault(x => x.Id == transferToDriverEditModel.CarId)"
|
||||
ValueChanged="v => { transferToDriverEditModel.CarId = v?.Id ?? Guid.Empty; transferToDriverEditModel.LicencePlate = v?.LicencePlate ?? string.Empty; }"
|
||||
SearchFilterCondition="ListSearchFilterCondition.Contains"
|
||||
SearchMode="ListSearchMode.AutoSearch">
|
||||
<Columns>
|
||||
@* <DxListEditorColumn FieldName="Id"/> *@
|
||||
<DxListEditorColumn FieldName="LicencePlate" Caption="LicencePlate"/>
|
||||
<DxListEditorColumn FieldName="Manufacture" Caption="Manufacture" />
|
||||
<DxListEditorColumn FieldName="CarModel" Caption="Model" />
|
||||
<DxListEditorColumn FieldName="SeatNumber" Caption="SeatNumber" />
|
||||
</Columns>
|
||||
</DxComboBox>
|
||||
</CellEditTemplate>
|
||||
</DxGridDataColumn>
|
||||
|
||||
@* <DxGridDataColumn FieldName="CarId">
|
||||
<CellEditTemplate>
|
||||
@{
|
||||
var transferToDriverId = ((TransferToDriver)context.DataItem).Id;
|
||||
}
|
||||
|
||||
<DxDropDownBox QueryDisplayText="QueryText"
|
||||
DropDownWidthMode="DropDownWidthMode.ContentWidth"
|
||||
ClearButtonDisplayMode="DataEditorClearButtonDisplayMode.Auto"
|
||||
NullText="Select a car...">
|
||||
<DropDownBodyTemplate>
|
||||
<CarDetailGridComponent GetAllTag="SignalRTags.GetAllCars"/>
|
||||
</DropDownBodyTemplate>
|
||||
</DxDropDownBox>
|
||||
</CellEditTemplate>
|
||||
</DxGridDataColumn>
|
||||
*@
|
||||
@* <DxGridDataColumn FieldName="CarId">
|
||||
<EditSettings>
|
||||
<DxComboBoxSettings Data="_cars" SearchMode="ListSearchMode.AutoSearch" Key
|
||||
<DxComboBoxSettings Data="_cars" SearchMode="ListSearchMode.AutoSearch"
|
||||
ValueFieldName="Id"
|
||||
TextFieldName="LicencePlate" />
|
||||
</EditSettings>
|
||||
</DxGridDataColumn>*@
|
||||
|
||||
|
||||
<DxGridDataColumn FieldName="Price" />
|
||||
<DxGridDataColumn FieldName="Id" ShowInColumnChooser="AcDomain.IsDeveloperVersion" Visible="AcDomain.IsDeveloperVersion" DisplayFormat="N" />
|
||||
@{
|
||||
var userEmailFieldName = $"{nameof(TransferToDriver.UserProductMapping)}.{nameof(UserProductMapping.User)}.{nameof(User.EmailAddress)}";
|
||||
}
|
||||
<DxGridDataColumn FieldName="@userEmailFieldName" Caption="User email" SortIndex="0" ReadOnly="true" />
|
||||
<DxGridDataColumn FieldName="LicencePlate" ReadOnly="true" />
|
||||
@* <DxGridDataColumn FieldName="LicencePlate" ReadOnly="true" /> *@
|
||||
</Columns>
|
||||
</TransferToDriversDetailGrid>
|
||||
|
||||
@code {
|
||||
[Parameter] public Guid? ContextId { get; set; }
|
||||
[Parameter] public Guid ContextId { get; set; }
|
||||
[Parameter] public ITransferToDriversRelation ParentData { get; set; } = null!;
|
||||
[Parameter] public EventCallback<TransferToDriver> OnTransferToDriverChanged { get; set; }
|
||||
|
||||
|
|
@ -60,6 +135,7 @@
|
|||
private LoggerClient<TransferToDriverGridComponent> _logger = null!;
|
||||
|
||||
private List<Car> _cars = [];
|
||||
private List<UserProductMapping> _drivers = [];
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
|
|
@ -67,7 +143,22 @@
|
|||
|
||||
_logger.Info($"DetailGridData: {ParentData.TransferToDrivers.Count}");
|
||||
|
||||
//_cars.AddRange((await AdminSignalRClient.GetAllAsync<List<Car>>(SignalRTags.GetAllCars))!);
|
||||
//EZ NEM JÓ, FILTER-ELNI KELL A PRODUCT-RA!!! - J.
|
||||
_cars.AddRange((await AdminSignalRClient.GetAllAsync<List<Car>>(SignalRTags.GetAllCarsByProductId, TiamConstClient.TransferProductId))!);
|
||||
// AdminSignalRClient.GetAllAsync<List<Car>>(SignalRTags.GetAllCars, response =>
|
||||
// {
|
||||
// _cars.AddRange(response.ResponseData!);
|
||||
// return Task.CompletedTask;
|
||||
// }).Forget();
|
||||
|
||||
//EZ NEM JÓ, FILTER-ELNI KELL A PRODUCT-RA!!! - J.
|
||||
_drivers.AddRange(_cars.DistinctBy(x => x.UserProductMappingId).Select(x => x.UserProductMapping));
|
||||
//_drivers.AddRange((await AdminSignalRClient.GetAllAsync<List<UserProductMapping>>(SignalRTags.GetAllDrivers))!);
|
||||
// AdminSignalRClient.GetAllAsync<List<UserProductMapping>>(SignalRTags.GetAllDrivers, response =>
|
||||
// {
|
||||
// _drivers.AddRange(response.ResponseData!);
|
||||
// return Task.CompletedTask;
|
||||
// }).Forget();
|
||||
|
||||
await base.OnInitializedAsync();
|
||||
}
|
||||
|
|
@ -97,12 +188,28 @@
|
|||
OnTransferToDriverChanged.InvokeAsync(args.DataItem);
|
||||
}
|
||||
|
||||
private void DataItemSaving(GridEditModelSavingEventArgs obj)
|
||||
private void DataItemSaving(GridEditModelSavingEventArgs args)
|
||||
{
|
||||
_logger.Debug($"DataItemSaving");
|
||||
|
||||
var transferToDriverEditModel = (TransferToDriver)args.EditModel;
|
||||
|
||||
if (transferToDriverEditModel.UserProductMappingId.IsNullOrEmpty() || transferToDriverEditModel.CarId.IsNullOrEmpty() ||
|
||||
transferToDriverEditModel.LicencePlate.IsNullOrWhiteSpace() || transferToDriverEditModel.Price <= 0)
|
||||
{
|
||||
args.Cancel = true;
|
||||
_logger.Error($"transferToDriverEditModel.UserProductMappingId.IsNullOrEmpty() || transferToDriverEditModel.CarId.IsNullOrEmpty() || transferToDriverEditModel.LicencePlate.IsNullOrWhiteSpace() || transferToDriverEditModel.Price <= 0");
|
||||
}
|
||||
|
||||
if (args.IsNew)
|
||||
{
|
||||
transferToDriverEditModel.TransferId = ContextId;
|
||||
transferToDriverEditModel.Id = Guid.NewGuid();
|
||||
transferToDriverEditModel.Car = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void DataItemDeleting(GridDataItemDeletingEventArgs obj)
|
||||
private void DataItemDeleting(GridDataItemDeletingEventArgs args)
|
||||
{
|
||||
_logger.Debug($"DataItemDeleting");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -285,7 +285,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
{
|
||||
_logger.Info($@"GetCarsForUserProductMapping called with userProductMappingId: {userProductMappingId}");
|
||||
|
||||
var cars = await adminDal.GetCarByUserProductMappingIdAsync(userProductMappingId);
|
||||
var cars = await adminDal.GetCarsByUserProductMappingIdAsync(userProductMappingId);
|
||||
return cars;
|
||||
}
|
||||
|
||||
|
|
@ -295,12 +295,24 @@ namespace TIAMWebApp.Server.Controllers
|
|||
[SignalR(SignalRTags.GetAllCars)]
|
||||
public async Task<List<Car>> GetAllCars()
|
||||
{
|
||||
_logger.Info($@"GetAllCars called ");
|
||||
_logger.Info($@"GetAllCars called");
|
||||
|
||||
var cars = await adminDal.GetAllCarsAsync();
|
||||
return cars;
|
||||
}
|
||||
|
||||
//[AllowAnonymous]
|
||||
//[HttpGet]
|
||||
//[Route(APIUrls.GetAllCarsRouteName)]
|
||||
[SignalR(SignalRTags.GetAllCarsByProductId)]
|
||||
public async Task<List<Car>> GetAllCarsByProductId(Guid productId)
|
||||
{
|
||||
_logger.Info($@"GetAllCarsByProductId called");
|
||||
|
||||
var cars = await adminDal.GetAllCarsbyProductIdAsync(productId);
|
||||
return cars;
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
[ApiExplorerSettings(IgnoreApi = true)]
|
||||
private async Task<bool> CarDataChanging(Car car, TrackingState trackingState)
|
||||
|
|
|
|||
|
|
@ -582,6 +582,26 @@ namespace TIAMWebApp.Server.Controllers
|
|||
return transferToModify;
|
||||
}
|
||||
|
||||
//[Authorize]
|
||||
//[HttpGet]
|
||||
//[Route(APIUrls.GetTransferDriverRouteName)]
|
||||
[SignalR(SignalRTags.GetAllDrivers)]
|
||||
public async Task<List<UserProductMapping>> GetAllDrivers()
|
||||
{
|
||||
var result = await _adminDal.GetTAllDrivers();
|
||||
return result;
|
||||
}
|
||||
|
||||
//[Authorize]
|
||||
//[HttpGet]
|
||||
//[Route(APIUrls.GetTransferDriverRouteName)]
|
||||
[SignalR(SignalRTags.GetAllDriversByProductId)]
|
||||
public async Task<List<UserProductMapping>> GetAllDriversByProductId(Guid productId)
|
||||
{
|
||||
var result = await _adminDal.GetTAllDriversByProductId(productId);
|
||||
return result;
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[HttpGet]
|
||||
[Route(APIUrls.GetTransferDriverRouteName)]
|
||||
|
|
@ -619,7 +639,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
public async Task<TransferToDriver?> UpdateTransferDriver([FromBody] TransferToDriver transferToDriver)
|
||||
{
|
||||
var result = await _adminDal.UpdateTransferToDriverAsync(transferToDriver);
|
||||
return result ? transferToDriver : null;
|
||||
return result; // ? transferToDriver : null;
|
||||
}
|
||||
|
||||
//[Authorize]
|
||||
|
|
|
|||
Loading…
Reference in New Issue