improvements, fixes, etc...

This commit is contained in:
Loretta 2024-07-04 19:54:00 +02:00
parent 2ca48c4ae8
commit dd6d9f17b7
7 changed files with 39 additions and 37 deletions

View File

@ -138,6 +138,7 @@ namespace TIAM.Database.DataLayers.Admins
#region TransferToDriver
public Task<TransferToDriver?> GetTransferToDriverByIdAsync(Guid transferToDriverId, bool autoInclude = true) => SessionAsync(ctx => ctx.GetTransferToDriverById(transferToDriverId, autoInclude));
public Task<List<TransferToDriver>> GetTransferToDriversByUpmId(Guid upmId, bool autoInclude = true) => SessionAsync(ctx => ctx.GetTransferToDriversByUpmId(upmId, autoInclude).ToList());
public Task<List<TransferToDriver>> GetTransferToDriversByTransferIdAsync(Guid transferId, bool autoInclude = true) => SessionAsync(ctx => ctx.GetTransferToDriversByTransferId(transferId, autoInclude).ToList());
public Task<bool> AddTransferToDriverAsync(TransferToDriver transferToDriver) => TransactionAsync(ctx => ctx.AddTransferToDriver(transferToDriver));
@ -251,8 +252,7 @@ namespace TIAM.Database.DataLayers.Admins
#region UserProductMapping
public Task<bool> AddUserProductMappingAsync(UserProductMapping userProductMapping)
=> TransactionAsync(ctx => ctx.AddUserProductMapping(userProductMapping));
public Task<bool> AddUserProductMappingAsync(UserProductMapping userProductMapping) => TransactionAsync(ctx => ctx.AddUserProductMapping(userProductMapping));
public async Task<UserProductMapping?> AddUserProductMappingAsync(Guid userProductMappingId, Guid userId, Guid productId, int permissions = 1, UserProductJsonDetailModel? userProductToCars = null)
{
@ -643,7 +643,7 @@ namespace TIAM.Database.DataLayers.Admins
#region UserProductMappings
//24 . (IServiceProviderDataService) Remove Assigned Users By Product Id
public Task RemoveUserProductMappingsByContextId(Guid productId)
public Task RemoveUserProductMappingsByProductId(Guid productId)
{
using (var transaction = Context.Database.BeginTransaction())
{

View File

@ -65,5 +65,7 @@ namespace TIAM.Database.DbContexts.ServiceProviders
//modelBuilder.Entity<TransferDestinationToProduct>().HasOne(e => e.TransferDestination);
//modelBuilder.Entity<TransferDestinationToProduct>().Navigation(e => e.TransferDestination).AutoInclude(true);
}
public DbSet<TransferToDriver> TransferToDrivers { get; set; }
}
}

View File

@ -16,6 +16,9 @@ public static class TransferToDriverDbSetExtensions
public static IQueryable<TransferToDriver> GetTransferToDriversByTransferId(this ITransferToDriverDbSet ctx, Guid transferId, bool autoInclude = true)
=> ctx.TransferToDrivers.Where(x => x.TransferId == transferId);
public static IQueryable<TransferToDriver> GetTransferToDriversByUpmId(this ITransferToDriverDbSet ctx, Guid upmId, bool autoInclude = true)
=> ctx.TransferToDrivers.Where(x => x.UserProductMappingId == upmId);
public static bool AddTransferToDriver(this ITransferDbSet ctx, TransferToDriver transferToDriver)
{
ctx.UpdateTransferStatus(transferToDriver.TransferId, TransferStatusType.AssignedToDriver);

View File

@ -1,9 +1,10 @@
using Microsoft.EntityFrameworkCore;
using TIAM.Database.DbSets.Transfers;
using TIAM.Entities.Users;
namespace TIAM.Database.DbSets.Users;
public interface IUserProductMappingDbSet
public interface IUserProductMappingDbSet : ITransferToDriverDbSet
{
public DbSet<UserProductMapping> UserProductMappings { get; set; }
}

View File

@ -1,5 +1,6 @@
using AyCode.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using TIAM.Database.DbSets.Transfers;
using TIAM.Entities.Drivers;
using TIAM.Entities.Users;
@ -69,6 +70,9 @@ public static class UserProductMappingDbSetExtensions
{
if (userProductMapping == null) return false;
if (ctx.GetTransferToDriversByUpmId(userProductMapping.Id).Any())
return false;
return ctx.UserProductMappings.Remove(userProductMapping).State == EntityState.Deleted;
}

View File

@ -12,6 +12,7 @@
@using AyCode.Core.Loggers
@using AyCode.Services.Loggers
@using AyCode.Core
@using AyCode.Core.Enums
@using AyCode.Core.Helpers
@using AyCode.Models.Users
@using AyCode.Services.SignalRs
@ -31,7 +32,8 @@
EditMode="GridEditMode.EditRow"
ColumnResizeMode="GridColumnResizeMode.NextColumn"
OnGridEditModelSaving="OnGridEditModelSaving"
DetailExpandButtonDisplayMode="DetailExpandButtonDisplayMode">
DetailExpandButtonDisplayMode="DetailExpandButtonDisplayMode"
OnGridItemChanged="OnGridItemChanged">
<Columns>
<DxGridCommandColumn Width="150" MinWidth="150" Visible="CommandColumnVisible" NewButtonVisible="NewButtonVisible" EditButtonVisible="EditButtonVisible" DeleteButtonVisible="DeleteButtonVisible" FixedPosition="GridColumnFixedPosition.Left" />
<DxGridDataColumn FieldName="Id" ShowInColumnChooser="AcDomain.IsDeveloperVersion" Visible="AcDomain.IsDeveloperVersion" DisplayFormat="N" />
@ -79,25 +81,6 @@
</DxTabs>
}
</DetailRowTemplate>
@* <EditFormTemplate Context="userEditFormContext">
@{
var userProduct = (UserProductMapping)userEditFormContext.EditModel;
}
<DxFormLayout CssClass="w-100">
<DxFormLayoutItem Caption="User" ColSpanMd="4">
@userEditFormContext.GetEditor("UserId")
</DxFormLayoutItem>
<DxFormLayoutItem Caption="Product:" ColSpanMd="4">
<DxComboBox Data="@_availableProducts" TextFieldName="Name" @bind-Value="((UserProductMapping)userEditFormContext.EditModel).ProductId" />
</DxFormLayoutItem>
<DxFormLayoutItem Caption="Permissions" ColSpanMd="4">
@userEditFormContext.GetEditor("Permissions")
</DxFormLayoutItem>
</DxFormLayout>
</EditFormTemplate>
*@
</UserProductMappingGrid>
@code {
@ -172,7 +155,15 @@
private void OnGridEditModelSaving(GridEditModelSavingEventArgs e)
{
_isNewState = false;
_isNewState = e.IsNew;
}
private void OnGridItemChanged(GridDataItemChangedEventArgs<UserProductMapping> args)
{
// if (args.TrackingState != TrackingState.Add) return;
// args.CancelStateChangeInvoke = true;
// StateHasChanged();
}
}

View File

@ -177,20 +177,20 @@ namespace TIAMWebApp.Server.Controllers
[Tags("Finished", "ServiceProvider")]
[EndpointSummary("Create assigned user to product")]
[SignalR(SignalRTags.CreateUserProductMapping)]
public async Task<IActionResult> CreateUserProductMapping(UserProductMapping userProductMapping)
public async Task<UserProductMapping?> CreateUserProductMapping(UserProductMapping userProductMapping)
{
if (userProductMapping.ProductId == Guid.Empty || userProductMapping.UserId == Guid.Empty)
{
return BadRequest("Invalid request");
}
else
{
_logger.Info($@"CreateUserProductMappings called with ownerId: {userProductMapping.ProductId}, {userProductMapping.UserId}");
_logger.Info($@"CreateUserProductMappings called with ownerId: {userProductMapping.ProductId}, {userProductMapping.UserId}");
var result = await adminDal.AddUserProductMappingAsync(userProductMapping);
return Ok(result);
if (userProductMapping.ProductId.IsNullOrEmpty() || userProductMapping.UserId.IsNullOrEmpty())
{
_logger.Error(@"CreateUserProductMappings; (userProductMapping.ProductId.IsNullOrEmpty() || userProductMapping.UserId.IsNullOrEmpty())");
return null;//BadRequest("Invalid request");
}
var result = await adminDal.AddUserProductMappingAsync(userProductMapping);
//TODO: A userProductMapping-nem include-olja be a User-t és a Product-ot automatikusan, ezért kell újra lekérni! TransactionAsync T-t adjon vissza, ne csak bool-t... - J.
return result ? adminDal.GetUserProductMappingById(userProductMapping.Id) : null; //Ok(result);
}
[AllowAnonymous]
@ -203,7 +203,8 @@ namespace TIAMWebApp.Server.Controllers
var result = await adminDal.UpdateUserProductMappingAsync(userProductMapping);
return result == null ? string.Empty : userProductMapping.ToJson();
//TODO: A userProductMapping-nem include-olja be a User-t és a Product-ot automatikusan, ezért kell újra lekérni! TransactionAsync T-t adjon vissza, ne csak bool-t... - J.
return result == null ? string.Empty : adminDal.GetUserProductMappingById(userProductMapping.Id).ToJson();
}
[AllowAnonymous]