refactoring, improvements, fixes, etc...

This commit is contained in:
jozsef.b@aycode.com 2024-01-18 19:54:20 +01:00
parent ac4a958ed6
commit ec0d07e238
34 changed files with 456 additions and 93 deletions

View File

@ -1,4 +1,4 @@
namespace TIAM.Entities.Drivers;
namespace TIAM.Core.Enums;
public enum CarMotorType : byte
{

View File

@ -0,0 +1,12 @@
namespace TIAM.Core.Enums;
public enum TransferStatusType : byte
{
OrderSubmitted = 5,
OrderConfirmed = 10,
AssignedToDriver = 15,
DriverConfirmed = 20,
DriverEnRoute = 25,
PassengerPickup = 30,
Finished = 35,
}

View File

@ -7,16 +7,20 @@ using System.Threading.Tasks;
using AyCode.Database.DataLayers.Users;
using AyCode.Utils.Extensions;
using Newtonsoft.Json;
using TIAM.Core.Enums;
using TIAM.Database.DataLayers.Admins;
//using TIAM.Database.DataLayers.ServiceProviders;
using TIAM.Database.DataLayers.Users;
using TIAM.Database.DbContexts.Admins;
using TIAM.Database.DbContexts.ServiceProviders;
using TIAM.Database.DbSets.Permissions;
using TIAM.Database.DbSets.Transfers;
using TIAM.Entities.Drivers;
using TIAM.Entities.Products;
using TIAM.Entities.Users;
using TIAM.Models.Dtos.Users;
using TIAM.Entities.TransferDestinations;
using TIAM.Entities.Transfers;
namespace TIAM.Database.Test
{
@ -71,6 +75,7 @@ namespace TIAM.Database.Test
var product = Dal.GetProductById(productId);
Assert.IsNotNull(product, "Product is null");
Assert.IsNotNull(product.Profile);
return product;
}
@ -82,6 +87,7 @@ namespace TIAM.Database.Test
var product = GetProductById_ReturnsProduct_WhenProductExists(productIdString);
Assert.IsTrue(product.UserProductMappings.Count > 0, "UserProductMappings count: 0");
Assert.IsNotNull(product.UserProductMappings[0].User, "User is null");
Assert.IsNotNull(product.ServiceProvider, "ServiceProvider is null");
}
@ -117,7 +123,36 @@ namespace TIAM.Database.Test
}
[DataTestMethod]
[DataRow(new[] { "8EF2FC69-2338-4D9F-91B4-B1E15C241E1C", "814b5495-c2e9-4f1d-a73f-37cd5d353078" })]
[DataRow("97179a87-d99f-4f12-b7b2-75e21aaec6ab")]
public void GetSerializedUserProductMappingCarByUserProductCarId_ReturnsUserProductMapping_WhenHasJsonDetailModelAndCar(string userProductCarIdString)
{
var userProductCarId = Guid.Parse(userProductCarIdString);
var serializedUserProductMapping = Dal.Session(ctx
=> ctx.UserProductMappings.FirstOrDefault(x
=> x.JsonDetailModel != null && x.JsonDetailModel.Cars != null && x.JsonDetailModel.Cars.Any(c => c.UserProductCarId == userProductCarId))?.ToJson());
//var transfers = Dal.Session(x => x.GetTransfers()).ToList();
//var userProductMappinIds = transfers.Select(x => x.UserProductMappingId).ToHashSet();
//var userProductMappings = Dal.Session(x => x.UserProductMappings.Where(x => userProductMappinIds.Contains(x.Id)));
Assert.IsNotNull(serializedUserProductMapping);
Assert.IsFalse(serializedUserProductMapping.IsNullOrWhiteSpace());
var userProductMapping = JsonConvert.DeserializeObject<UserProductMapping>(serializedUserProductMapping);
//var car = userProductMapping.JsonDetailModel.Cars.FirstOrDefault(x => x.UserProductCarId == userProductCarId)?.Car;
Assert.IsNotNull(userProductMapping);
Assert.IsNotNull(userProductMapping.JsonDetailModel, "User is null");
Assert.IsNotNull(userProductMapping.JsonDetailModel.Cars, "Product is null");
Assert.IsTrue(userProductMapping.JsonDetailModel.Cars.Count == 1);
Assert.IsTrue(userProductMapping.JsonDetailModel.Cars[0].UserProductCarId == userProductCarId, "userProductMapping.JsonDetailModel.Cars[0].UserProductCarId == userProductCarId");
}
[DataTestMethod]
[DataRow(["8EF2FC69-2338-4D9F-91B4-B1E15C241E1C", "814b5495-c2e9-4f1d-a73f-37cd5d353078"])]
public async Task UserProductMappingCrudTest(string[] userIdProductIdStrings)
{
var userId = Guid.Parse(userIdProductIdStrings[0]);
@ -126,7 +161,9 @@ namespace TIAM.Database.Test
await Dal.RemoveUserProductMappingAsync(userId, productId); //kitöröljük a szemetet, ha korábbról bentmaradt - J.
var userProductMapping = await Dal.AddUserProductMappingAsync(userProductMappingId, userId, productId, 2);
var cars = new UserProductJsonDetailModel([new UserProductToCar(new Car())]);
var userProductMapping = await Dal.AddUserProductMappingAsync(userProductMappingId, userId, productId, 2, cars);
Assert.IsNotNull(userProductMapping);
userProductMapping = await Dal.GetUserProductMappingByIdAsync(userProductMappingId, true);
@ -192,7 +229,7 @@ namespace TIAM.Database.Test
[DataRow("540271F6-C604-4C16-8160-D5A7CAFEDF00")]
[DataRow("dcf451d2-cc4c-4ac2-8c1f-da00041be1fd")]
[DataRow("ac612aa8-863b-4b4f-9d63-f5d261b5c5f9")]
public void SerializeUserEntity_ReturnDeserializedUser_WhenUserAndRelationsExists(string userIdString)
public void GetSerializedUserEntity_ReturnDeserializedUser_WhenUserAndRelationsExists(string userIdString)
{
var userId = Guid.Parse(userIdString);
var userJson = Dal.GetUserJsonById(userId);
@ -216,7 +253,7 @@ namespace TIAM.Database.Test
}
[TestMethod]
public void SerializeUsers_ReturnDeserializedUsers_WhenUsersAndRelationsExists()
public void GetSerializedUsers_ReturnDeserializedUsers_WhenUsersAndRelationsExists()
{
var userJson = Dal.GetUsersJson();
@ -228,6 +265,18 @@ namespace TIAM.Database.Test
Assert.IsTrue(users.Count>0);
}
#region Transfer
[DataTestMethod]
[DataRow("6216f9fb-1dda-44bd-9d85-431f3cb09fde")]
public void GetTransferById_ReturnsTransfer_WhenHasTransfer(string transferIdString)
{
var transferId = Guid.Parse(transferIdString);
var transfer = Dal.GetTransferById(transferId);
Assert.IsNotNull(transfer);
Assert.IsTrue(transfer.Id == transferId, "transfer.Id != transferId");
}
[DataTestMethod]
[DataRow("273EFE3C-D19F-4C2A-BF19-7397DC835C60")]
public void GetTransferDestionationById_ReturnsTransferDestination_WhenHasAddressRelation(string transferDestinationIdString)
@ -243,6 +292,62 @@ namespace TIAM.Database.Test
//Assert.IsTrue(user.UserProductMappings.Count > 0, "UserProductMappings count: 0");
//Assert.IsNotNull(user.UserProductMappings[0].Product, "Product is null");
}
[DataTestMethod]
[DataRow(["8f38f8e3-a92c-4979-88b1-dc812a82245f", "814b5495-c2e9-4f1d-a73f-37cd5d353078"])]
public async Task TransferCrudTest(string[] transferIdProductIdStrings)
{
var transferId = Guid.Parse(transferIdProductIdStrings[0]);
var productId = Guid.Parse(transferIdProductIdStrings[1]);
var fromAddress = "Budapest, Liszt Ferenc tér";
var toAddress = "1211 Budapest, Kossuth Lajos utca 145";
var userProductToCarId = Guid.Parse("97179a87-d99f-4f12-b7b2-75e21aaec6ab");
await Dal.RemoveTransferAsync(transferId); //kitöröljük a szemetet, ha korábbról bentmaradt - J.
var transfer = new Transfer
{
Id = transferId,
ProductId = productId,
Appointment = DateTime.UtcNow.AddDays(3),
FlightNumber = "GSD234",
FromAddress = fromAddress,
ToAddress = toAddress,
PassengerCount = 3,
Price = 20000,
TransferStatusType = TransferStatusType.OrderConfirmed,
};
Assert.IsTrue(await Dal.AddTransferAsync(transfer));
Assert.IsNotNull(transfer);
transfer = Dal.GetTransferById(transferId);
Assert.IsNotNull(transfer);
transfer.Payed = true;
transfer.UserProductToCarId = userProductToCarId;
transfer.TransferStatusType = TransferStatusType.AssignedToDriver;
Assert.IsTrue(await Dal.UpdateTransferAsync(transfer));
transfer = Dal.GetTransferById(transferId);
Assert.IsNotNull(transfer);
Assert.IsTrue(transfer.Payed);
Assert.IsTrue(transfer.UserProductToCarId == userProductToCarId);
Assert.IsTrue(transfer.TransferStatusType == TransferStatusType.AssignedToDriver);
Assert.IsTrue(transfer.Id == transferId, "transfer.Id != transferId");
Assert.IsTrue(await Dal.RemoveTransferAsync(transferId)); //mielőbb kitöröljük, h ne maradjon szemét a db-ben - J.
transfer = Dal.GetTransferById(transferId);
Assert.IsNull(transfer); //a korábbi törlés miatt NULL kell legyen - J.
}
#endregion Trnsfer
}
}

View File

@ -5,13 +5,16 @@ using Microsoft.EntityFrameworkCore;
using TIAM.Database.DbContexts.Admins;
using TIAM.Database.DbSets.Permissions;
using TIAM.Database.DbSets.Products;
using TIAM.Database.DbSets.Transfers;
using TIAM.Database.DbSets.Users;
using TIAM.Entities.Drivers;
using TIAM.Entities.Permissions;
using TIAM.Entities.Products;
using TIAM.Entities.Products.DTOs;
using TIAM.Entities.ServiceProviders;
using TIAM.Entities.TransferDestinations;
using TIAM.Entities.Transfers;
using TIAM.Entities.Users;
using TIAM.Models.Dtos.Products;
using TIAM.Models.Dtos.Users;
namespace TIAM.Database.DataLayers.Admins
@ -22,8 +25,18 @@ namespace TIAM.Database.DataLayers.Admins
{
}
public TransferDestination? GetTransferDestinationById(Guid transferDestinationId, bool autoInclude = false) => Session(ctx=>ctx.TransferDestinations.FirstOrDefault(x=>x.Id == transferDestinationId));
public string? GetTransferDestinationJsonById(Guid transferDestinationId) => Session(ctx => ctx.TransferDestinations.FirstOrDefault(x => x.Id == transferDestinationId)?.ToJson());
#region Transfer
public TransferDestination? GetTransferDestinationById(Guid transferDestinationId, bool autoInclude = false) => Session(ctx=>ctx.GetTransferDestinationById(transferDestinationId));
public string? GetTransferDestinationJsonById(Guid transferDestinationId) => Session(ctx => ctx.GetTransferDestinationById(transferDestinationId)?.ToJson());
public Transfer? GetTransferById(Guid transferId, bool autoInclude = false) => Session(ctx => ctx.GetTransferById(transferId, autoInclude));
public string? GetTransferJsonById(Guid transferId, bool autoInclude = false) => Session(ctx => ctx.GetTransferById(transferId, autoInclude)?.ToJson());
public Task<bool> AddTransferAsync(Transfer transfer) => TransactionAsync(ctx => ctx.AddTransfer(transfer) && ctx.SaveChanges() > 0);
public Task<bool> UpdateTransferAsync(Transfer transfer) => TransactionAsync(ctx => ctx.UpdateTransfer(transfer) && ctx.SaveChanges() > 0);
public Task<bool> RemoveTransferAsync(Transfer transfer) => TransactionAsync(ctx => ctx.RemoveTransfer(transfer) && ctx.SaveChanges() > 0);
public Task<bool> RemoveTransferAsync(Guid transferId) => TransactionAsync(ctx => ctx.RemoveTransfer(transferId) && ctx.SaveChanges() > 0);
#endregion Transfer
public User? GetUserById(Guid userId, bool autoInclude = false) => Session(ctx => ctx.GetUserById(userId, autoInclude));
public User? GetUserByEmail(string email, bool autoInclude = false) => Session(ctx => ctx.GetUserByEmail(email, autoInclude));
@ -36,7 +49,10 @@ namespace TIAM.Database.DataLayers.Admins
public string GetUsersJson() => Session(ctx => ctx.Users.ToJson());
public Product? GetProductById(Guid contextId) => Session(ctx => ctx.GetProductById(contextId));
public Task<bool> AddProduct(Product product) => TransactionAsync(ctx => ctx.AddProduct(product));
public Task<bool> AddProduct(Product product) => TransactionAsync(ctx => ctx.AddProduct(product) && ctx.SaveChanges() > 0);
public Task<bool> UpdateProduct(Product product) => TransactionAsync(ctx => ctx.UpdateProduct(product) && ctx.SaveChanges() > 0);
public Task<bool> RemoveProduct(Product product) => TransactionAsync(ctx => ctx.RemoveProduct(product) && ctx.SaveChanges() > 0);
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));
@ -57,13 +73,13 @@ namespace TIAM.Database.DataLayers.Admins
public Task<bool> AddUserProductMappingAsync(UserProductMapping userProductMapping)
=> TransactionAsync(ctx => ctx.AddUserProductMapping(userProductMapping) && ctx.SaveChanges() == 1);
public async Task<UserProductMapping?> AddUserProductMappingAsync(Guid userProductMappingId, Guid userId, Guid productId, int permissions = 1, string? jsonDetails = null)
public async Task<UserProductMapping?> AddUserProductMappingAsync(Guid userProductMappingId, Guid userId, Guid productId, int permissions = 1, UserProductJsonDetailModel? userProductToCars = null)
{
UserProductMapping? userProductMapping = null;
var isSucces = await TransactionAsync(ctx =>
{
userProductMapping = ctx.AddUserProductMapping(userProductMappingId, userId, productId, permissions, jsonDetails);
userProductMapping = ctx.AddUserProductMapping(userProductMappingId, userId, productId, permissions, userProductToCars);
return userProductMapping != null && ctx.SaveChanges() == 1;
});
@ -74,13 +90,13 @@ namespace TIAM.Database.DataLayers.Admins
public Task<bool> UpdateUserProductMappingAsync(UserProductMapping userProductMapping)
=> TransactionAsync(ctx => ctx.UpdateUserProductMapping(userProductMapping) && ctx.SaveChanges() > 0);
public async Task<UserProductMapping?> UpdateUserProductMappingAsync(Guid userProductMappingId, int permissions = 1, string? jsonDetails = null)
public async Task<UserProductMapping?> UpdateUserProductMappingAsync(Guid userProductMappingId, int permissions = 1, UserProductJsonDetailModel? userProductToCars = null)
{
UserProductMapping? userProductMapping = null;
var isSucces = await TransactionAsync(ctx =>
{
userProductMapping = ctx.UpdateUserProductMapping(userProductMappingId, permissions, jsonDetails);
userProductMapping = ctx.UpdateUserProductMapping(userProductMappingId, permissions, userProductToCars);
return userProductMapping != null && ctx.SaveChanges() == 1;
});
@ -432,16 +448,6 @@ namespace TIAM.Database.DataLayers.Admins
#region Products
//* 20. (IServiceProviderDataService) Update product
public Product UpdateProduct(Product product)
{
var prod = Context.UpdateProduct(product);
Console.WriteLine($"Saving product to db {product.Id}, {product.Name}, {product.ServiceProviderId}");
Context.SaveChanges();
return prod;
}
//* 21. (IServiceProviderDataService) delete product
public Task<bool> DeleteProductByIdAsync(Guid productId)
{

View File

@ -77,26 +77,6 @@ namespace TIAM.Database.DataLayers.Admins
return true;
}
public static Product UpdateProduct(this IAdminDbContext ctx, Product product)
{
if (product == null) return null;
var existingProduct = ctx.Products.FirstOrDefault(u => u.Id == product.Id);
if (existingProduct == null) return null;
existingProduct.Name = product.Name;
existingProduct.ServiceProviderId = product.ServiceProviderId;
existingProduct.Description = product.Description;
existingProduct.Price = product.Price;
existingProduct.JsonDetails = product.JsonDetails;
//existingProduct.UserMediaId = product.UserMediaId;
existingProduct.ProductType = product.ProductType;
return existingProduct;
}
public static void DeleteProductById(this IAdminDbContext ctx, Guid productId)
{
var product = ctx.Products.FirstOrDefault(u => u.Id == productId);

View File

@ -12,7 +12,6 @@ using TIAM.Entities.Users;
using TIAM.Database.DbContexts.ServiceProviders;
using TIAM.Database.DbSets.Permissions;
using TIAM.Database.DbSets.Users;
using TIAM.Entities.Products.DTOs;
using AyCode.Database.DataLayers;
using AyCode.Database.DbSets.Users;
using TIAM.Database.DbSets.Products;

View File

@ -8,10 +8,12 @@ using Microsoft.EntityFrameworkCore;
using TIAM.Database.ModelBuilders.Products;
using TIAM.Database.ModelBuilders.Users;
using TIAM.Entities.Addresses;
using TIAM.Entities.Drivers;
using TIAM.Entities.Permissions;
using TIAM.Entities.Products;
using TIAM.Entities.ServiceProviders;
using TIAM.Entities.TransferDestinations;
using TIAM.Entities.Transfers;
using TIAM.Entities.Users;
namespace TIAM.Database.DbContexts.Admins
@ -20,6 +22,7 @@ namespace TIAM.Database.DbContexts.Admins
{
public DbSet<User> Users { get; set; }
public DbSet<TransferDestination> TransferDestinations { get; set; }
public DbSet<Transfer> Transfers { get; set; }
public DbSet<TiamServiceProvider> ServiceProviders { get; set; }
public DbSet<Product> Products { get; set; }
@ -32,7 +35,6 @@ namespace TIAM.Database.DbContexts.Admins
public AdminDbContext() //: this(string.Empty)
{
}
public AdminDbContext(string name) : base(name)
@ -57,6 +59,49 @@ namespace TIAM.Database.DbContexts.Admins
new ProductEntityTypeDefaultConfiguration().Configure(modelBuilder.Entity<Product>());
modelBuilder.Entity<TransferDestination>().Navigation(e => e.Address).AutoInclude(true);
//modelBuilder.Entity<UserProductToCar>().Ignore(x => x.Id);
//modelBuilder.Entity<Car>().Ignore(x => x.Id);
////modelBuilder.Entity<UserProductToCars>().Ignore(x => x.Cars);
//modelBuilder.Entity<UserProductMapping>().Ignore(x => x.Cars);
//modelBuilder.Entity<Car>().HasNoKey();
//modelBuilder.Entity<UserProductToCar>().HasNoKey();
modelBuilder.Entity<UserProductMapping>().OwnsOne(
userToProduct => userToProduct.JsonDetailModel, builderUserProductJsonDetail =>
{
builderUserProductJsonDetail.ToJson();
//builderUserProductJsonDetail.Property(nameof(UserProductMapping.JsonDetailModel)).HasColumnName("JsonDetailModel");
builderUserProductJsonDetail.OwnsMany(userProductJsonDetail => userProductJsonDetail.Cars, builderUserProductToCar =>
{
//builderUserProductToCar.ToJson();
//builderUserProductToCar.Ignore(x => x.UserProductToCarId);
//builderUserProductToCar.Ignore(x => x.Created);
//builderUserProductToCar.Ignore(x => x.Modified);
builderUserProductToCar.OwnsOne(userProductToCar => userProductToCar.Car, builderCar =>
{
//builderCar.ToJson();
//builderCar.Ignore(x => x.Id);
//builderCar.Ignore(x => x.Created);
//builderCar.Ignore(x => x.Modified);
});
});
//builderUserProductJsonDetail.OwnsMany(userProductJsonDetail => userProductJsonDetail.Cars2);
});
//modelBuilder.Entity<UserProductToCar>().OwnsOne(
// userToProduct => userToProduct.Car, ownedNavigationBuilder =>
// {
// ownedNavigationBuilder.ToJson();
// });
}
}
}

View File

@ -7,6 +7,6 @@ using TIAM.Database.DbSets.Users;
namespace TIAM.Database.DbContexts.Admins;
public interface IAdminDbContext : IServiceProviderDbSet, IProductDbSet, IUserProductMappingDbSet, IUserDbSet, IPermissionsDbSetContext, IAddressDbSet, ITransferDestinationDbSet
public interface IAdminDbContext : IServiceProviderDbSet, IProductDbSet, IUserProductMappingDbSet, IUserDbSet, IPermissionsDbSetContext, IAddressDbSet, ITransferDestinationDbSet, ITransferDbSet
{
}

View File

@ -63,6 +63,21 @@ namespace TIAM.Database.DbContexts.Users
//modelBuilder.Entity<Product>().BuildProductToServiceProviderRelation();
//new UserProductMappingEntityTypeDefaultConfiguration().Configure(modelBuilder.Entity<UserProductMapping>());
modelBuilder.Entity<UserProductMapping>().OwnsOne(
userToProduct => userToProduct.JsonDetailModel, builderUserProductJsonDetail =>
{
builderUserProductJsonDetail.ToJson();
builderUserProductJsonDetail.OwnsMany(userProductJsonDetail => userProductJsonDetail.Cars, builderUserProductToCar =>
{
builderUserProductToCar.OwnsOne(userProductToCar => userProductToCar.Car, builderCar =>
{
});
});
//builderUserProductJsonDetail.OwnsMany(userProductJsonDetail => userProductJsonDetail.Cars2);
});
}
}
}

View File

@ -10,6 +10,12 @@ public static class ProductDbSetExtensins
public static bool AddProduct(this IProductDbSet ctx, Product product)
=> ctx.Products.Add(product).State == EntityState.Added;
public static bool UpdateProduct(this IProductDbSet ctx, Product product)
=> ctx.Products.Update(product).State == EntityState.Modified;
public static bool RemoveProduct(this IProductDbSet ctx, Product product)
=> ctx.Products.Remove(product).State == EntityState.Deleted;
#endregion Add, Update, Remove
public static IQueryable<Product> ProductsWithUserRelations(this IProductDbSet ctx, bool autoInclude = true)

View File

@ -0,0 +1,10 @@
using Microsoft.EntityFrameworkCore;
using TIAM.Entities.TransferDestinations;
using TIAM.Entities.Transfers;
namespace TIAM.Database.DbSets.Transfers;
public interface ITransferDbSet
{
public DbSet<Transfer> Transfers { get; }
}

View File

@ -0,0 +1,43 @@
using Microsoft.EntityFrameworkCore;
using TIAM.Database.DbSets.Products;
using TIAM.Database.DbSets.Users;
using TIAM.Entities.Products;
using TIAM.Entities.TransferDestinations;
using TIAM.Entities.Transfers;
namespace TIAM.Database.DbSets.Transfers;
public static class TransferDbSetExtensions
{
#region Add, Update, Remove
public static bool AddTransfer(this ITransferDbSet ctx, Transfer transfer)
=> ctx.Transfers.Add(transfer).State == EntityState.Added;
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;
public static bool RemoveTransfer(this ITransferDbSet ctx, Guid transferId)
{
var transfer = ctx.GetTransferById(transferId, false);
return transfer == null || ctx.RemoveTransfer(transfer);
}
#endregion Add, Update, Remove
public static Transfer? GetTransferById(this ITransferDbSet ctx, Guid transferId, bool autoInclude = false)
=> ctx.Transfers.FirstOrDefault(x => x.Id == transferId);
public static IQueryable<Transfer> GetTransfers(this ITransferDbSet ctx)
=> ctx.Transfers;
public static TransferDestination? GetTransferDestinationById(this ITransferDestinationDbSet ctx, Guid transferDestinationId)
=> ctx.TransferDestinations.FirstOrDefault(x => x.Id == transferDestinationId);
public static IQueryable<TransferDestination> GetTransferDestinations(this ITransferDestinationDbSet ctx)
=> ctx.TransferDestinations;
}

View File

@ -1,6 +1,7 @@
using AyCode.Utils.Extensions;
using Microsoft.EntityFrameworkCore;
using TIAM.Database.DbContexts.ServiceProviders;
using TIAM.Entities.Drivers;
using TIAM.Entities.Users;
namespace TIAM.Database.DbSets.Users;
@ -37,9 +38,9 @@ public static class UserProductMappingDbSetExtensions
return ctx.UserProductMappings.Add(userProductMapping).State == EntityState.Added;
}
public static UserProductMapping? AddUserProductMapping(this IUserProductMappingDbSet ctx, Guid userProductMappingId, Guid userId, Guid productId, int permissions = 1, string? jsonDetails = null)
public static UserProductMapping? AddUserProductMapping(this IUserProductMappingDbSet ctx, Guid userProductMappingId, Guid userId, Guid productId, int permissions = 1, UserProductJsonDetailModel? userProductToCars = null)
{
var userProductMapping = new UserProductMapping(userProductMappingId, userId, productId, permissions, jsonDetails);
var userProductMapping = new UserProductMapping(userProductMappingId, userId, productId, permissions, userProductToCars);
return ctx.AddUserProductMapping(userProductMapping) ? userProductMapping : null;
}
@ -52,7 +53,7 @@ public static class UserProductMappingDbSetExtensions
return ctx.UserProductMappings.Update(userProductMapping).State == EntityState.Modified;
}
public static UserProductMapping? UpdateUserProductMapping(this IUserProductMappingDbSet ctx, Guid userProductMappingId, int permissions = 1, string? jsonDetails = null)
public static UserProductMapping? UpdateUserProductMapping(this IUserProductMappingDbSet ctx, Guid userProductMappingId, int permissions = 1, UserProductJsonDetailModel? userProductToCars = null)
{
if (userProductMappingId.IsNullOrEmpty() || permissions < 0)
return null;
@ -61,25 +62,29 @@ public static class UserProductMappingDbSetExtensions
if (userProductMapping == null) return null;
userProductMapping.Permissions = permissions;
userProductMapping.JsonDetails = jsonDetails;
userProductMapping.JsonDetailModel = userProductToCars;
return ctx.UpdateUserProductMapping(userProductMapping) ? userProductMapping : null;
}
public static bool RemoveUserProductMapping(this IUserProductMappingDbSet ctx, UserProductMapping? userProductMapping)
{
if (userProductMapping == null) return false;
return ctx.UserProductMappings.Remove(userProductMapping).State == EntityState.Deleted;
}
public static bool RemoveUserProductMapping(this IUserProductMappingDbSet ctx, Guid userProductMappingId)
{
var userProductMapping = ctx.GetUserProductMappingById(userProductMappingId, false);
if (userProductMapping == null) return true;
return ctx.UserProductMappings.Remove(userProductMapping).State == EntityState.Deleted;
return userProductMapping == null || ctx.RemoveUserProductMapping(userProductMapping);
}
public static bool RemoveUserProductMapping(this IUserProductMappingDbSet ctx, Guid userId, Guid productId)
{
var userProductMapping = ctx.GetUserProductMapping(userId, productId, false);
if (userProductMapping == null) return true;
return ctx.UserProductMappings.Remove(userProductMapping).State == EntityState.Deleted;
return userProductMapping == null || ctx.RemoveUserProductMapping(userProductMapping);
}
}

View File

@ -34,5 +34,12 @@ public static class ProductEntityTypeBuilderExtensions
modelBuilder.Navigation(e => e.ServiceProvider).AutoInclude(autoInclude);
}
public static void BuildProductToProfileRelation(this EntityTypeBuilder<Product> modelBuilder, bool autoInclude = true)
{
//modelBuilder.HasOne(x => x.Profile)
modelBuilder.Navigation(e => e.Profile).AutoInclude(autoInclude);
}
#endregion Product
}

View File

@ -11,6 +11,8 @@ public class ProductEntityTypeDefaultConfiguration : IAcEntityTypeConfiguration<
{
public void Configure(EntityTypeBuilder<Product> builder)
{
builder.BuildProductToProfileRelation();
//builder.BuildProductToUserProductMappingRelation();
builder.BuildProductToServiceProviderRelation();
}

View File

@ -18,7 +18,6 @@
<Folder Include="DataLayers\Permissions\" />
<Folder Include="DataLayers\Products\" />
<Folder Include="DbSets\Addresses\" />
<Folder Include="DbSets\Transfers\" />
<Folder Include="DbSets\ServiceProvider\" />
<Folder Include="Extensions\" />
</ItemGroup>

View File

@ -1,33 +1,28 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations.Schema;
using AyCode.Interfaces.Entities;
using AyCode.Interfaces.TimeStampInfo;
using TIAM.Core.Enums;
namespace TIAM.Entities.Drivers
{
public class Car : IEntityGuid, ITimeStampModified
public class Car : IEntityGuid//, ITimeStampInfo, ITimeStampDisableAutoSet
{
public Guid Id { get; set; }
//[NotMapped]
public Guid Id { get; set; } = Guid.NewGuid();
public int CountryCode { get; set; }
public int CountryCode { get; set; } = 36;
public string LicencePlate { get; set; }
public string Color { get; set; }
public string Manufacture{ get; set; }
public string CarModel { get; set; }
public int YearOfMake { get; set; }
public int SeetNumber { get; set; }
public string LicencePlate { get; set; } = "JGH452";
public string Color { get; set; } = "Fehér";
public string Manufacture { get; set; } = "Ford";
public string CarModel { get; set; } = "Mondeo";
public CarMotorType CarMotorType { get; set; }
public int YearOfMake { get; set; } = 2021;
public int SeatNumber { get; set; } = 5;
public CarMotorType CarMotorType { get; set; } = CarMotorType.Diesel;
public DateTime Modified { get; set; }
public DateTime Created { get; set; }
public DateTime Created { get; set; } = DateTime.UtcNow;
public DateTime Modified { get; set; } = DateTime.UtcNow;
}
}

View File

@ -0,0 +1,23 @@
namespace TIAM.Entities.Drivers;
public class UserProductJsonDetailModel
{
//public string Value { get; set; } = "ANYÁD!!!";
//[NotMapped]
public List<UserProductToCar>? Cars { get; set; }
//public List<UserProductToCarTest>? Cars2 { get; set; }
public UserProductJsonDetailModel(){}
public UserProductJsonDetailModel(List<UserProductToCar>? cars)
{
Cars = cars;
//Cars2 = [new UserProductToCarTest()];
}
}
public class UserProductToCarTest
{
public string DisplayName { get; set; } = "dfasbhsftvfrv rvfe qvfr ";
}

View File

@ -0,0 +1,37 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
using AyCode.Interfaces.Entities;
using AyCode.Interfaces.TimeStampInfo;
using Microsoft.EntityFrameworkCore;
namespace TIAM.Entities.Drivers;
//[Table(nameof(UserProductToCar))]
//[Owned]
public class UserProductToCar //: IEntityGuid//, ITimeStampInfo, ITimeStampDisableAutoSet
{
/// <summary>
/// Primary key [Guid Id]
/// </summary>
public Guid UserProductCarId { get; set; }
//[NotMapped, JsonIgnore]
//public Guid UserProductMappingId { get; set; }
public Car Car { get; set; }
public DateTime Created { get; set; } = DateTime.UtcNow;
public DateTime Modified { get; set; } = DateTime.UtcNow;
public UserProductToCar()
{ }
public UserProductToCar(Car car) : this(Guid.NewGuid(), car)
{ }
public UserProductToCar(Guid userProductCarId, Car car)
{
UserProductCarId = userProductCarId;
Car = car;
}
}

View File

@ -0,0 +1,9 @@
namespace TIAM.Entities.Products;
public interface IProductForeignKey<T>
{
public T ProductId { get; set; }
}
public interface IProductForeignKey : IProductForeignKey<Guid>
{ }

View File

@ -11,6 +11,7 @@ namespace TIAM.Entities.Products;
[Table("Products")]
public class Product : ProductBase
{
[Required]
public Guid ServiceProviderId { get; set; }
public virtual TiamServiceProvider ServiceProvider { get; set; }

View File

@ -1,19 +1,27 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using AyCode.Interfaces.Entities;
using AyCode.Interfaces.Profiles;
using AyCode.Interfaces.TimeStampInfo;
using TIAM.Core.Enums;
using TIAM.Entities.Profiles;
namespace TIAM.Entities.Products;
public abstract class ProductBase : IEntityGuid, ITimeStampInfo
public abstract class ProductBase : IEntityGuid, ITimeStampInfo, IProfileRelation
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
public Guid Id { get; set; }
[Required]
public ProductType ProductType { get; set; }
//public Guid? UserMediaId { get; set; }
[Required]
public Guid ProfileId { get; set; }
[ForeignKey(nameof(ProfileId))]
public virtual Profile Profile { get; set; }
public string Name { get; set; }
public string Description { get; set; }

View File

@ -0,0 +1,7 @@
using AyCode.Interfaces.Profiles;
namespace TIAM.Entities.Profiles;
public interface IProfileRelation : IAcProfileRelation<Profile>
{
}

View File

@ -35,4 +35,8 @@
<Folder Include="Emails\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="8.0.0" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,37 @@
using AyCode.Interfaces.Entities;
using AyCode.Interfaces.TimeStampInfo;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
using TIAM.Core.Enums;
using TIAM.Entities.Drivers;
using TIAM.Entities.Products;
namespace TIAM.Entities.Transfers;
[Table(nameof(Transfer))]
public class Transfer: IEntityGuid, ITimeStampInfo, IProductForeignKey<Guid?>
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
public Guid Id { get; set; }
[Required] public Guid UserProductToCarId { get; set; }
[Required] public TransferStatusType TransferStatusType { get; set; } = TransferStatusType.OrderSubmitted;
[Required] public DateTime Appointment { get; set; }
public bool Payed { get; set; }
public double? Price { get; set; }
public byte PassengerCount { get; set; }
[MaxLength(50)] public string? FlightNumber { get; set; }
[MaxLength(200)] public string FromAddress { get; set; }
[MaxLength(200)] public string? ToAddress { get; set; }
[MaxLength(250)] public string? Comment { get; set; }
[Column("ReferralProductId")]
public Guid? ProductId { get; set; }
public DateTime Created { get; set; }
public DateTime Modified { get; set; }
}

View File

@ -1,14 +1,17 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Runtime.Serialization;
using System.Text.Json.Serialization;
using AyCode.Interfaces.Entities;
using AyCode.Interfaces.TimeStampInfo;
using AyCode.Interfaces.Users;
using TIAM.Entities.Drivers;
using TIAM.Entities.Products;
namespace TIAM.Entities.Users;
[Table("UserProductMapping")]
public class UserProductMapping : IEntityGuid, ITimeStampInfo
public class UserProductMapping : IEntityGuid, IUserForeignKey, IProductForeignKey, ITimeStampInfo
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid Id { get; set; }
@ -19,7 +22,12 @@ public class UserProductMapping : IEntityGuid, ITimeStampInfo
public virtual Product Product { get; set; }
public int Permissions { get; set; } = 1;
public string? JsonDetails { get; set; }
//[JsonIgnore]
//private string? JsonDetails { get; set; }
//[Column("JsonDetailModel")]
public UserProductJsonDetailModel? JsonDetailModel { get; set; } = null;
public DateTime Created { get; set; }
public DateTime Modified { get; set; }
@ -35,13 +43,14 @@ public class UserProductMapping : IEntityGuid, ITimeStampInfo
public UserProductMapping(Guid id, Guid userId, Guid productId, int permissions) : this(id, userId, productId, permissions, null)
{ }
public UserProductMapping(Guid id, Guid userId, Guid productId, int permissions, string? jsonDetails) : this()
public UserProductMapping(Guid id, Guid userId, Guid productId, int permissions, UserProductJsonDetailModel? toJsonDetailModel) : this()
{
Id = id;
UserId = userId;
ProductId = productId;
Permissions = permissions;
JsonDetails = jsonDetails;
JsonDetailModel = toJsonDetailModel;
}
}

View File

@ -9,6 +9,6 @@ namespace TIAM.Models.Drivers
{
public class DriverModel
{
public List<Car> Cars { get; set; }
//public List<Car> Cars { get; set; }
}
}

View File

@ -1,12 +1,6 @@
using AyCode.Models.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.AccessControl;
using System.Text;
using System.Threading.Tasks;
namespace TIAM.Entities.Products.DTOs
namespace TIAM.Models.Dtos.Products
{
public class AssignedPermissionModel
{

View File

@ -5,9 +5,10 @@ namespace TIAM.Models.Dtos.Profiles;
public class ProfileDto : IProfileDto
{
public Guid Id { get; set; }
public Guid OwnerId { get; set; }
public Guid? UserMediaId { get; set; }
public string? Name { get; set; }
public string Name { get; set; }
public string? Description { get; set; }
public string? ThumbnailUrl { get; set; }
}

View File

@ -8,8 +8,12 @@ namespace TIAM.Models.Dtos.Users;
public class UserDto : IUserDto
{
public Guid Id { get; set; }
public Guid ProfileId { get; set; }
public Profile Profile { get; set; }
public Guid AffiliateId { get; set; }
public List<TiamServiceProvider> ServiceProviders { get; set; }
public List<UserToServiceProvider> UserToServiceProviders { get; set; }
}

View File

@ -4,8 +4,8 @@ using System.Net.Http.Json;
using System.Text.Json;
using TIAM.Entities.Permissions;
using TIAM.Entities.Products;
using TIAM.Entities.Products.DTOs;
using TIAM.Entities.TransferDestinations;
using TIAM.Models.Dtos.Products;
using TIAMWebApp.Shared.Application.Interfaces;
using TIAMWebApp.Shared.Application.Models;
using TIAMWebApp.Shared.Application.Models.ClientSide;

View File

@ -5,8 +5,8 @@ using System.Text;
using System.Threading.Tasks;
using TIAM.Entities.Permissions;
using TIAM.Entities.Products;
using TIAM.Entities.Products.DTOs;
using TIAM.Entities.ServiceProviders;
using TIAM.Models.Dtos.Products;
namespace TIAMWebApp.Shared.Application.Interfaces
{