diff --git a/TIAM.Core/Enums/SeatNumberPriceType.cs b/TIAM.Core/Enums/SeatNumberPriceType.cs new file mode 100644 index 00000000..bd9673e4 --- /dev/null +++ b/TIAM.Core/Enums/SeatNumberPriceType.cs @@ -0,0 +1,8 @@ +namespace TIAM.Core.Enums; + +public enum SeatNumberPriceType : byte +{ + Price1SeatNum = 0, + Price2SeatNum = 4, + Price3SeatNum = 8, +} \ No newline at end of file diff --git a/TIAM.Database/DbContexts/Admins/AdminDbContext.cs b/TIAM.Database/DbContexts/Admins/AdminDbContext.cs index 8aa0ae2c..03c9932b 100644 --- a/TIAM.Database/DbContexts/Admins/AdminDbContext.cs +++ b/TIAM.Database/DbContexts/Admins/AdminDbContext.cs @@ -83,32 +83,33 @@ namespace TIAM.Database.DbContexts.Admins //modelBuilder.Entity().HasNoKey(); //modelBuilder.Entity().HasNoKey(); - modelBuilder.Entity().OwnsOne( - userToProduct => userToProduct.JsonDetailModel, builderUserProductJsonDetail => - { - builderUserProductJsonDetail.ToJson(); - //builderUserProductJsonDetail.Property(nameof(UserProductMapping.JsonDetailModel)).HasColumnName("JsonDetailModel"); + //JSONMODEL - J. + //modelBuilder.Entity().OwnsOne( + // userToProduct => userToProduct.JsonDetailModel, builderUserProductJsonDetail => + // { + // builderUserProductJsonDetail.ToJson(); + // //builderUserProductJsonDetail.Property(nameof(UserProductMapping.JsonDetailModel)).HasColumnName("JsonDetailModel"); - builderUserProductJsonDetail.OwnsMany(userProductJsonDetail => userProductJsonDetail.Cars, builderUserProductToCar => - { - //builderUserProductToCar.ToJson(); + // builderUserProductJsonDetail.OwnsMany(userProductJsonDetail => userProductJsonDetail.Cars, builderUserProductToCar => + // { + // //builderUserProductToCar.ToJson(); - //builderUserProductToCar.Ignore(x => x.UserProductToCarId); - //builderUserProductToCar.Ignore(x => x.Created); - //builderUserProductToCar.Ignore(x => x.Modified); + // //builderUserProductToCar.Ignore(x => x.UserProductToCarId); + // //builderUserProductToCar.Ignore(x => x.Created); + // //builderUserProductToCar.Ignore(x => x.Modified); - builderUserProductToCar.OwnsOne(userProductToCar => userProductToCar.Car, builderCar => - { - //builderCar.ToJson(); + // builderUserProductToCar.OwnsOne(userProductToCar => userProductToCar.Car, builderCar => + // { + // //builderCar.ToJson(); - //builderCar.Ignore(x => x.Id); - //builderCar.Ignore(x => x.Created); - //builderCar.Ignore(x => x.Modified); - }); - }); + // //builderCar.Ignore(x => x.Id); + // //builderCar.Ignore(x => x.Created); + // //builderCar.Ignore(x => x.Modified); + // }); + // }); - //builderUserProductJsonDetail.OwnsMany(userProductJsonDetail => userProductJsonDetail.Cars2); - }); + // //builderUserProductJsonDetail.OwnsMany(userProductJsonDetail => userProductJsonDetail.Cars2); + // }); //modelBuilder.Entity().OwnsOne( // userToProduct => userToProduct.Car, ownedNavigationBuilder => diff --git a/TIAM.Database/DbContexts/Users/UserDbContext.cs b/TIAM.Database/DbContexts/Users/UserDbContext.cs index 7c4c7b12..c75d88e5 100644 --- a/TIAM.Database/DbContexts/Users/UserDbContext.cs +++ b/TIAM.Database/DbContexts/Users/UserDbContext.cs @@ -83,20 +83,20 @@ namespace TIAM.Database.DbContexts.Users //modelBuilder.Entity().BuildProductToServiceProviderRelation(); //new UserProductMappingEntityTypeDefaultConfiguration().Configure(modelBuilder.Entity()); - modelBuilder.Entity().OwnsOne( - userToProduct => userToProduct.JsonDetailModel, builderUserProductJsonDetail => - { - builderUserProductJsonDetail.ToJson(); + //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.Cars, builderUserProductToCar => + // { + // builderUserProductToCar.OwnsOne(userProductToCar => userProductToCar.Car, builderCar => + // { + // }); + // }); - //builderUserProductJsonDetail.OwnsMany(userProductJsonDetail => userProductJsonDetail.Cars2); - }); + // //builderUserProductJsonDetail.OwnsMany(userProductJsonDetail => userProductJsonDetail.Cars2); + // }); } } } diff --git a/TIAM.Entities/Drivers/Car.cs b/TIAM.Entities/Drivers/Car.cs index 271184bd..433ba17d 100644 --- a/TIAM.Entities/Drivers/Car.cs +++ b/TIAM.Entities/Drivers/Car.cs @@ -1,15 +1,20 @@ -using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; using AyCode.Interfaces.Entities; using AyCode.Interfaces.TimeStampInfo; using TIAM.Core.Enums; +using TIAM.Entities.Users; namespace TIAM.Entities.Drivers { - public class Car : IEntityGuid//, ITimeStampInfo, ITimeStampDisableAutoSet + [Table(nameof(Car))] + public class Car : IEntityGuid, ITimeStampInfo, IUserProductMappingForeignKey//, ITimeStampDisableAutoSet { - //[NotMapped] + [Key, DatabaseGenerated(DatabaseGeneratedOption.None)] public Guid Id { get; set; } = Guid.NewGuid(); + public Guid UserProductMappingId { get; set; } + public int CountryCode { get; set; } = 36; public string LicencePlate { get; set; } = "JGH452"; @@ -18,10 +23,13 @@ namespace TIAM.Entities.Drivers public string CarModel { get; set; } = "Mondeo"; public int YearOfMake { get; set; } = 2021; - public int SeatNumber { get; set; } = 5; + public byte SeatNumber { get; set; } = 5; public CarMotorType CarMotorType { get; set; } = CarMotorType.Diesel; + //public string Tulajdonos { get; set; } + //public string Üzembentartó { 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 index 629d643d..ad3d201b 100644 --- a/TIAM.Entities/Drivers/UserProductJsonDetailModel.cs +++ b/TIAM.Entities/Drivers/UserProductJsonDetailModel.cs @@ -1,10 +1,12 @@ -namespace TIAM.Entities.Drivers; +using System.ComponentModel.DataAnnotations.Schema; + +namespace TIAM.Entities.Drivers; public class UserProductJsonDetailModel { //public string Value { get; set; } = "ANYÁD!!!"; - //[NotMapped] + [NotMapped] public List? Cars { get; set; } //public List? Cars2 { get; set; } diff --git a/TIAM.Entities/Drivers/UserProductToCar.cs b/TIAM.Entities/Drivers/UserProductToCar.cs index 57fd9faf..a8983bbe 100644 --- a/TIAM.Entities/Drivers/UserProductToCar.cs +++ b/TIAM.Entities/Drivers/UserProductToCar.cs @@ -16,7 +16,7 @@ public class UserProductToCar //: IEntityGuid//, ITimeStampInfo, ITimeStampDisab /// public Guid UserProductCarId { get; set; } - //[NotMapped, JsonIgnore] + [NotMapped] //public Guid UserProductMappingId { get; set; } public Car Car { get; set; } diff --git a/TIAM.Entities/Transfers/Transfer.cs b/TIAM.Entities/Transfers/Transfer.cs index ce39efd9..68266e93 100644 --- a/TIAM.Entities/Transfers/Transfer.cs +++ b/TIAM.Entities/Transfers/Transfer.cs @@ -9,7 +9,7 @@ using TIAM.Entities.Users; namespace TIAM.Entities.Transfers; [Table(nameof(Transfer))] -public class Transfer: IEntityGuid, ITimeStampInfo, IProductForeignKey, IUserProductMappingRelation +public class Transfer: IEntityGuid, ITimeStampInfo, IProductForeignKey, IUserProductMappingRelation, IUserForeignKey { [Key, DatabaseGenerated(DatabaseGeneratedOption.None)] public Guid Id { get; set; } @@ -17,6 +17,7 @@ public class Transfer: IEntityGuid, ITimeStampInfo, IProductForeignKey, IUserPro [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int OrderId { get; } + public Guid UserId { get; set; } public Guid ProductId { get; set; } public Guid? UserProductMappingId { get; set; } public Guid? UserProductToCarId { get; set; } @@ -36,8 +37,8 @@ public class Transfer: IEntityGuid, ITimeStampInfo, IProductForeignKey, IUserPro [MaxLength(200)] public string? ToAddress { get; set; } [MaxLength(250)] public string? Comment { get; set; } - [Column("ReferralProductId")] - public Guid? ReferralProductId { get; set; } + //[Column("ReferralProductId")] + public Guid? ReferralId { get; set; } public DateTime Created { get; set; } public DateTime Modified { get; set; } diff --git a/TIAM.Entities/Transfers/TransferToDriver.cs b/TIAM.Entities/Transfers/TransferToDriver.cs new file mode 100644 index 00000000..6fb948f9 --- /dev/null +++ b/TIAM.Entities/Transfers/TransferToDriver.cs @@ -0,0 +1,24 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using AyCode.Interfaces.Entities; +using AyCode.Interfaces.TimeStampInfo; +using TIAM.Entities.Users; + +namespace TIAM.Entities.Transfers; + +[Table(nameof(TransferToDriver))] +public class TransferToDriver : IEntityGuid, ITimeStampInfo, IUserProductMappingForeignKey +{ + [Key, DatabaseGenerated(DatabaseGeneratedOption.None)] + public Guid Id { get; set; } + + public Guid TransferId { get; set; } + public Guid UserProductMappingId { get; set; } + public Guid CarId { get; set; } + + public string LicencePlate { get; set; } + public double Price { get; set; } + + public DateTime Created { get; set; } + public DateTime Modified { get; set; } +} \ No newline at end of file diff --git a/TIAM.Entities/Users/UserProductMapping.cs b/TIAM.Entities/Users/UserProductMapping.cs index 6fd2dbb3..e1942db6 100644 --- a/TIAM.Entities/Users/UserProductMapping.cs +++ b/TIAM.Entities/Users/UserProductMapping.cs @@ -30,6 +30,7 @@ public class UserProductMapping : IEntityGuid, IUserRelation, IProductRelation, //private string? JsonDetails { get; set; } //[Column("JsonDetailModel")] + [NotMapped] public UserProductJsonDetailModel? JsonDetailModel { get; set; } = null; public DateTime Created { get; set; } diff --git a/TIAMWebApp/Server/Controllers/TransferDataAPIController.cs b/TIAMWebApp/Server/Controllers/TransferDataAPIController.cs index eef35a0f..c84367ce 100644 --- a/TIAMWebApp/Server/Controllers/TransferDataAPIController.cs +++ b/TIAMWebApp/Server/Controllers/TransferDataAPIController.cs @@ -11,6 +11,7 @@ using TIAM.Database.DataLayers.Admins; using TIAM.Database.DataLayers.TransferDestinations; using TIAM.Database.DataLayers.Users; using TIAM.Database.DbContexts; +using TIAM.Entities.Products; using TIAM.Entities.Transfers; using TIAM.Entities.Users; using TIAMWebApp.Shared.Application.Models; @@ -47,6 +48,51 @@ namespace TIAMWebApp.Server.Controllers _adminDal = adminDal; } + public double GetTransferPrice(Guid productId, Guid fromTransferDestinationId, Guid toTranferDestinationId) + { + throw new NotImplementedException(); + } + + public double GetTransferPrice(Guid productId, TransferDestination fromTransferDestination, TransferDestination toTransferDestination, in byte seatNumber) + { + var product = _adminDal.GetProductById(productId); + + if (product == null) return -1; + + return GetTransferPrice(product, fromTransferDestination, toTransferDestination, in seatNumber); + } + + public double GetTransferPrice(Product product, TransferDestination fromTransferDestination, TransferDestination toTransferDestination, in byte seatNumber) + { + var baseDestination = product.Profile.AddressId == fromTransferDestination.AddressId ? toTransferDestination : fromTransferDestination; + + var transferDestinationToProduct = _adminDal.GetTransferDestinationToProduct(product.Id, baseDestination.Id); + + var tranferDestinationPrice = transferDestinationToProduct ?? baseDestination as ITransfeDestinationPrices; + + var price = GetSeatNumberPrice(in tranferDestinationPrice, seatNumber); + + //TODO: ExtraPrice - J. + + return price; + } + + public double GetSeatNumberPrice(in ITransfeDestinationPrices transfeDestinationPrices, in byte seatNumber) + => GetSeatNumberPrice(transfeDestinationPrices.Price, transfeDestinationPrices.Price2, transfeDestinationPrices.Price3, seatNumber); + + public double GetSeatNumberPrice(in double price, in double? price2, in double? price3, in byte seatNumber) + { + if (seatNumber >= (byte)SeatNumberPriceType.Price3SeatNum) + return price3 ?? price; //TODO: *seatnum percent - J. + + if (seatNumber >= (byte)SeatNumberPriceType.Price2SeatNum) + return price2 ?? price; //TODO: *seatnum percent - J. + + return price; + } + + //public double GetExtraPrice(bool? extraPriceType){} + [AllowAnonymous] [HttpGet] [Route(APIUrls.GetTransferDestinationsRouteName)] diff --git a/TIAMWebApp/Shared/Services/TransferDataService.cs b/TIAMWebApp/Shared/Services/TransferDataService.cs index accd07ed..49dcfebc 100644 --- a/TIAMWebApp/Shared/Services/TransferDataService.cs +++ b/TIAMWebApp/Shared/Services/TransferDataService.cs @@ -19,6 +19,7 @@ namespace TIAMWebApp.Shared.Application.Services this.logToBrowserConsole = logToBrowserConsole; } + public async Task> GetDestinationsAsync() {