This commit is contained in:
Adam 2024-01-31 17:32:31 +01:00
commit f317406acf
49 changed files with 467 additions and 85 deletions

View File

@ -5,7 +5,9 @@ using TIAM.Core;
using TIAM.Core.Enums;
using TIAM.Database.DataLayers.Admins;
using TIAM.Database.DbContexts.Admins;
using TIAM.Database.DbSets.Emails;
using TIAM.Entities.Drivers;
using TIAM.Entities.Emails;
using TIAM.Entities.Products;
using TIAM.Entities.Users;
using TIAM.Models.Dtos.Users;
@ -61,31 +63,43 @@ namespace TIAM.Database.Test
public Product GetProductById_ReturnsProduct_WhenProductExists(string productIdString)
{
var productId = Guid.Parse(productIdString);
var product = Dal.GetProductById(productId);
var product = Dal.GetProductById(productId, true);
Assert.IsNotNull(product, "Product is null");
Assert.IsNotNull(product.Profile);
Assert.IsNotNull(product.Profile, "Profile is null");
Assert.IsNotNull(product.Profile.Address, "Profile.Address is null");
return product;
}
[DataTestMethod]
public void GetProducts_ReturnProducts_WhenProductsExist()
public void GetProducts_ReturnProductsJson_WhenProductsExist()
{
var products = JsonConvert.DeserializeObject<IEnumerable<Product>>(Dal.GetProducts());
var products = JsonConvert.DeserializeObject<List<Product>>(Dal.GetProductsJson(false));
Assert.IsNotNull(products, "Products is null");
Assert.IsTrue(products.Count() > 0, "No products found");
Assert.IsTrue(products.Count > 0, "No products found");
Assert.IsNotNull(products[0].Profile, "Profile is null");
Assert.IsNotNull(products[0].Profile.Address, "Profile.Address is null");
Assert.IsNotNull(products[0].ServiceProvider, "ServiceProvider is null");
}
[DataTestMethod]
[DataRow("3587F169-683C-4EEE-BCB5-E8D57F8C6DCE")]
public void GetProductsByServiceProviderId_ReturnProducts_WhenProductsExist(string serviceProviderId)
public void GetProductsByServiceProviderId_ReturnProductsJson_WhenProductsExist(string serviceProviderId)
{
var products = JsonConvert.DeserializeObject<IEnumerable<Product>>(Dal.GetProductsByServiceProviderId(Guid.Parse(serviceProviderId)));
Assert.IsNotNull(products, "Products is null");
Assert.IsTrue(products.Count() > 0, "No products found");
var products = JsonConvert.DeserializeObject<List<Product>>(Dal.GetProductsJsonByServiceProviderId(Guid.Parse(serviceProviderId), true));
Assert.IsNotNull(products, "Products is null");
Assert.IsTrue(products.Count > 0, "No products found");
Assert.IsNotNull(products[0].Profile, "Profile is null");
Assert.IsNotNull(products[0].Profile.Address, "Profile.Address is null");
Assert.IsNotNull(products[0].ServiceProvider, "ServiceProvider is null");
}
[DataTestMethod]
@ -128,6 +142,9 @@ namespace TIAM.Database.Test
Assert.IsNotNull(userProductMapping.User, "User is null");
Assert.IsNotNull(userProductMapping.Product, "Product is null");
Assert.IsNotNull(userProductMapping.User.Profile.Address, "User.Profile.Address is null");
Assert.IsNotNull(userProductMapping.Product.Profile.Address, "Product.Profile.Address is null");
Assert.IsTrue(userProductMapping.Transfers?.Count != 0, "Transfers?.Count == 0");
Assert.IsTrue(userProductMapping.Id == userProductMappingId, "userProductMapping.Id != userProductMappingId");
}
@ -251,6 +268,7 @@ namespace TIAM.Database.Test
Assert.IsNotNull(user);
Assert.IsNotNull(user.Profile);
Assert.IsNotNull(user.Profile.Address, "Profile.Address is null");
Assert.IsTrue(user.Id == userId, "user.Id != userId");
@ -366,7 +384,85 @@ namespace TIAM.Database.Test
Assert.IsNull(transfer); //a korábbi törlés miatt NULL kell legyen - J.
}
#endregion Trnsfer
#endregion Transfer
#region EmailMessage
[DataTestMethod]
[DataRow("f6ec3eed-5e00-47db-a6cf-804699515aa2")]
public async Task GetEmailMessageById_ReturnsEmailMessage_WhenHasEmailMessage(string emailMessageIdString)
{
var emailMessageId = Guid.Parse(emailMessageIdString);
var emailMessage = await Dal.GetEmailMessageByIdAsync(emailMessageId);
Assert.IsNotNull(emailMessage);
Assert.IsTrue(emailMessage.Recipients?.Count > 0);
Assert.IsTrue(emailMessage.Id == emailMessageId, "emailMessage.Id != emailMessageId");
}
[DataTestMethod]
[DataRow(["4CBAED43-2465-4D99-84F1-C8BC6B7025F7", "71392cfd-fb9c-45c1-9540-7be3782cf26a"])]
public async Task GetMyEmailMessagesByUserProductMappingId_ReturnsEmailMessages_WhenHasEmailMessageAndAllRecipientIsValid(string[] userIdUserProductMappingIdString)
{
var userId = Guid.Parse(userIdUserProductMappingIdString[0]);
var userProductMappingId = Guid.Parse(userIdUserProductMappingIdString[1]);
var emailMessages = await Dal.GetEmailMessagesAsync(userId, userProductMappingId);
Assert.IsNotNull(emailMessages);
Assert.IsTrue(emailMessages.Count > 0);
Assert.IsTrue(emailMessages.All(x => x.Recipients.Any(recipient => recipient.RecipientId == userId || recipient.RecipientId == userProductMappingId)));
}
[DataTestMethod]
[DataRow(["718b04ef-47a7-444e-8527-54460a7f1ea3", "71392cfd-fb9c-45c1-9540-7be3782cf26a", "6216f9fb-1dda-44bd-9d85-431f3cb09fde", "test@tiam.hu", "AC612AA8-863B-4B4F-9D63-F5D261B5C5F9"])]
public async Task EmailMessageCrudTest(string[] emailIdSenderIdContextIdSenderEmailRecipientIdStrings)
{
var emailMessageId = Guid.Parse(emailIdSenderIdContextIdSenderEmailRecipientIdStrings[0]);
var senderId = Guid.Parse(emailIdSenderIdContextIdSenderEmailRecipientIdStrings[1]);
var contextId = Guid.Parse(emailIdSenderIdContextIdSenderEmailRecipientIdStrings[2]);
var senderEmail = emailIdSenderIdContextIdSenderEmailRecipientIdStrings[3];
var recipientId = Guid.Parse(emailIdSenderIdContextIdSenderEmailRecipientIdStrings[4]);
var subject = "Transfer - Budapest, Liszt Ferenc tér";
var text = "1211 Budapest, Kossuth Lajos utca 145";
await Dal.RemoveEmailMessageAsync(emailMessageId); //kitöröljük a szemetet, ha korábbról bentmaradt - J.
var emailMessage = new EmailMessage(emailMessageId, senderId, contextId, subject, text, senderEmail);
emailMessage.Recipients.Add(new EmailRecipient(id: Guid.NewGuid(), recipientId, emailMessageId));
Assert.IsTrue(await Dal.AddEmailMessageAsync(emailMessage));
Assert.IsNotNull(emailMessage);
emailMessage = await Dal.GetEmailMessageByIdAsync(emailMessageId);
Assert.IsNotNull(emailMessage);
Assert.IsTrue(emailMessage.Recipients?.Count > 0);
var modifiedText = "modifiedText";
emailMessage.Text = modifiedText;
Assert.IsTrue(await Dal.UpdateEmailMessageAsync(emailMessage));
emailMessage = await Dal.GetEmailMessageByIdAsync(emailMessageId);
Assert.IsNotNull(emailMessage);
Assert.IsTrue(emailMessage.Recipients?.Count > 0);
Assert.IsTrue(emailMessage.Text == modifiedText);
Assert.IsTrue(emailMessage.Id == emailMessageId, "emailMessage.Id != emailMessageId");
Assert.IsTrue(await Dal.RemoveEmailMessageAsync(emailMessageId)); //mielőbb kitöröljük, h ne maradjon szemét a db-ben - J.
emailMessage = await Dal.GetEmailMessageByIdAsync(emailMessageId);
Assert.IsNull(emailMessage); //a korábbi törlés miatt NULL kell legyen - J.
}
#endregion EmailMessage
}
}

View File

@ -10,10 +10,10 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />

View File

@ -15,11 +15,12 @@ using TIAM.Entities.Users;
using TIAM.Models.Dtos.Users;
using AyCode.Interfaces.Users.Dtos;
using TIAM.Entities.ServiceProviders;
using TIAM.Entities.Addresses;
namespace TIAM.Database.Test
{
[TestClass]
public class UserDalTests : AcUserDalTestBase<UserDal, UserDbContext, User, Profile, UserToken, TiamServiceProvider, UserToServiceProvider>
public class UserDalTests : AcUserDalTestBase<UserDal, UserDbContext, User, Profile, UserToken, TiamServiceProvider, UserToServiceProvider, Address>
{
private Mock<UserDbContext> _mockContext;

View File

@ -1,14 +1,18 @@
using AyCode.Database.DbSets.Users;
using System.Security.Cryptography.X509Certificates;
using AyCode.Database.DbSets.Users;
using AyCode.Models.Enums;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using TIAM.Core;
//using TIAM.Database.DataLayers.ServiceProviders;
using TIAM.Database.DbContexts.Admins;
using TIAM.Database.DbSets.Emails;
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.Emails;
using TIAM.Entities.Permissions;
using TIAM.Entities.Products;
using TIAM.Entities.ServiceProviders;
@ -49,9 +53,11 @@ namespace TIAM.Database.DataLayers.Admins
public string? GetUserJsonById(Guid userId) => Session(ctx => ctx.GetUserById(userId)?.ToJson());
public string GetUsersJson() => Session(ctx => ctx.Users.ToJson());
public Product? GetProductById(Guid contextId) => Session(ctx => ctx.GetProductById(contextId));
public string GetProducts() => Session(ctx => ctx.Products.ToJson());
public string GetProductsByServiceProviderId(Guid serviceProviderId) => Session(ctx => ctx.Products.Where(x => x.ServiceProviderId == serviceProviderId).ToJson());
public Product? GetProductById(Guid contextId, bool includeUsers = true) => Session(ctx => ctx.GetProductById(contextId, includeUsers));
public string GetProductsJson(bool includeUsers = true) => Session(ctx => ctx.ProductsWithUserRelations(includeUsers).ToJson());
public List<Product> GetProductsByServiceProviderId(Guid serviceProviderId, bool includeUsers = true) => Session(ctx => ctx.GetProductsByServiceProviderId(serviceProviderId, includeUsers).ToList());
public string GetProductsJsonByServiceProviderId(Guid serviceProviderId, bool includeUsers = true) => Session(ctx => ctx.GetProductsByServiceProviderId(serviceProviderId, includeUsers).ToJson());
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);
@ -74,7 +80,7 @@ namespace TIAM.Database.DataLayers.Admins
#region UserProductMapping
public Task<bool> AddUserProductMappingAsync(UserProductMapping userProductMapping)
=> TransactionAsync(ctx => ctx.AddUserProductMapping(userProductMapping) && ctx.SaveChanges() == 1);
=> TransactionAsync(ctx => ctx.AddUserProductMapping(userProductMapping) && ctx.SaveChanges() > 0);
public async Task<UserProductMapping?> AddUserProductMappingAsync(Guid userProductMappingId, Guid userId, Guid productId, int permissions = 1, UserProductJsonDetailModel? userProductToCars = null)
{
@ -84,7 +90,7 @@ namespace TIAM.Database.DataLayers.Admins
{
userProductMapping = ctx.AddUserProductMapping(userProductMappingId, userId, productId, permissions, userProductToCars);
return userProductMapping != null && ctx.SaveChanges() == 1;
return userProductMapping != null && ctx.SaveChanges() > 0;
});
return isSucces ? userProductMapping : null;
@ -101,20 +107,40 @@ namespace TIAM.Database.DataLayers.Admins
{
userProductMapping = ctx.UpdateUserProductMapping(userProductMappingId, permissions, userProductToCars);
return userProductMapping != null && ctx.SaveChanges() == 1;
return userProductMapping != null && ctx.SaveChanges() > 0;
});
return isSucces ? userProductMapping : null;
}
public Task<bool> RemoveUserProductMappingAsync(Guid userProductMappingId)
=> TransactionAsync(ctx => ctx.RemoveUserProductMapping(userProductMappingId) && ctx.SaveChanges() == 1);
=> TransactionAsync(ctx => ctx.RemoveUserProductMapping(userProductMappingId) && ctx.SaveChanges() > 0);
public Task<bool> RemoveUserProductMappingAsync(Guid userId, Guid productId)
=> TransactionAsync(ctx => ctx.RemoveUserProductMapping(userId, productId) && ctx.SaveChanges() == 1);
=> TransactionAsync(ctx => ctx.RemoveUserProductMapping(userId, productId) && ctx.SaveChanges() > 0);
#endregion UserProductMapping
#region EmailMessage
public Task<EmailMessage?> GetEmailMessageByIdAsync(Guid emailMessageId) => SessionAsync(ctx => ctx.GetEmailMessageById(emailMessageId));
public Task<List<EmailMessage>> GetEmailMessagesByContextIdAsync(Guid contextId) => SessionAsync(ctx => ctx.GetEmailMessagesByContextId(contextId).ToList());
public Task<List<EmailMessage>> GetEmailMessagesBySenderIdAsync(Guid senderId) => SessionAsync(ctx => ctx.GetEmailMessagesBySenderId(senderId).ToList());
public Task<List<EmailMessage>> GetEmailMessagesBySenderEmailAddressAsync(string emailAddress) => SessionAsync(ctx => ctx.GetEmailMessagesBySenderEmailAddress(emailAddress).ToList());
public Task<List<EmailMessage>> GetEmailMessagesAsync(Guid userId, Guid userProductMappingId) => SessionAsync(ctx => ctx.GetEmailMessages(userId, userProductMappingId).ToList());
public Task<List<EmailMessage>> GetEmailMessagesAsync(Guid contextId, Guid userId, Guid userProductMappingId) => SessionAsync(ctx => ctx.GetEmailMessages(contextId, userId, userProductMappingId).ToList());
public Task<bool> AddEmailMessageAsync(EmailMessage emailMessage)
=> TransactionAsync(ctx => ctx.AddEmailMessage(emailMessage) && ctx.SaveChanges() > 0);
public Task<bool> UpdateEmailMessageAsync(EmailMessage emailMessage)
=> TransactionAsync(ctx => ctx.UpdateEmailMessage(emailMessage) && ctx.SaveChanges() > 0);
public Task<bool> RemoveEmailMessageAsync(Guid emailMessageId)
=> TransactionAsync(ctx => ctx.RemoveEmailMessage(emailMessageId) && ctx.SaveChanges() > 0);
#endregion EmailMessage
//15. (IServiceProviderDataService) Create service provider
public Task<bool> CreateServiceProviderAsync(TiamServiceProvider serviceProvider)
{

View File

@ -10,6 +10,7 @@ using AyCode.Entities.Users;
using Microsoft.EntityFrameworkCore;
using TIAM.Database.DbContexts.Users;
using TIAM.Database.DbSets.Users;
using TIAM.Entities.Addresses;
using TIAM.Entities.Profiles;
using TIAM.Entities.ServiceProviders;
using TIAM.Entities.Users;
@ -17,7 +18,7 @@ using TIAM.Models.Dtos.Users;
namespace TIAM.Database.DataLayers.Users
{
public class UserDal : AcUserDalBase<UserDbContext, User, Profile, UserToken, TiamServiceProvider, UserToServiceProvider>
public class UserDal : AcUserDalBase<UserDbContext, User, Profile, UserToken, TiamServiceProvider, UserToServiceProvider, Address>
{
public UserDal() : base()

View File

@ -5,13 +5,16 @@ using System.Text;
using System.Threading.Tasks;
using AyCode.Database.DbContexts;
using Microsoft.EntityFrameworkCore;
using TIAM.Database.ModelBuilders.Emails;
using TIAM.Database.ModelBuilders.Products;
using TIAM.Database.ModelBuilders.Transfers;
using TIAM.Database.ModelBuilders.Users;
using TIAM.Entities.Addresses;
using TIAM.Entities.Drivers;
using TIAM.Entities.Emails;
using TIAM.Entities.Permissions;
using TIAM.Entities.Products;
using TIAM.Entities.Profiles;
using TIAM.Entities.ServiceProviders;
using TIAM.Entities.TransferDestinations;
using TIAM.Entities.Transfers;
@ -32,6 +35,9 @@ namespace TIAM.Database.DbContexts.Admins
public DbSet<PermissionGroupUserMapping> PermissionGroupUserMappings { get; set; }
public DbSet<PermissionContextMapping> PermissionContextMappings { get; set; }
public DbSet<PermissionsType> PermissionsTypes { get; set; }
public DbSet<EmailMessage> EmailMessages { get; set; }
public DbSet<Address> Addresses { get; set; }
public AdminDbContext() //: this(string.Empty)
@ -56,6 +62,7 @@ namespace TIAM.Database.DbContexts.Admins
base.OnModelCreating(modelBuilder);
new UserEntityTypeDefaultConfiguration().Configure(modelBuilder.Entity<User>());
new ProfileEntityTypeConfigurations().Configure(modelBuilder.Entity<Profile>());
new UserProductMappingEntityTypeDefaultConfiguration().Configure(modelBuilder.Entity<UserProductMapping>());
new ProductEntityTypeDefaultConfiguration().Configure(modelBuilder.Entity<Product>());
@ -63,6 +70,7 @@ namespace TIAM.Database.DbContexts.Admins
new TransferEntityTypeDefaultConfigurations().Configure(modelBuilder.Entity<Transfer>());
modelBuilder.Entity<TransferDestination>().Navigation(e => e.Address).AutoInclude(true);
new EmailMessageEntityTypeDefaultConfigurations().Configure(modelBuilder.Entity<EmailMessage>());
//modelBuilder.Entity<UserProductToCar>().Ignore(x => x.Id);
//modelBuilder.Entity<Car>().Ignore(x => x.Id);

View File

@ -1,4 +1,5 @@
using TIAM.Database.DbSets.Addresses;
using TIAM.Database.DbSets.Emails;
using TIAM.Database.DbSets.Permissions;
using TIAM.Database.DbSets.Products;
using TIAM.Database.DbSets.ServiceProvider;
@ -7,6 +8,7 @@ using TIAM.Database.DbSets.Users;
namespace TIAM.Database.DbContexts.Admins;
public interface IAdminDbContext : IServiceProviderDbSet, IProductDbSet, IUserProductMappingDbSet, IUserDbSet, IPermissionsDbSetContext, IAddressDbSet, ITransferDestinationDbSet, ITransferDbSet
public interface IAdminDbContext :
IServiceProviderDbSet, IProductDbSet, IUserProductMappingDbSet, IUserDbSet, IPermissionsDbSetContext, IAddressDbSet, ITransferDestinationDbSet, ITransferDbSet, IEmailMessageDbSet
{
}

View File

@ -1,6 +1,7 @@
using AyCode.Database.DbContexts.Users;
using AyCode.Entities.Users;
using TIAM.Database.DbSets.Addresses;
using TIAM.Database.DbSets.Emails;
using TIAM.Database.DbSets.Transfers;
using TIAM.Database.DbSets.Users;
using TIAM.Entities.Addresses;
@ -10,6 +11,6 @@ using TIAM.Entities.Users;
namespace TIAM.Database.DbContexts.Users;
public interface IUserDbContext : IAcUserDbContextBase<User, Profile, UserToken, TiamServiceProvider, UserToServiceProvider>, IUserDbSet, IAddressDbSet, ITransferDestinationDbSet
{
}
public interface IUserDbContext :
IAcUserDbContextBase<User, Profile, UserToken, TiamServiceProvider, UserToServiceProvider, Address>, IUserDbSet, IAddressDbSet, ITransferDestinationDbSet, ITransferDbSet, IEmailMessageDbSet
{ }

View File

@ -7,16 +7,22 @@ using System.Text;
using System.Threading.Tasks;
using AyCode.Database.DbContexts;
using AyCode.Database.DbContexts.Users;
using AyCode.Database.ModelBuilders.Profiles;
using AyCode.Entities.Users;
using AyCode.Interfaces.Users;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using TIAM.Database.ModelBuilders.Emails;
using TIAM.Database.ModelBuilders.Products;
using TIAM.Database.ModelBuilders.Transfers;
using TIAM.Database.ModelBuilders.Users;
using TIAM.Entities.Addresses;
using TIAM.Entities.Emails;
using TIAM.Entities.Permissions;
using TIAM.Entities.Products;
using TIAM.Entities.Profiles;
using TIAM.Entities.TransferDestinations;
using TIAM.Entities.Transfers;
using TIAM.Entities.Users;
namespace TIAM.Database.DbContexts.Users
@ -27,7 +33,11 @@ namespace TIAM.Database.DbContexts.Users
public DbSet<UserToken> UserTokens { get; set; }
public DbSet<Address> Addresses { get; set; }
public DbSet<TransferDestination> TransferDestinations { get; }
public DbSet<Transfer> Transfers { get; set; }
public DbSet<EmailMessage> EmailMessages { get; set; }
public DbSet<TransferDestination> TransferDestinations { get; set; }
public UserDbContext() //: this(string.Empty)
{
@ -57,10 +67,15 @@ namespace TIAM.Database.DbContexts.Users
base.OnModelCreating(modelBuilder);
new UserEntityTypeDefaultConfiguration().Configure(modelBuilder.Entity<User>());
new ProfileEntityTypeConfigurations().Configure(modelBuilder.Entity<Profile>());
new ProductEntityTypeDefaultConfiguration().Configure(modelBuilder.Entity<Product>());
new TransferEntityTypeDefaultConfigurations().Configure(modelBuilder.Entity<Transfer>());
modelBuilder.Entity<TransferDestination>().Navigation(e => e.Address).AutoInclude(true);
new EmailMessageEntityTypeDefaultConfigurations().Configure(modelBuilder.Entity<EmailMessage>());
//modelBuilder.Entity<Product>().BuildProductToServiceProviderRelation();
//new UserProductMappingEntityTypeDefaultConfiguration().Configure(modelBuilder.Entity<UserProductMapping>());

View File

@ -0,0 +1,50 @@
using Microsoft.EntityFrameworkCore;
using TIAM.Entities.Emails;
using TIAM.Entities.Products;
namespace TIAM.Database.DbSets.Emails;
public static class EmailMessageDbSetExtension
{
public static EmailMessage? GetEmailMessageById(this IEmailMessageDbSet ctx, Guid emailMessageId)
=> ctx.EmailMessages.FirstOrDefault(x => x.Id == emailMessageId);
public static IQueryable<EmailMessage> GetEmailMessagesByContextId(this IEmailMessageDbSet ctx, Guid contextId)
=> ctx.EmailMessages.Where(x => x.ContextId == contextId);
public static IQueryable<EmailMessage> GetEmailMessagesBySenderId(this IEmailMessageDbSet ctx, Guid senderId)
=> ctx.EmailMessages.Where(x => x.SenderId == senderId);
public static IQueryable<EmailMessage> GetEmailMessagesBySenderEmailAddress(this IEmailMessageDbSet ctx, string senderEmailAddress)
=> ctx.EmailMessages.Where(x => x.SenderEmailAddress == senderEmailAddress);
private static IQueryable<EmailMessage> GetEmailMessages(this IQueryable<EmailMessage> queryableEmails, Guid userId, Guid userProductMappingId)
=> queryableEmails.Where(x => x.SenderId == userId || x.SenderId == userProductMappingId || x.Recipients.Any(recipient => recipient.RecipientId == userId || recipient.RecipientId == userProductMappingId));
public static IQueryable<EmailMessage> GetEmailMessages(this IEmailMessageDbSet ctx, Guid userId, Guid userProductMappingId)
=> ctx.EmailMessages.GetEmailMessages(userId, userProductMappingId);
public static IQueryable<EmailMessage> GetEmailMessages(this IEmailMessageDbSet ctx, Guid contextId, Guid userId, Guid userProductMappingId)
=> ctx.GetEmailMessagesByContextId(contextId).GetEmailMessages(userId, userProductMappingId);
#region Add, Update, Remove
public static bool AddEmailMessage(this IEmailMessageDbSet ctx, EmailMessage emailMessage)
=> ctx.EmailMessages.Add(emailMessage).State == EntityState.Added;
public static bool UpdateEmailMessage(this IEmailMessageDbSet ctx, EmailMessage emailMessage)
=> ctx.EmailMessages.Update(emailMessage).State == EntityState.Modified;
public static bool RemoveEmailMessage(this IEmailMessageDbSet ctx, Guid emailMessageId)
{
var emailMessage = ctx.GetEmailMessageById(emailMessageId);
return emailMessage == null || ctx.RemoveEmailMessage(emailMessage);
}
public static bool RemoveEmailMessage(this IEmailMessageDbSet ctx, EmailMessage emailMessage)
=> ctx.EmailMessages.Remove(emailMessage).State == EntityState.Deleted;
#endregion Add, Update, Remove
}

View File

@ -0,0 +1,10 @@
using Microsoft.EntityFrameworkCore;
using TIAM.Entities.Emails;
using TIAM.Entities.Permissions;
namespace TIAM.Database.DbSets.Emails;
public interface IEmailMessageDbSet
{
public DbSet<EmailMessage> EmailMessages { get; set; }
}

View File

@ -1,9 +1,10 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using TIAM.Entities.Products;
namespace TIAM.Database.DbSets.Products;
public static class ProductDbSetExtensins
public static class ProductDbSetExtensions
{
#region Add, Update, Remove
@ -27,4 +28,8 @@ public static class ProductDbSetExtensins
public static Product? GetProductById(this IProductDbSet ctx, Guid productId, bool includeUsers = true)
=> ctx.ProductsWithUserRelations(includeUsers).FirstOrDefault(x => x.Id == productId);
public static IQueryable<Product> GetProductsByServiceProviderId(this IProductDbSet ctx, Guid serviceProviderId, bool includeUsers = true)
=> ctx.ProductsWithUserRelations(includeUsers).Where(x => x.ServiceProviderId == serviceProviderId);
}

View File

@ -6,5 +6,5 @@ namespace TIAM.Database.DbSets.Transfers;
public interface ITransferDbSet
{
public DbSet<Transfer> Transfers { get; }
public DbSet<Transfer> Transfers { get; set; }
}

View File

@ -6,5 +6,5 @@ namespace TIAM.Database.DbSets.Transfers;
public interface ITransferDestinationDbSet
{
public DbSet<TransferDestination> TransferDestinations { get; }
public DbSet<TransferDestination> TransferDestinations { get; set; }
}

View File

@ -1,10 +1,11 @@
using AyCode.Database.DbSets.Users;
using TIAM.Entities.Addresses;
using TIAM.Entities.Profiles;
using TIAM.Entities.ServiceProviders;
using TIAM.Entities.Users;
namespace TIAM.Database.DbSets.Users;
public interface IUserDbSet : IAcUserDbSet<User, Profile, TiamServiceProvider, UserToServiceProvider>
public interface IUserDbSet : IAcUserDbSet<User, Profile, TiamServiceProvider, UserToServiceProvider, Address>
{
}

View File

@ -0,0 +1,16 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using TIAM.Entities.Emails;
namespace TIAM.Database.ModelBuilders.Emails;
public static class EmailMessageEntityTypeBuilderExtensions
{
public static void BuildEmailMessageToRecipientRelation(this EntityTypeBuilder<EmailMessage> modelBuilder, bool autoInclude = true)
{
modelBuilder
.HasMany(x => x.Recipients)
.WithOne(x => x.EmailMessage);
modelBuilder.Navigation(e => e.Recipients).AutoInclude(autoInclude);
}
}

View File

@ -0,0 +1,15 @@
using AyCode.Database.DbContexts;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using TIAM.Database.ModelBuilders.Products;
using TIAM.Entities.Emails;
using TIAM.Entities.Products;
namespace TIAM.Database.ModelBuilders.Emails;
public class EmailMessageEntityTypeDefaultConfigurations : IAcEntityTypeConfiguration<EmailMessage>
{
public void Configure(EntityTypeBuilder<EmailMessage> builder)
{
builder.BuildEmailMessageToRecipientRelation();
}
}

View File

@ -3,9 +3,11 @@ using AyCode.Database.ModelBuilders.Users;
using AyCode.Interfaces.Users;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using TIAM.Entities.Addresses;
using TIAM.Entities.Profiles;
using TIAM.Entities.ServiceProviders;
using TIAM.Entities.Users;
using static AyCode.Database.ModelBuilders.Profiles.AcProfileEntityTypeConfigurations;
namespace TIAM.Database.ModelBuilders.Users;
@ -25,7 +27,7 @@ public class UserProductMappingEntityTypeTransferConfiguration : IAcEntityTypeCo
builder.BuildUserProductMappingToRelations(false);
}
}
public class UserEntityTypeDefaultConfiguration : AcUserEntityTypeDefaultConfiguration<User, Profile, TiamServiceProvider, UserToServiceProvider> //IAcEntityTypeConfiguration<User>//
public class UserEntityTypeDefaultConfiguration : AcUserEntityTypeDefaultConfiguration<User, Profile, TiamServiceProvider, UserToServiceProvider, Address> //IAcEntityTypeConfiguration<User>//
{
public override void Configure(EntityTypeBuilder<User> builder)
{
@ -34,3 +36,15 @@ public class UserEntityTypeDefaultConfiguration : AcUserEntityTypeDefaultConfigu
builder.BuildUserToUserProductMappingRelation();
}
}
public class ProfileEntityTypeConfigurations : AcProfileEntityTypeDefaultConfiguration<Profile, Address>
{
public override void Configure(EntityTypeBuilder<Profile> builder)
{
base.Configure(builder);
//builder.BuildEntityToAddressRelation();
}
}

View File

@ -7,9 +7,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
@ -20,6 +20,8 @@
<Folder Include="DbSets\Addresses\" />
<Folder Include="DbSets\ServiceProvider\" />
<Folder Include="Extensions\" />
<Folder Include="ModelBuilders\Emails\" />
<Folder Include="ModelBuilders\Profiles\" />
</ItemGroup>
<ItemGroup>

View File

@ -7,21 +7,35 @@ using AyCode.Interfaces.TimeStampInfo;
namespace TIAM.Entities.Emails;
[Table(nameof(EmailMessage))]
public class EmailMessage : IEntityGuid, ITimeStampInfo
public class EmailMessage : IEntityGuid, ITimeStampInfo, IEmailRecipientsRelation
{
public EmailMessage()
{
}
public EmailMessage(Guid id, Guid? senderId, Guid contextId, string subject, string? text, string senderEmailAddress) : this()
{
Id = id;
SenderId = senderId;
ContextId = contextId;
Subject = subject;
Text = text;
SenderEmailAddress = senderEmailAddress;
}
[Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
public Guid Id { get; set; }
public Guid ForeignKey { get; set; }
public Guid UserProductMappingId { get; set; }
public Guid UserId { get; set; }
public Guid ContextId { get; set; }
public Guid? SenderId { get; set; }
public virtual List<EmailRecipient> Recipients { get; set; } = [];
public bool SentToUser { get; set; }
[MaxLength(150)]
public string EmailAddress { get; set; }
public string SenderEmailAddress { get; set; }
[MaxLength(100)]
public string Subject { get; set; }
public string Text { get; set; }
public string? Text { get; set; }
public DateTime Created { get; set; }
public DateTime Modified { get; set; }

View File

@ -0,0 +1,31 @@
using AyCode.Interfaces.Entities;
using AyCode.Interfaces.TimeStampInfo;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
namespace TIAM.Entities.Emails;
//Update efcore, aspnetcore to 8.0.1; Implement EmailMessage, EmailRecipient; refactoring, improvments, fixes, etc...
public class EmailRecipient : IEntityGuid, ITimeStampInfo, IEmailMessageRelation
{
public EmailRecipient()
{
}
public EmailRecipient(Guid id, Guid recipientId, Guid emailMessageId) : this()
{
Id = id;
RecipientId = recipientId;
EmailMessageId = emailMessageId;
}
[Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
public Guid Id { get; set; }
public Guid RecipientId { get; set; }
public Guid EmailMessageId { get; set; }
public virtual EmailMessage EmailMessage { get; set; }
public DateTime Created { get; set; }
public DateTime Modified { get; set; }
}

View File

@ -0,0 +1,9 @@
namespace TIAM.Entities.Emails;
public interface IEmailMessageForeignKey<T>
{
public T EmailMessageId { get; set; }
}
public interface IEmailMessageForeignKey : IEmailMessageForeignKey<Guid>
{ }

View File

@ -0,0 +1,6 @@
namespace TIAM.Entities.Emails;
public interface IEmailMessageRelation : IEmailMessageForeignKey
{
public EmailMessage EmailMessage{ get; set; }
}

View File

@ -0,0 +1,6 @@
namespace TIAM.Entities.Emails;
public interface IEmailRecipientsRelation
{
public List<EmailRecipient> Recipients { get; set; }
}

View File

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

View File

@ -1,12 +1,6 @@
using AyCode.Interfaces.ServiceProviders;
using AyCode.Interfaces.Users;
using TIAM.Entities.Users;
namespace TIAM.Entities.Products;
namespace TIAM.Entities.Products;
public interface IProductRelation
public interface IProductRelation : IProductForeignKey
{
public List<UserProductMapping> UserProductMappings { get; set; }
public List<Product> Products { get; set; }
public Product Product { get; set; }
}

View File

@ -0,0 +1,11 @@
using AyCode.Interfaces.ServiceProviders;
using AyCode.Interfaces.Users;
using TIAM.Entities.Users;
namespace TIAM.Entities.Products;
public interface IProductsRelation
{
public List<UserProductMapping> UserProductMappings { get; set; }
public List<Product> Products { get; set; }
}

View File

@ -1,8 +1,9 @@
using AyCode.Interfaces.Profiles;
using TIAM.Entities.Addresses;
namespace TIAM.Entities.Profiles;
public interface IProfile : IAcProfile, IProfileDto
public interface IProfile : IAcProfile<Address>, IProfileDto
{
}

View File

@ -0,0 +1,7 @@
using AyCode.Interfaces.Profiles;
namespace TIAM.Entities.Profiles;
public interface IProfileForeignKey : IAcProfileForeignKey
{
}

View File

@ -2,6 +2,6 @@
namespace TIAM.Entities.Profiles;
public interface IProfileRelation : IAcProfileRelation<Profile>
public interface IProfileRelation : IAcProfileRelation<Profile>, IProfileForeignKey
{
}

View File

@ -1,8 +1,9 @@
using AyCode.Entities.Profiles;
using TIAM.Entities.Addresses;
namespace TIAM.Entities.Profiles;
public class Profile : AcProfile, IProfile
public class Profile : AcProfile<Address>, IProfile
{
}

View File

@ -32,11 +32,7 @@
</ItemGroup>
<ItemGroup>
<Folder Include="Emails\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="8.0.1" />
</ItemGroup>
</Project>

View File

@ -11,7 +11,7 @@ using TIAM.Entities.Users;
namespace TIAM.Entities.Transfers;
[Table(nameof(Transfer))]
public class Transfer: IEntityGuid, ITimeStampInfo, IProductForeignKey, IUserProductMappingForeignKey<Guid?>
public class Transfer: IEntityGuid, ITimeStampInfo, IProductForeignKey, IUserProductMappingRelation<Guid?>
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
public Guid Id { get; set; }

View File

@ -1,11 +1,12 @@
using AyCode.Interfaces.Users;
using TIAM.Entities.Addresses;
using TIAM.Entities.Products;
using TIAM.Entities.Profiles;
using TIAM.Entities.ServiceProviders;
namespace TIAM.Entities.Users;
public interface IUser : IAcUser<Profile, TiamServiceProvider, UserToServiceProvider>, IUserDto
public interface IUser : IAcUser<Profile, TiamServiceProvider, UserToServiceProvider, Address>, IUserDto
{
public List<Product> Products { get; }

View File

@ -1,11 +1,12 @@
using AyCode.Interfaces.Profiles;
using AyCode.Interfaces.Users;
using AyCode.Interfaces.Users.Dtos;
using TIAM.Entities.Addresses;
using TIAM.Entities.Products;
using TIAM.Entities.Profiles;
using TIAM.Entities.ServiceProviders;
namespace TIAM.Entities.Users;
public interface IUserDto : IAcUserDtoBase<Profile, TiamServiceProvider, UserToServiceProvider>
public interface IUserDto : IAcUserDtoBase<Profile, TiamServiceProvider, UserToServiceProvider, Address>
{ }

View File

@ -0,0 +1,15 @@
using AyCode.Interfaces.Users;
namespace TIAM.Entities.Users;
public interface IUserForeignKey : IAcUserForeignKey
{
}
public interface IUserRelation : IAcUserRelation<User>, IUserForeignKey
{
}
public interface IUsersRelation : IAcUsersRelation<User, UserToServiceProvider>
{
}

View File

@ -1,4 +1,6 @@
namespace TIAM.Entities.Users;
using System.Runtime;
namespace TIAM.Entities.Users;
public interface IUserProductMappingForeignKey<T>
{

View File

@ -0,0 +1,9 @@
namespace TIAM.Entities.Users;
public interface IUserProductMappingRelation<T> : IUserProductMappingForeignKey<T>
{
public UserProductMapping UserProductMapping { get; set; }
}
public interface IUserProductMappingsRelation : IUserProductMappingRelation<Guid>
{ }

View File

@ -5,13 +5,14 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AyCode.Entities.Users;
using TIAM.Entities.Addresses;
using TIAM.Entities.Products;
using TIAM.Entities.Profiles;
using TIAM.Entities.ServiceProviders;
namespace TIAM.Entities.Users
{
public class User : AcUser<Profile, TiamServiceProvider, UserToServiceProvider>, IUser
public class User : AcUser<Profile, TiamServiceProvider, UserToServiceProvider, Address>, IUser
{
public virtual List<Product> Products { get; } = new();

View File

@ -12,7 +12,7 @@ using TIAM.Entities.Transfers;
namespace TIAM.Entities.Users;
[Table("UserProductMapping")]
public class UserProductMapping : IEntityGuid, IUserForeignKey, IProductForeignKey, ITimeStampInfo
public class UserProductMapping : IEntityGuid, IUserRelation, IProductRelation, ITimeStampInfo
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid Id { get; set; }

View File

@ -6,6 +6,7 @@ public class ProfileDto : IProfileDto
{
public Guid Id { get; set; }
public Guid? UserMediaId { get; set; }
public Guid AddressId { get; set; }
public string Name { get; set; }
public string? Description { get; set; }

View File

@ -1,6 +1,7 @@
using AyCode.Entities.Profiles;
using AyCode.Interfaces.Users.Dtos;
using AyCode.Models.Users;
using TIAM.Entities.Addresses;
using TIAM.Entities.Products;
using TIAM.Entities.Profiles;
using TIAM.Entities.ServiceProviders;
@ -9,7 +10,7 @@ using TIAM.Models.Dtos.Profiles;
namespace TIAM.Models.Dtos.Users;
public class UserModelDto : AcUserModelDtoBase<UserDto, Profile, ProfileDto, TiamServiceProvider, UserToServiceProvider>, IProductRelation
public class UserModelDto : AcUserModelDtoBase<UserDto, Profile, ProfileDto, TiamServiceProvider, UserToServiceProvider, Address>, IProductsRelation
{
public List<UserProductMapping> UserProductMappings { get; set; }
public List<Product> Products { get; set; }

View File

@ -79,4 +79,16 @@
</Reference>
</ItemGroup>
<ItemGroup>
<PackageReference Update="Microsoft.AspNetCore.Components.WebView.Maui" Version="8.0.6" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="Microsoft.Maui.Controls" Version="8.0.6" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="Microsoft.Maui.Controls.Compatibility" Version="8.0.6" />
</ItemGroup>
</Project>

View File

@ -15,8 +15,8 @@
<PackageReference Include="Blazor.AnimateOnScroll" Version="1.1.0" />
<PackageReference Include="BlazorAnimation" Version="2.2.0" />
<PackageReference Include="DevExpress.Blazor" Version="23.2.3" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="8.0.1" />
</ItemGroup>
<ItemGroup>

View File

@ -8,8 +8,8 @@
<ItemGroup>
<PackageReference Include="Blazored.LocalStorage" Version="4.4.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.1" PrivateAssets="all" />
<PackageReference Include="SkiaSharp" Version="2.88.7" />
<PackageReference Include="SkiaSharp.Views.Desktop.Common" Version="2.88.7" />
</ItemGroup>

View File

@ -227,7 +227,7 @@ namespace TIAMWebApp.Server.Controllers
}
else
{
var products = _adminDal.GetProductsByServiceProviderId(serviceProviderId);
var products = _adminDal.GetProductsJsonByServiceProviderId(serviceProviderId);
if (products != null)
{
return Ok(products);

View File

@ -7,13 +7,13 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="GoogleApi" Version="5.3.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageReference Include="Microsoft.OpenApi" Version="1.6.11" />
<PackageReference Include="GoogleApi" Version="5.3.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.1" />
<PackageReference Include="Microsoft.OpenApi" Version="1.6.12" />
<PackageReference Include="QRCoderNetCore" Version="1.0.0" />
<PackageReference Include="SendGrid" Version="9.28.1" />
<PackageReference Include="SendGrid" Version="9.29.1" />
<PackageReference Include="SkiaSharp" Version="2.88.7" />
<PackageReference Include="SkiaSharp.Views.Desktop.Common" Version="2.88.7" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.5.0" />

View File

@ -1,10 +1,10 @@
using AyCode.Models.Enums;
using AyCode.Models.Messages;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AyCode.Models.Messages;
namespace TIAMWebApp.Shared.Application.Models.ClientSide.Messages
{

View File

@ -17,8 +17,8 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="8.0.0" />
<PackageReference Include="Microsoft.JSInterop" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="8.0.1" />
<PackageReference Include="Microsoft.JSInterop" Version="8.0.1" />
<PackageReference Include="SkiaSharp" Version="2.88.7" />
<PackageReference Include="SkiaSharp.Views.Desktop.Common" Version="2.88.7" />
</ItemGroup>