diff --git a/TIAM.Entities/Drivers/CarMotorType.cs b/TIAM.Core/Enums/CarMotorType.cs similarity index 70% rename from TIAM.Entities/Drivers/CarMotorType.cs rename to TIAM.Core/Enums/CarMotorType.cs index c03429f3..dee10b0a 100644 --- a/TIAM.Entities/Drivers/CarMotorType.cs +++ b/TIAM.Core/Enums/CarMotorType.cs @@ -1,4 +1,4 @@ -namespace TIAM.Entities.Drivers; +namespace TIAM.Core.Enums; public enum CarMotorType : byte { diff --git a/TIAM.Core/Enums/TransferStatusType.cs b/TIAM.Core/Enums/TransferStatusType.cs new file mode 100644 index 00000000..1bb3ff28 --- /dev/null +++ b/TIAM.Core/Enums/TransferStatusType.cs @@ -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, +} \ No newline at end of file diff --git a/TIAM.Database.Test/AdminDalTest.cs b/TIAM.Database.Test/AdminDalTest.cs index 0db78b8a..0f85b2d1 100644 --- a/TIAM.Database.Test/AdminDalTest.cs +++ b/TIAM.Database.Test/AdminDalTest.cs @@ -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(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 } } \ No newline at end of file diff --git a/TIAM.Database/DataLayers/Admins/AdminDal.cs b/TIAM.Database/DataLayers/Admins/AdminDal.cs index 06337d21..dd0e89ee 100644 --- a/TIAM.Database/DataLayers/Admins/AdminDal.cs +++ b/TIAM.Database/DataLayers/Admins/AdminDal.cs @@ -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 AddTransferAsync(Transfer transfer) => TransactionAsync(ctx => ctx.AddTransfer(transfer) && ctx.SaveChanges() > 0); + public Task UpdateTransferAsync(Transfer transfer) => TransactionAsync(ctx => ctx.UpdateTransfer(transfer) && ctx.SaveChanges() > 0); + public Task RemoveTransferAsync(Transfer transfer) => TransactionAsync(ctx => ctx.RemoveTransfer(transfer) && ctx.SaveChanges() > 0); + public Task 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 AddProduct(Product product) => TransactionAsync(ctx => ctx.AddProduct(product)); + public Task AddProduct(Product product) => TransactionAsync(ctx => ctx.AddProduct(product) && ctx.SaveChanges() > 0); + + public Task UpdateProduct(Product product) => TransactionAsync(ctx => ctx.UpdateProduct(product) && ctx.SaveChanges() > 0); + public Task 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 GetUserProductMappingByIdAsync(Guid userProductMappingId, bool autoInclude = true) => SessionAsync(ctx => ctx.GetUserProductMappingById(userProductMappingId, autoInclude)); @@ -57,13 +73,13 @@ namespace TIAM.Database.DataLayers.Admins public Task AddUserProductMappingAsync(UserProductMapping userProductMapping) => TransactionAsync(ctx => ctx.AddUserProductMapping(userProductMapping) && ctx.SaveChanges() == 1); - public async Task AddUserProductMappingAsync(Guid userProductMappingId, Guid userId, Guid productId, int permissions = 1, string? jsonDetails = null) + public async Task 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 UpdateUserProductMappingAsync(UserProductMapping userProductMapping) => TransactionAsync(ctx => ctx.UpdateUserProductMapping(userProductMapping) && ctx.SaveChanges() > 0); - public async Task UpdateUserProductMappingAsync(Guid userProductMappingId, int permissions = 1, string? jsonDetails = null) + public async Task 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 DeleteProductByIdAsync(Guid productId) { diff --git a/TIAM.Database/DataLayers/Admins/AdminDalDbContextExtension.cs b/TIAM.Database/DataLayers/Admins/AdminDalDbContextExtension.cs index 4721399a..c1c4785a 100644 --- a/TIAM.Database/DataLayers/Admins/AdminDalDbContextExtension.cs +++ b/TIAM.Database/DataLayers/Admins/AdminDalDbContextExtension.cs @@ -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); diff --git a/TIAM.Database/DataLayers/ServiceProviders/ServiceProviderDal.cs b/TIAM.Database/DataLayers/ServiceProviders/ServiceProviderDal.cs index 1e11b529..f30a106c 100644 --- a/TIAM.Database/DataLayers/ServiceProviders/ServiceProviderDal.cs +++ b/TIAM.Database/DataLayers/ServiceProviders/ServiceProviderDal.cs @@ -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; diff --git a/TIAM.Database/DbContexts/Admins/AdminDbContext.cs b/TIAM.Database/DbContexts/Admins/AdminDbContext.cs index b8b7e967..44ca2241 100644 --- a/TIAM.Database/DbContexts/Admins/AdminDbContext.cs +++ b/TIAM.Database/DbContexts/Admins/AdminDbContext.cs @@ -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 Users { get; set; } public DbSet TransferDestinations { get; set; } + public DbSet Transfers { get; set; } public DbSet ServiceProviders { get; set; } public DbSet 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()); modelBuilder.Entity().Navigation(e => e.Address).AutoInclude(true); + + + //modelBuilder.Entity().Ignore(x => x.Id); + //modelBuilder.Entity().Ignore(x => x.Id); + ////modelBuilder.Entity().Ignore(x => x.Cars); + //modelBuilder.Entity().Ignore(x => x.Cars); + + //modelBuilder.Entity().HasNoKey(); + //modelBuilder.Entity().HasNoKey(); + + modelBuilder.Entity().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().OwnsOne( + // userToProduct => userToProduct.Car, ownedNavigationBuilder => + // { + // ownedNavigationBuilder.ToJson(); + // }); + } } } diff --git a/TIAM.Database/DbContexts/Admins/IAdminDbContext.cs b/TIAM.Database/DbContexts/Admins/IAdminDbContext.cs index 3440de7e..c6f0b79d 100644 --- a/TIAM.Database/DbContexts/Admins/IAdminDbContext.cs +++ b/TIAM.Database/DbContexts/Admins/IAdminDbContext.cs @@ -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 { } \ No newline at end of file diff --git a/TIAM.Database/DbContexts/Users/UserDbContext.cs b/TIAM.Database/DbContexts/Users/UserDbContext.cs index 900af945..681d9f9b 100644 --- a/TIAM.Database/DbContexts/Users/UserDbContext.cs +++ b/TIAM.Database/DbContexts/Users/UserDbContext.cs @@ -63,6 +63,21 @@ namespace TIAM.Database.DbContexts.Users //modelBuilder.Entity().BuildProductToServiceProviderRelation(); //new UserProductMappingEntityTypeDefaultConfiguration().Configure(modelBuilder.Entity()); + + modelBuilder.Entity().OwnsOne( + userToProduct => userToProduct.JsonDetailModel, builderUserProductJsonDetail => + { + builderUserProductJsonDetail.ToJson(); + + builderUserProductJsonDetail.OwnsMany(userProductJsonDetail => userProductJsonDetail.Cars, builderUserProductToCar => + { + builderUserProductToCar.OwnsOne(userProductToCar => userProductToCar.Car, builderCar => + { + }); + }); + + //builderUserProductJsonDetail.OwnsMany(userProductJsonDetail => userProductJsonDetail.Cars2); + }); } } } diff --git a/TIAM.Database/DbSets/Products/ProductDbSetExtensins.cs b/TIAM.Database/DbSets/Products/ProductDbSetExtensins.cs index c9e0a339..7728a7ee 100644 --- a/TIAM.Database/DbSets/Products/ProductDbSetExtensins.cs +++ b/TIAM.Database/DbSets/Products/ProductDbSetExtensins.cs @@ -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 ProductsWithUserRelations(this IProductDbSet ctx, bool autoInclude = true) diff --git a/TIAM.Database/DbSets/Transfers/ITransferDbSet.cs b/TIAM.Database/DbSets/Transfers/ITransferDbSet.cs new file mode 100644 index 00000000..fb9ceeb8 --- /dev/null +++ b/TIAM.Database/DbSets/Transfers/ITransferDbSet.cs @@ -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 Transfers { get; } +} \ No newline at end of file diff --git a/TIAM.Database/DbSets/Transfers/TransferDbSetExtensions.cs b/TIAM.Database/DbSets/Transfers/TransferDbSetExtensions.cs new file mode 100644 index 00000000..757320d6 --- /dev/null +++ b/TIAM.Database/DbSets/Transfers/TransferDbSetExtensions.cs @@ -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 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 GetTransferDestinations(this ITransferDestinationDbSet ctx) + => ctx.TransferDestinations; + +} \ No newline at end of file diff --git a/TIAM.Database/DbSets/Users/UserProductMappingDbSetExtensions.cs b/TIAM.Database/DbSets/Users/UserProductMappingDbSetExtensions.cs index da60162c..9fe01c71 100644 --- a/TIAM.Database/DbSets/Users/UserProductMappingDbSetExtensions.cs +++ b/TIAM.Database/DbSets/Users/UserProductMappingDbSetExtensions.cs @@ -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); } - } \ No newline at end of file diff --git a/TIAM.Database/ModelBuilders/Products/ProductEntityTypeBuilderExtensions.cs b/TIAM.Database/ModelBuilders/Products/ProductEntityTypeBuilderExtensions.cs index 69d37173..efdef73f 100644 --- a/TIAM.Database/ModelBuilders/Products/ProductEntityTypeBuilderExtensions.cs +++ b/TIAM.Database/ModelBuilders/Products/ProductEntityTypeBuilderExtensions.cs @@ -34,5 +34,12 @@ public static class ProductEntityTypeBuilderExtensions modelBuilder.Navigation(e => e.ServiceProvider).AutoInclude(autoInclude); } + public static void BuildProductToProfileRelation(this EntityTypeBuilder modelBuilder, bool autoInclude = true) + { + //modelBuilder.HasOne(x => x.Profile) + + modelBuilder.Navigation(e => e.Profile).AutoInclude(autoInclude); + } + #endregion Product } \ No newline at end of file diff --git a/TIAM.Database/ModelBuilders/Products/ProductEntityTypeConfigurations.cs b/TIAM.Database/ModelBuilders/Products/ProductEntityTypeConfigurations.cs index 3a9b7a31..f473502e 100644 --- a/TIAM.Database/ModelBuilders/Products/ProductEntityTypeConfigurations.cs +++ b/TIAM.Database/ModelBuilders/Products/ProductEntityTypeConfigurations.cs @@ -11,6 +11,8 @@ public class ProductEntityTypeDefaultConfiguration : IAcEntityTypeConfiguration< { public void Configure(EntityTypeBuilder builder) { + builder.BuildProductToProfileRelation(); + //builder.BuildProductToUserProductMappingRelation(); builder.BuildProductToServiceProviderRelation(); } diff --git a/TIAM.Database/TIAM.Database.csproj b/TIAM.Database/TIAM.Database.csproj index c219be5b..4401deb4 100644 --- a/TIAM.Database/TIAM.Database.csproj +++ b/TIAM.Database/TIAM.Database.csproj @@ -18,7 +18,6 @@ - diff --git a/TIAM.Entities/Drivers/Car.cs b/TIAM.Entities/Drivers/Car.cs index e17a1b25..271184bd 100644 --- a/TIAM.Entities/Drivers/Car.cs +++ b/TIAM.Entities/Drivers/Car.cs @@ -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; } } diff --git a/TIAM.Entities/Drivers/UserProductJsonDetailModel.cs b/TIAM.Entities/Drivers/UserProductJsonDetailModel.cs new file mode 100644 index 00000000..629d643d --- /dev/null +++ b/TIAM.Entities/Drivers/UserProductJsonDetailModel.cs @@ -0,0 +1,23 @@ +namespace TIAM.Entities.Drivers; + +public class UserProductJsonDetailModel +{ + //public string Value { get; set; } = "ANYÁD!!!"; + + //[NotMapped] + public List? Cars { get; set; } + //public List? Cars2 { get; set; } + + public UserProductJsonDetailModel(){} + + public UserProductJsonDetailModel(List? cars) + { + Cars = cars; + //Cars2 = [new UserProductToCarTest()]; + } +} + +public class UserProductToCarTest +{ + public string DisplayName { get; set; } = "dfasbhsftvfrv rvfe qvfr "; +} diff --git a/TIAM.Entities/Drivers/UserProductToCar.cs b/TIAM.Entities/Drivers/UserProductToCar.cs new file mode 100644 index 00000000..57fd9faf --- /dev/null +++ b/TIAM.Entities/Drivers/UserProductToCar.cs @@ -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 +{ + /// + /// Primary key [Guid Id] + /// + 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; + } +} \ No newline at end of file diff --git a/TIAM.Entities/Products/IProductForeignKey.cs b/TIAM.Entities/Products/IProductForeignKey.cs new file mode 100644 index 00000000..930da46e --- /dev/null +++ b/TIAM.Entities/Products/IProductForeignKey.cs @@ -0,0 +1,9 @@ +namespace TIAM.Entities.Products; + +public interface IProductForeignKey +{ + public T ProductId { get; set; } +} + +public interface IProductForeignKey : IProductForeignKey +{ } diff --git a/TIAM.Entities/Products/Product.cs b/TIAM.Entities/Products/Product.cs index 48a6e700..5f8d50f3 100644 --- a/TIAM.Entities/Products/Product.cs +++ b/TIAM.Entities/Products/Product.cs @@ -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; } diff --git a/TIAM.Entities/Products/ProductBase.cs b/TIAM.Entities/Products/ProductBase.cs index 80315e7d..8f0e6924 100644 --- a/TIAM.Entities/Products/ProductBase.cs +++ b/TIAM.Entities/Products/ProductBase.cs @@ -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; } diff --git a/TIAM.Entities/Profiles/IProfileRelation.cs b/TIAM.Entities/Profiles/IProfileRelation.cs new file mode 100644 index 00000000..9029287e --- /dev/null +++ b/TIAM.Entities/Profiles/IProfileRelation.cs @@ -0,0 +1,7 @@ +using AyCode.Interfaces.Profiles; + +namespace TIAM.Entities.Profiles; + +public interface IProfileRelation : IAcProfileRelation +{ +} \ No newline at end of file diff --git a/TIAM.Entities/ServiceProviders/ServiceProvider.cs b/TIAM.Entities/ServiceProviders/TiamServiceProvider.cs similarity index 100% rename from TIAM.Entities/ServiceProviders/ServiceProvider.cs rename to TIAM.Entities/ServiceProviders/TiamServiceProvider.cs diff --git a/TIAM.Entities/TIAM.Entities.csproj b/TIAM.Entities/TIAM.Entities.csproj index 37cf4d4b..911cb6fb 100644 --- a/TIAM.Entities/TIAM.Entities.csproj +++ b/TIAM.Entities/TIAM.Entities.csproj @@ -35,4 +35,8 @@ + + + + diff --git a/TIAM.Entities/Transfers/Transfer.cs b/TIAM.Entities/Transfers/Transfer.cs new file mode 100644 index 00000000..884dbb5d --- /dev/null +++ b/TIAM.Entities/Transfers/Transfer.cs @@ -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 +{ + [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; } +} \ No newline at end of file diff --git a/TIAM.Entities/TransferDestinations/TransferDestination.cs b/TIAM.Entities/Transfers/TransferDestination.cs similarity index 100% rename from TIAM.Entities/TransferDestinations/TransferDestination.cs rename to TIAM.Entities/Transfers/TransferDestination.cs diff --git a/TIAM.Entities/Users/UserProductMapping.cs b/TIAM.Entities/Users/UserProductMapping.cs index 67b5092d..e279903c 100644 --- a/TIAM.Entities/Users/UserProductMapping.cs +++ b/TIAM.Entities/Users/UserProductMapping.cs @@ -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; } } \ No newline at end of file diff --git a/TIAM.Models/Drivers/DriverModel.cs b/TIAM.Models/Drivers/DriverModel.cs index aca16aed..7a29b890 100644 --- a/TIAM.Models/Drivers/DriverModel.cs +++ b/TIAM.Models/Drivers/DriverModel.cs @@ -9,6 +9,6 @@ namespace TIAM.Models.Drivers { public class DriverModel { - public List Cars { get; set; } + //public List Cars { get; set; } } } diff --git a/TIAM.Models/Dtos/Products/AssignedPermissionModel.cs b/TIAM.Models/Dtos/Products/AssignedPermissionModel.cs index 43affc9f..aadfa599 100644 --- a/TIAM.Models/Dtos/Products/AssignedPermissionModel.cs +++ b/TIAM.Models/Dtos/Products/AssignedPermissionModel.cs @@ -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 { diff --git a/TIAM.Models/Dtos/Profiles/ProfileDto.cs b/TIAM.Models/Dtos/Profiles/ProfileDto.cs index 7ece3932..0fa895b0 100644 --- a/TIAM.Models/Dtos/Profiles/ProfileDto.cs +++ b/TIAM.Models/Dtos/Profiles/ProfileDto.cs @@ -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; } } \ No newline at end of file diff --git a/TIAM.Models/Dtos/Users/UserDto.cs b/TIAM.Models/Dtos/Users/UserDto.cs index d61ace33..b0d9139a 100644 --- a/TIAM.Models/Dtos/Users/UserDto.cs +++ b/TIAM.Models/Dtos/Users/UserDto.cs @@ -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 ServiceProviders { get; set; } public List UserToServiceProviders { get; set; } } \ No newline at end of file diff --git a/TIAMWebApp/Client/Services/PermissionService.cs b/TIAMWebApp/Client/Services/PermissionService.cs index c64d147f..80567f09 100644 --- a/TIAMWebApp/Client/Services/PermissionService.cs +++ b/TIAMWebApp/Client/Services/PermissionService.cs @@ -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; diff --git a/TIAMWebApp/Shared/Interfaces/IPermissionService.cs b/TIAMWebApp/Shared/Interfaces/IPermissionService.cs index c25631a4..9fb29bad 100644 --- a/TIAMWebApp/Shared/Interfaces/IPermissionService.cs +++ b/TIAMWebApp/Shared/Interfaces/IPermissionService.cs @@ -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 {