TransferStatusType set to AssignedToDriver; imrpovements, fixes, etc...

This commit is contained in:
Loretta 2024-06-28 08:58:20 +02:00
parent 6cd675d76d
commit 372de428d6
11 changed files with 115 additions and 21 deletions

View File

@ -23,6 +23,7 @@ using TIAM.Entities.Transfers;
using TIAM.Entities.Users;
using TIAM.Models.Dtos.Products;
using AyCode.Database.DbSets.Profiles;
using TIAM.Database.DbSets.Drivers;
namespace TIAM.Database.DataLayers.Admins
{
@ -66,7 +67,7 @@ namespace TIAM.Database.DataLayers.Admins
return ctx.UpdateTransfer(transfer);
});
public Task<bool> RemoveTransferAsync(Transfer transfer) => TransactionAsync(ctx => ctx.RemoveTransfer(transfer));
public Task<bool> RemoveTransferAsync(Transfer transfer) => RemoveTransferAsync(transfer.Id);
public Task<bool> RemoveTransferAsync(Guid transferId) => TransactionAsync(ctx => ctx.RemoveTransfer(transferId));
#endregion Transfer
@ -78,15 +79,15 @@ namespace TIAM.Database.DataLayers.Admins
public Task<bool> AddTransferDestinationAsync(TransferDestination transferDestination) => TransactionAsync(ctx => ctx.AddTransferDestination(transferDestination));
public Task<bool> UpdateTransferDestinationAsync(TransferDestination transferDestination) => TransactionAsync(ctx => ctx.UpdateTransferDestination(transferDestination));
public Task<bool> RemoveTransferDestinationAsync(TransferDestination transferDestination, bool removeAddress) => TransactionAsync(ctx => ctx.RemoveTransferDestination(transferDestination.Id, removeAddress));
public Task<bool> RemoveTransferDestinationAsync(TransferDestination transferDestination, bool removeAddress) => RemoveTransferDestinationAsync(transferDestination.Id, removeAddress);
public Task<bool> RemoveTransferDestinationAsync(Guid transferDestinationId, bool removeAddress) => TransactionAsync(ctx => ctx.RemoveTransferDestination(transferDestinationId, removeAddress));
#endregion TransferDestination
#region TransferToDriver
public Task<TransferToDriver?> GetTransferToDriverByIdAsync(Guid transferToDriverId, bool autoInclude = false) => SessionAsync(ctx => ctx.TransferToDrivers.FirstOrDefault(x=>x.Id == transferToDriverId));
public Task<List<TransferToDriver>> GetTransferToDriversByTransferIdAsync(Guid transferId, bool autoInclude = false) => SessionAsync(ctx => ctx.TransferToDrivers.Where(x => x.TransferId == transferId).ToList());
public Task<TransferToDriver?> GetTransferToDriverByIdAsync(Guid transferToDriverId, bool autoInclude = true) => SessionAsync(ctx => ctx.GetTransferToDriverById(transferToDriverId, autoInclude));
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.TransferToDrivers.Add(transferToDriver).State == EntityState.Added);
public Task<bool> AddTransferToDriverAsync(TransferToDriver transferToDriver) => TransactionAsync(ctx => ctx.AddTransferToDriver(transferToDriver));
public async Task<TransferToDriver?> UpdateTransferToDriverAsync(TransferToDriver transferToDriver)
{
var transferToDriverId = transferToDriver.Id;
@ -104,14 +105,14 @@ namespace TIAM.Database.DataLayers.Admins
return result ? transferToDriver : null;
}
public Task<bool> RemoveTransferToDriverAsync(TransferToDriver transferToDriver) => TransactionAsync(ctx => ctx.TransferToDrivers.Remove(transferToDriver).State == EntityState.Deleted);
public Task<bool> RemoveTransferToDriverAsync(TransferToDriver transferToDriver) => TransactionAsync(ctx => ctx.RemoveTransferToDriver(transferToDriver.Id));
#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());
public Task<List<UserProductMapping>> GetAllDriversAsync(bool autoInclude = true) => SessionAsync(ctx => ctx.GetAllDrivers(autoInclude).ToList());
public Task<List<UserProductMapping>> GetAllDriversByProductIdAsync(Guid productId, bool autoInclude = true) => SessionAsync(ctx => ctx.GetAllDriversByProductId(productId, autoInclude).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));
@ -125,7 +126,7 @@ namespace TIAM.Database.DataLayers.Admins
public Task<bool> AddTransferDestinationToProductAsync(TransferDestinationToProduct transferDestinationToProduct) => TransactionAsync(ctx => ctx.AddTransferDestinationToProduct(transferDestinationToProduct));
public Task<bool> UpdateTransferDestinationToProductAsync(TransferDestinationToProduct transferDestinationToProduct) => TransactionAsync(ctx => ctx.UpdateTransferDestinationToProduct(transferDestinationToProduct));
public Task<bool> RemoveTransferDestinationToProductAsync(TransferDestinationToProduct transferDestinationToProduct) => TransactionAsync(ctx => ctx.RemoveTransferDestinationToProduct(transferDestinationToProduct.Id));
public Task<bool> RemoveTransferDestinationToProductAsync(TransferDestinationToProduct transferDestinationToProduct) => RemoveTransferDestinationToProductAsync(transferDestinationToProduct.Id);
public Task<bool> RemoveTransferDestinationToProductAsync(Guid transferDestinationToProductId) => TransactionAsync(ctx => ctx.RemoveTransferDestinationToProduct(transferDestinationToProductId));
#endregion TransferDestinationToProduct
@ -158,7 +159,7 @@ namespace TIAM.Database.DataLayers.Admins
public Task<bool> AddProductAsync(Product product) => TransactionAsync(ctx => ctx.AddProduct(product));
public Task<bool> UpdateProductAsync(Product product) => TransactionAsync(ctx => ctx.UpdateProduct(product));
//public Task<bool> RemoveProductAsync(Product product) => TransactionAsync(ctx => ctx.RemoveProduct(product.Id));
public Task<bool> RemoveProductAsync(Product product) => RemoveProductAsync(product.Id);
public Task<bool> RemoveProductAsync(Guid productId) => TransactionAsync(ctx => ctx.RemoveProduct(productId));
public UserProductMapping? GetUserProductMappingById(Guid userProductMappingId, bool autoInclude = true) => Session(ctx => ctx.GetUserProductMappingById(userProductMappingId, autoInclude));
@ -217,9 +218,7 @@ namespace TIAM.Database.DataLayers.Admins
}
public Task<bool> RemoveUserProductMappingAsync(Guid userProductMappingId) => TransactionAsync(ctx => ctx.RemoveUserProductMapping(userProductMappingId));
public Task<bool> RemoveUserProductMappingAsync(Guid userId, Guid productId)
=> TransactionAsync(ctx => ctx.RemoveUserProductMapping(userId, productId));
public Task<bool> RemoveUserProductMappingAsync(Guid userId, Guid productId) => TransactionAsync(ctx => ctx.RemoveUserProductMapping(userId, productId));
#endregion UserProductMapping

View File

@ -1,4 +1,5 @@
using AyCode.Database.DbContexts.Users;
using TIAM.Database.DbSets.Drivers;
using TIAM.Database.DbSets.Emails;
using TIAM.Database.DbSets.Permissions;
using TIAM.Database.DbSets.Products;
@ -14,7 +15,7 @@ using TIAM.Entities.Users;
namespace TIAM.Database.DbContexts.Admins;
public interface IAdminDbContext :
ICompanyDbSet, IProductDbSet, IUserProductMappingDbSet,
ICompanyDbSet, IProductDbSet, IDriverDbSet,
IAcUserDbContextBase<User, Profile, UserToken, Company, UserToCompany, Address, EmailMessage>,
IPermissionsDbSetContext, ITransferDestinationDbSet, ITransferDbSet, IEmailMessageDbSet
{

View File

@ -0,0 +1,9 @@
using Microsoft.EntityFrameworkCore;
using TIAM.Entities.Drivers;
namespace TIAM.Database.DbSets.Cars;
public interface ICarDbSet
{
public DbSet<Car> Cars { get; set; }
}

View File

@ -0,0 +1,18 @@
using AyCode.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using TIAM.Database.DbSets.Transfers;
using TIAM.Database.DbSets.Users;
using TIAM.Entities.Drivers;
using TIAM.Entities.Transfers;
using TIAM.Entities.Users;
namespace TIAM.Database.DbSets.Drivers;
public static class DriverDbSetExtensions
{
public static IQueryable<UserProductMapping> GetAllDrivers(this IDriverDbSet ctx, bool autoInclude = true)
=> ctx.UserProductMappingsWithRelations(autoInclude).Where(x => ctx.Cars.Any(car => car.UserProductMappingId == x.Id));
public static IQueryable<UserProductMapping> GetAllDriversByProductId(this IDriverDbSet ctx, Guid productId, bool autoInclude = true)
=> ctx.GetAllDrivers(autoInclude).Where(x => x.ProductId == productId);
}

View File

@ -0,0 +1,9 @@
using TIAM.Database.DbSets.Cars;
using TIAM.Database.DbSets.Transfers;
using TIAM.Database.DbSets.Users;
using TIAM.Entities.Users;
namespace TIAM.Database.DbSets.Drivers;
public interface IDriverDbSet : IUserProductMappingDbSet, ICarDbSet, ITransferToDriverDbSet, ITransferDbSet
{ }

View File

@ -3,7 +3,7 @@ using TIAM.Entities.Transfers;
namespace TIAM.Database.DbSets.Transfers;
public interface ITransferDbSet
public interface ITransferDbSet : ITransferToDriverDbSet
{
public DbSet<Transfer> Transfers { get; set; }
}

View File

@ -0,0 +1,9 @@
using Microsoft.EntityFrameworkCore;
using TIAM.Entities.Transfers;
namespace TIAM.Database.DbSets.Transfers;
public interface ITransferToDriverDbSet
{
public DbSet<TransferToDriver> TransferToDrivers { get; set; }
}

View File

@ -13,8 +13,12 @@ public static class TransferDbSetExtensions
public static bool UpdateTransfer(this ITransferDbSet ctx, Transfer transfer)
=> ctx.Transfers.Update(transfer).State == EntityState.Modified;
public static bool RemoveTransfer(this ITransferDbSet ctx, Transfer transfer)
=> ctx.Transfers.Remove(transfer).State == EntityState.Deleted;
private static bool RemoveTransfer(this ITransferDbSet ctx, Transfer transfer)
{
ctx.TransferToDrivers.RemoveRange(ctx.TransferToDrivers.Where(x => x.TransferId == transfer.Id));
return ctx.Transfers.Remove(transfer).State == EntityState.Deleted;
}
public static bool RemoveTransfer(this ITransferDbSet ctx, Guid transferId)
{

View File

@ -0,0 +1,40 @@
using Microsoft.EntityFrameworkCore;
using TIAM.Core.Enums;
using TIAM.Database.DbSets.Drivers;
using TIAM.Database.DbSets.Users;
using TIAM.Entities.Transfers;
using TIAM.Entities.Users;
namespace TIAM.Database.DbSets.Transfers;
public static class TransferToDriverDbSetExtensions
{
#region TransferToDriver
public static TransferToDriver? GetTransferToDriverById(this ITransferToDriverDbSet ctx, Guid transferToDriverId, bool autoInclude = true)
=> ctx.TransferToDrivers.FirstOrDefault(x => x.Id == transferToDriverId);
public static IQueryable<TransferToDriver> GetTransferToDriversByTransferId(this ITransferToDriverDbSet ctx, Guid transferId, bool autoInclude = true)
=> ctx.TransferToDrivers.Where(x => x.TransferId == transferId);
public static bool AddTransferToDriver(this IDriverDbSet ctx, TransferToDriver transferToDriver)
{
var transfer = ctx.GetTransferById(transferToDriver.TransferId)!;
transfer.TransferStatusType = TransferStatusType.AssignedToDriver;
return ctx.TransferToDrivers.Add(transferToDriver).State == EntityState.Added;
}
private static bool RemoveTransferToDriver(this ITransferToDriverDbSet ctx, TransferToDriver transferToDriver)
{
//TODO: TransferStatusType change, ha nincs sofőr a törlés után! - J.
return ctx.TransferToDrivers.Remove(transferToDriver).State == EntityState.Deleted;
}
public static bool RemoveTransferToDriver(this ITransferToDriverDbSet ctx, Guid transferToDriverId)
{
var transferToDriver = ctx.GetTransferToDriverById(transferToDriverId);
return transferToDriver == null || ctx.RemoveTransferToDriver(transferToDriver);
}
#endregion TransferToDriver
}

View File

@ -25,7 +25,6 @@ public static class UserProductMappingDbSetExtensions
public static IQueryable<UserProductMapping> GetUserProductMappingsByProductId(this IUserProductMappingDbSet ctx, Guid productId, bool autoInclude = true)
=> ctx.UserProductMappingsWithRelations(autoInclude).Where(x => x.ProductId == productId);
public static bool AddUserProductMapping(this IUserProductMappingDbSet ctx, UserProductMapping userProductMapping)
{
if (userProductMapping.UserId.IsNullOrEmpty() || userProductMapping.ProductId.IsNullOrEmpty() || userProductMapping.Permissions < 0)

View File

@ -588,7 +588,7 @@ namespace TIAMWebApp.Server.Controllers
[SignalR(SignalRTags.GetAllDrivers)]
public async Task<List<UserProductMapping>> GetAllDrivers()
{
var result = await _adminDal.GetTAllDrivers();
var result = await _adminDal.GetAllDriversAsync();
return result;
}
@ -598,7 +598,7 @@ namespace TIAMWebApp.Server.Controllers
[SignalR(SignalRTags.GetAllDriversByProductId)]
public async Task<List<UserProductMapping>> GetAllDriversByProductId(Guid productId)
{
var result = await _adminDal.GetTAllDriversByProductId(productId);
var result = await _adminDal.GetAllDriversByProductIdAsync(productId);
return result;
}
@ -629,6 +629,8 @@ namespace TIAMWebApp.Server.Controllers
public async Task<TransferToDriver?> AddTransferDriver([FromBody] TransferToDriver transferToDriver)
{
var result = await _adminDal.AddTransferToDriverAsync(transferToDriver);
//TODO: Send email to driver... - J.
return result ? transferToDriver : null;
}
@ -639,6 +641,8 @@ namespace TIAMWebApp.Server.Controllers
public async Task<TransferToDriver?> UpdateTransferDriver([FromBody] TransferToDriver transferToDriver)
{
var result = await _adminDal.UpdateTransferToDriverAsync(transferToDriver);
//TODO: Send email to driver/user, ha van változás... - J.
return result; // ? transferToDriver : null;
}
@ -649,6 +653,8 @@ namespace TIAMWebApp.Server.Controllers
public async Task<TransferToDriver?> RemoveTransferDriver([FromBody] TransferToDriver transferToDriver)
{
var result = await _adminDal.RemoveTransferToDriverAsync(transferToDriver);
//TODO: Send email to driver/user... - J.
return result ? transferToDriver : null;
}