90 lines
4.0 KiB
C#
90 lines
4.0 KiB
C#
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
|
|
.Where(x => x.Id == transferToDriverId)
|
|
.Include(x => x.UserProductMapping.User.Products).ThenInclude(x => x.UserProductMappings)
|
|
.Include(x => x.Car.UserProductMapping.Product.ServiceProvider).ThenInclude(x => x.Products)
|
|
.Include(x => x.UserProductMapping.User.Profile.Address)
|
|
.Include(x => x.Transfer)
|
|
.FirstOrDefault(x => x.Id == transferToDriverId);
|
|
|
|
public static IQueryable<TransferToDriver> GetTransferToDriversByTransferId(this ITransferToDriverDbSet ctx, Guid transferId, bool autoInclude = true)
|
|
{
|
|
var query = ctx.TransferToDrivers.Where(x => x.TransferId == transferId);
|
|
|
|
if (autoInclude)
|
|
{
|
|
query = query.Include(x => x.Car.UserProductMapping.Product.ServiceProvider).ThenInclude(x => x.Products)
|
|
.Include(x => x.UserProductMapping.User.Profile.Address)
|
|
.Include(x => x.Transfer);
|
|
}
|
|
|
|
return query;
|
|
//.Include(x => x.UserProductMapping.User.Products).ThenInclude(x => x.UserProductMappings)
|
|
//.Include(x => x.Car.UserProductMapping.Product.ServiceProvider).ThenInclude(x => x.Products)
|
|
//.Include(x => x.UserProductMapping.User.Profile.Address)
|
|
//.Include(x => x.Transfer);
|
|
|
|
//.Include(x => x.UserProductMapping.User.Products).ThenInclude(x => x.UserProductMappings).ThenInclude(x => x.User.Profile.Address)
|
|
//.Include(x => x.Car.UserProductMapping.Product.ServiceProvider).ThenInclude(x => x.Products)
|
|
//.Include(x => x.UserProductMapping.User.Profile.Address)
|
|
//.Include(x => x.Transfer);
|
|
}
|
|
|
|
public static IQueryable<TransferToDriver> GetTransferToDriversByProductId(this ITransferToDriverDbSet ctx, Guid productId, bool autoInclude = true)
|
|
{
|
|
var query = ctx.TransferToDrivers.Where(x => x.UserProductMapping.ProductId == productId);
|
|
|
|
if (autoInclude)
|
|
{
|
|
query = query.Include(x => x.Car.UserProductMapping.Product.ServiceProvider).ThenInclude(x => x.Products)
|
|
.Include(x => x.UserProductMapping.User.Profile.Address)
|
|
.Include(x => x.Transfer);
|
|
}
|
|
|
|
return query;
|
|
}
|
|
|
|
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);
|
|
|
|
return ctx.TransferToDrivers.Add(transferToDriver).State == EntityState.Added;
|
|
}
|
|
|
|
public static bool UpdateTransferToDriver(this ITransferDbSet ctx, TransferToDriver transferToDriver)
|
|
{
|
|
ctx.UpdateTransferStatus(transferToDriver.Transfer, TransferStatusType.AssignedToDriver);
|
|
|
|
return ctx.TransferToDrivers.Update(transferToDriver).State == EntityState.Modified;
|
|
}
|
|
|
|
private static bool RemoveTransferToDriver(this ITransferDbSet 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 ITransferDbSet ctx, Guid transferToDriverId)
|
|
{
|
|
var transferToDriver = ctx.GetTransferToDriverById(transferToDriverId);
|
|
return transferToDriver == null || ctx.RemoveTransferToDriver(transferToDriver);
|
|
}
|
|
|
|
#endregion TransferToDriver
|
|
} |