Add TransferDestinationToProduct; TransferDestination Prices fix; improvements, fixes, etc..
This commit is contained in:
parent
8dcb641ccf
commit
b97a3eca4f
|
|
@ -325,7 +325,23 @@ namespace TIAM.Database.Test
|
|||
//Assert.IsNotNull(user.UserProductMappings[0].Product, "Product is null");
|
||||
}
|
||||
|
||||
[DataTestMethod]
|
||||
//[DataRow("273EFE3C-D19F-4C2A-BF19-7397DC835C60")]
|
||||
//[DataRow("814b5495-c2e9-4f1d-a73f-37cd5d353078")]
|
||||
[DataRow(["814b5495-c2e9-4f1d-a73f-37cd5d353078", "273EFE3C-D19F-4C2A-BF19-7397DC835C60"])]
|
||||
public void GetTransferDestionationToProductById_ReturnsTransferDestinationToProduct_WhenHasTransferDestinationRelation(string[] productIdTransferDestinationIdString)
|
||||
{
|
||||
var productId = Guid.Parse(productIdTransferDestinationIdString[0]);
|
||||
var transferDestinationId = Guid.Parse(productIdTransferDestinationIdString[1]);
|
||||
|
||||
var transferDestinationToProduct = Dal.GetTransferDestinationToProduct(productId, transferDestinationId);
|
||||
|
||||
Assert.IsNotNull(transferDestinationToProduct);
|
||||
Assert.IsNotNull(transferDestinationToProduct.TransferDestination);
|
||||
|
||||
Assert.IsTrue(transferDestinationToProduct.TransferDestination.Id == transferDestinationId, "transferDestinationToProduct.TransferDestination.Id != transferDestinationId");
|
||||
}
|
||||
|
||||
[DataTestMethod]
|
||||
[DataRow(["8f38f8e3-a92c-4979-88b1-dc812a82245f", "814b5495-c2e9-4f1d-a73f-37cd5d353078", "71392CFD-FB9C-45C1-9540-7BE3782CF26A"])]
|
||||
public async Task TransferCrudTest(string[] transferIdProductIdUserProductIdStrings)
|
||||
|
|
@ -406,9 +422,9 @@ namespace TIAM.Database.Test
|
|||
Name = name,
|
||||
Description = name + "description",
|
||||
Price = 15000,
|
||||
Price2 = 21000,
|
||||
Price3 = 23000,
|
||||
PriceType = PriceType.Fix,
|
||||
//Price2 = 21000,
|
||||
//Price3 = 23000,
|
||||
//PriceType = PriceType.Fix,
|
||||
Address = new Address
|
||||
{
|
||||
Id = addressId,
|
||||
|
|
|
|||
|
|
@ -28,9 +28,6 @@ namespace TIAM.Database.DataLayers.Admins
|
|||
}
|
||||
|
||||
#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());
|
||||
|
||||
|
|
@ -41,13 +38,28 @@ namespace TIAM.Database.DataLayers.Admins
|
|||
#endregion Transfer
|
||||
|
||||
#region TransferDestination
|
||||
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 Task<bool> AddTransferDestinationAsync(TransferDestination transferDestination) => TransactionAsync(ctx => ctx.AddTransferDestination(transferDestination));
|
||||
public Task<bool> UpdateTransferDestinationAsync(TransferDestination transferDestination) => TransactionAsync(ctx => ctx.UpdateTransferDestination(transferDestination));
|
||||
public Task<bool> RemoveTransferDestinationAsync(TransferDestination transferDestination, bool removeAddress = false) => TransactionAsync(ctx => ctx.RemoveTransferDestination(transferDestination, removeAddress));
|
||||
public Task<bool> RemoveTransferDestinationAsync(Guid transferDestinationId, bool removeAddress = false) => TransactionAsync(ctx => ctx.RemoveTransferDestination(transferDestinationId, removeAddress));
|
||||
|
||||
#endregion TransferDestination
|
||||
|
||||
#region TransferDestinationToProduct
|
||||
public TransferDestinationToProduct? GetTransferDestinationToProductById(Guid transferDestinationToProductId) => Session(ctx=>ctx.GetTransferDestinationToProductById(transferDestinationToProductId));
|
||||
public string? GetTransferDestinationToProductJsonById(Guid transferDestinationToProductId) => Session(ctx => ctx.GetTransferDestinationToProductById(transferDestinationToProductId)?.ToJson());
|
||||
|
||||
public TransferDestinationToProduct? GetTransferDestinationToProduct(Guid productId, Guid transferDestinationId) => Session(ctx=>ctx.GetTransferDestinationToProduct(productId, transferDestinationId));
|
||||
public string? GetTransferDestinationToProductJson(Guid productId, Guid transferDestinationId) => Session(ctx => ctx.GetTransferDestinationToProduct(productId, transferDestinationId)?.ToJson());
|
||||
|
||||
public Task<bool> AddTransferDestinationToProductAsync(TransferDestinationToProduct transferDestinationToProduct) => TransactionAsync(ctx => ctx.AddTransferDestinationToProduct(transferDestinationToProduct));
|
||||
public Task<bool> UpdateTransferDestinationToProductAsync(TransferDestinationToProduct transferDestinationToProduct) => TransactionAsync(ctx => ctx.UpdateTransferDestinationToProduct(transferDestinationToProduct));
|
||||
public Task<bool> RemoveTransferDestinationToProductAsync(TransferDestinationToProduct transferDestinationToProduct) => TransactionAsync(ctx => ctx.RemoveTransferDestinationToProduct(transferDestinationToProduct));
|
||||
public Task<bool> RemoveTransferDestinationToProductAsync(Guid transferDestinationToProductId) => TransactionAsync(ctx => ctx.RemoveTransferDestinationToProduct(transferDestinationToProductId));
|
||||
#endregion TransferDestinationToProduct
|
||||
|
||||
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));
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ namespace TIAM.Database.DbContexts.Admins
|
|||
{
|
||||
public DbSet<User> Users { get; set; }
|
||||
public DbSet<TransferDestination> TransferDestinations { get; set; }
|
||||
public DbSet<TransferDestinationToProduct> TransferDestinationToProducts { get; set; }
|
||||
public DbSet<Transfer> Transfers { get; set; }
|
||||
|
||||
public DbSet<TiamServiceProvider> ServiceProviders { get; set; }
|
||||
|
|
@ -69,6 +70,9 @@ namespace TIAM.Database.DbContexts.Admins
|
|||
new TransferEntityTypeDefaultConfigurations().Configure(modelBuilder.Entity<Transfer>());
|
||||
modelBuilder.Entity<TransferDestination>().Navigation(e => e.Address).AutoInclude(true);
|
||||
|
||||
modelBuilder.Entity<TransferDestinationToProduct>().HasOne(e => e.TransferDestination);
|
||||
modelBuilder.Entity<TransferDestinationToProduct>().Navigation(e => e.TransferDestination).AutoInclude(true);
|
||||
|
||||
new EmailMessageEntityTypeDefaultConfigurations().Configure(modelBuilder.Entity<EmailMessage>());
|
||||
|
||||
//modelBuilder.Entity<UserProductToCar>().Ignore(x => x.Id);
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ namespace TIAM.Database.DbContexts.ServiceProviders
|
|||
{
|
||||
public DbSet<Address> Addresses { get; set; }
|
||||
public DbSet<TransferDestination> TransferDestinations { get; set; }
|
||||
public DbSet<TransferDestinationToProduct> TransferDestinationToProducts { get; set; }
|
||||
|
||||
public DbSet<User> Users { get; set; }
|
||||
public DbSet<UserProductMapping> UserProductMappings { get; set; }
|
||||
|
|
@ -67,8 +68,8 @@ namespace TIAM.Database.DbContexts.ServiceProviders
|
|||
new UserEntityTypeDefaultConfiguration().Configure(modelBuilder.Entity<User>());
|
||||
//new UserProductMappingEntityTypeDefaultConfiguration().Configure(modelBuilder.Entity<UserProductMapping>());
|
||||
|
||||
new ProductEntityTypeDefaultConfiguration().Configure(modelBuilder.Entity<Product>());
|
||||
modelBuilder.Entity<TransferDestination>().Navigation(e => e.Address).AutoInclude(true);
|
||||
//modelBuilder.Entity<TransferDestinationToProduct>().HasOne(e => e.TransferDestination);
|
||||
//modelBuilder.Entity<TransferDestinationToProduct>().Navigation(e => e.TransferDestination).AutoInclude(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,8 @@ namespace TIAM.Database.DbContexts.Users
|
|||
public DbSet<Address> Addresses { get; set; }
|
||||
|
||||
public DbSet<Transfer> Transfers { get; set; }
|
||||
public DbSet<TransferDestinationToProduct> TransferDestinationToProducts { get; set; }
|
||||
|
||||
public DbSet<EmailMessage> EmailMessages { get; set; }
|
||||
|
||||
public DbSet<TransferDestination> TransferDestinations { get; set; }
|
||||
|
|
@ -74,6 +76,9 @@ namespace TIAM.Database.DbContexts.Users
|
|||
|
||||
new EmailMessageEntityTypeDefaultConfigurations().Configure(modelBuilder.Entity<EmailMessage>());
|
||||
|
||||
//modelBuilder.Entity<TransferDestinationToProduct>().HasOne(e => e.TransferDestination);
|
||||
//modelBuilder.Entity<TransferDestinationToProduct>().Navigation(e => e.TransferDestination).AutoInclude(true);
|
||||
|
||||
|
||||
//modelBuilder.Entity<Product>().BuildProductToServiceProviderRelation();
|
||||
//new UserProductMappingEntityTypeDefaultConfiguration().Configure(modelBuilder.Entity<UserProductMapping>());
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using TIAM.Database.DbSets.Addresses;
|
||||
using TIAM.Entities.Addresses;
|
||||
using TIAM.Entities.Products;
|
||||
using TIAM.Entities.Transfers;
|
||||
|
||||
namespace TIAM.Database.DbSets.Transfers;
|
||||
|
||||
public interface ITransferDestinationDbSet
|
||||
public interface ITransferDestinationDbSet : IAddressDbSet, ITransferDestinationToProductDbSet
|
||||
{
|
||||
public DbSet<TransferDestination> TransferDestinations { get; set; }
|
||||
public DbSet<Address> Addresses { get; set; }
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using TIAM.Entities.Transfers;
|
||||
|
||||
namespace TIAM.Database.DbSets.Transfers;
|
||||
|
||||
public interface ITransferDestinationToProductDbSet
|
||||
{
|
||||
public DbSet<TransferDestinationToProduct> TransferDestinationToProducts { get; set; }
|
||||
}
|
||||
|
|
@ -55,6 +55,30 @@ public static class TransferDbSetExtensions
|
|||
var transferDestination = ctx.GetTransferDestinationById(transferDestinationId);
|
||||
return transferDestination == null || ctx.RemoveTransferDestination(transferDestination, removeAddress);
|
||||
}
|
||||
|
||||
#endregion TransferDestination
|
||||
|
||||
#region TransferDestinationToProduct
|
||||
public static TransferDestinationToProduct? GetTransferDestinationToProductById(this ITransferDestinationToProductDbSet ctx, Guid transferDestinationToProductId)
|
||||
=> ctx.TransferDestinationToProducts.FirstOrDefault(x => x.Id == transferDestinationToProductId);
|
||||
|
||||
public static TransferDestinationToProduct? GetTransferDestinationToProduct(this ITransferDestinationToProductDbSet ctx, Guid productId, Guid transferDestinationId)
|
||||
=> ctx.TransferDestinationToProducts.FirstOrDefault(x => x.ProductId == productId && x.TransferDestinationId == transferDestinationId);
|
||||
|
||||
public static bool AddTransferDestinationToProduct(this ITransferDestinationToProductDbSet ctx, TransferDestinationToProduct transferDestinationToProduct)
|
||||
=> ctx.TransferDestinationToProducts.Add(transferDestinationToProduct).State == EntityState.Added;
|
||||
|
||||
public static bool UpdateTransferDestinationToProduct(this ITransferDestinationToProductDbSet ctx, TransferDestinationToProduct transferDestinationToProduct)
|
||||
=> ctx.TransferDestinationToProducts.Update(transferDestinationToProduct).State == EntityState.Modified;
|
||||
|
||||
public static bool RemoveTransferDestinationToProduct(this ITransferDestinationToProductDbSet ctx, TransferDestinationToProduct transferDestinationToProduct)
|
||||
{
|
||||
return ctx.TransferDestinationToProducts.Remove(transferDestinationToProduct).State == EntityState.Deleted;
|
||||
}
|
||||
|
||||
public static bool RemoveTransferDestinationToProduct(this ITransferDestinationToProductDbSet ctx, Guid transferDestinationToProductId)
|
||||
{
|
||||
var transferDestinationToProduct = ctx.GetTransferDestinationToProductById(transferDestinationToProductId);
|
||||
return transferDestinationToProduct == null || ctx.RemoveTransferDestinationToProduct(transferDestinationToProduct);
|
||||
}
|
||||
#endregion TransferDestinationToProduct
|
||||
}
|
||||
|
|
@ -2,9 +2,7 @@
|
|||
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;
|
||||
using TIAM.Entities.Users;
|
||||
|
||||
|
|
|
|||
|
|
@ -17,14 +17,15 @@ namespace TIAM.Entities.Transfers
|
|||
[ForeignKey(nameof(AddressId))]
|
||||
public virtual Address Address { get; set; }
|
||||
|
||||
//public virtual List<Product> Products { get; set; }
|
||||
//public virtual List<TransferDestinationToProduct> TransferDestinationToProducts { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Description { get; set; }
|
||||
|
||||
public PriceType PriceType { get; set; }
|
||||
//public PriceType PriceType { get; set; }
|
||||
public double Price { get; set; }
|
||||
public double Price2 { get; set; }
|
||||
public double Price3 { get; set; }
|
||||
|
||||
//TEMPORARY!!!
|
||||
public string? AddressString { get; set; }
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using AyCode.Interfaces.Entities;
|
||||
using AyCode.Interfaces.TimeStampInfo;
|
||||
using TIAM.Core.Enums;
|
||||
using TIAM.Entities.Products;
|
||||
|
||||
namespace TIAM.Entities.Transfers
|
||||
{
|
||||
[Table(nameof(TransferDestinationToProduct))]
|
||||
public class TransferDestinationToProduct : IEntityGuid, ITimeStampInfo, IProductForeignKey
|
||||
{
|
||||
[Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
|
||||
public Guid Id { get; set; }
|
||||
|
||||
public Guid ProductId { get; set; }
|
||||
//public virtual Product Product { get; set; }
|
||||
|
||||
public Guid TransferDestinationId { get; set; }
|
||||
public virtual TransferDestination TransferDestination { get; set; }
|
||||
|
||||
//public PriceType PriceType { get; set; }
|
||||
public double Price { get; set; }
|
||||
public double? Price2 { get; set; }
|
||||
public double? Price3 { get; set; }
|
||||
|
||||
public double? ExtraPrice { get; set; }
|
||||
public bool? ExtraPriceType { get; set; }
|
||||
|
||||
public DateTime Created { get; set; }
|
||||
public DateTime Modified { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -102,8 +102,8 @@ namespace TIAMWebApp.Server.Controllers
|
|||
Console.WriteLine($"TransferDestination to be created: {transferDestination.AddressId}");
|
||||
Console.WriteLine($"TransferDestination to be created: {transferDestination.Name}");
|
||||
Console.WriteLine($"TransferDestination to be created: {transferDestination.Price}");
|
||||
Console.WriteLine($"TransferDestination to be created: {transferDestination.Price2}");
|
||||
Console.WriteLine($"TransferDestination to be created: {transferDestination.Price3}");
|
||||
//Console.WriteLine($"TransferDestination to be created: {transferDestination.Price2}");
|
||||
//Console.WriteLine($"TransferDestination to be created: {transferDestination.Price3}");
|
||||
Console.WriteLine($"TransferDestination to be created: {transferDestination.PriceType}");
|
||||
Console.WriteLine($"TransferDestination to be created: {transferDestination.AddressString}");
|
||||
Console.WriteLine($"TransferDestination to be created: {transferDestination.Description}");
|
||||
|
|
@ -160,8 +160,8 @@ namespace TIAMWebApp.Server.Controllers
|
|||
Console.WriteLine($"TransferDestination to be updated: {transferDestination.Id}");
|
||||
Console.WriteLine($"TransferDestination to be updated new name: {transferDestination.Name}");
|
||||
Console.WriteLine($"TransferDestination to be updated new price: {transferDestination.Price}");
|
||||
Console.WriteLine($"TransferDestination to be updated new price: {transferDestination.Price2}");
|
||||
Console.WriteLine($"TransferDestination to be updated new price: {transferDestination.Price3}");
|
||||
//Console.WriteLine($"TransferDestination to be updated new price: {transferDestination.Price2}");
|
||||
//Console.WriteLine($"TransferDestination to be updated new price: {transferDestination.Price3}");
|
||||
Console.WriteLine($"TransferDestination to be updated new priceType: {transferDestination.PriceType}");
|
||||
Console.WriteLine($"TransferDestination to be updated new address: {transferDestination.AddressString}");
|
||||
Console.WriteLine($"TransferDestination to be updated new description: {transferDestination.Description}");
|
||||
|
|
|
|||
|
|
@ -81,8 +81,8 @@ namespace TIAMWebApp.Shared.Application.Models.ClientSide.UI.WizardModels
|
|||
destination.Description = model.Description;
|
||||
destination.AddressString = model.AddressString;
|
||||
destination.Price = model.Price;
|
||||
destination.Price2 = model.Price;
|
||||
destination.Price3 = model.Price;
|
||||
//destination.Price2 = model.Price;
|
||||
//destination.Price3 = model.Price;
|
||||
destination.PriceType = model.PriceType;
|
||||
destination.Address = model.Address;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue