Merge branch 'master' of http://git2.aycode.com/Adam/TourIAm
This commit is contained in:
commit
a843236736
|
|
@ -303,6 +303,10 @@
|
||||||
<Name>RegisterDataTierApplication</Name>
|
<Name>RegisterDataTierApplication</Name>
|
||||||
<Value>False</Value>
|
<Value>False</Value>
|
||||||
</PropertyElementName>
|
</PropertyElementName>
|
||||||
|
<PropertyElementName>
|
||||||
|
<Name>PerformIndexOperationsOnline</Name>
|
||||||
|
<Value>False</Value>
|
||||||
|
</PropertyElementName>
|
||||||
<PropertyElementName>
|
<PropertyElementName>
|
||||||
<Name>RebuildIndexesOfflineForDataPhase</Name>
|
<Name>RebuildIndexesOfflineForDataPhase</Name>
|
||||||
<Value>False</Value>
|
<Value>False</Value>
|
||||||
|
|
|
||||||
|
|
@ -201,8 +201,7 @@ namespace TIAM.Database.Test
|
||||||
userProductMapping = await Dal.GetUserProductMappingByIdAsync(userProductMappingId, true);
|
userProductMapping = await Dal.GetUserProductMappingByIdAsync(userProductMappingId, true);
|
||||||
|
|
||||||
Assert.IsNotNull(userProductMapping);
|
Assert.IsNotNull(userProductMapping);
|
||||||
|
|
||||||
//userProductMapping.Permissions = 1;
|
|
||||||
Assert.IsNotNull(await Dal.UpdateUserProductMappingAsync(userProductMappingId, 1));
|
Assert.IsNotNull(await Dal.UpdateUserProductMappingAsync(userProductMappingId, 1));
|
||||||
|
|
||||||
userProductMapping = await Dal.GetUserProductMappingByIdAsync(userProductMappingId, true);
|
userProductMapping = await Dal.GetUserProductMappingByIdAsync(userProductMappingId, true);
|
||||||
|
|
@ -224,8 +223,8 @@ namespace TIAM.Database.Test
|
||||||
#endregion UserProductMapping
|
#endregion UserProductMapping
|
||||||
|
|
||||||
#region Product
|
#region Product
|
||||||
//[DataTestMethod]
|
[DataTestMethod]
|
||||||
//[DataRow(["e24f6942-2210-47d7-8660-ace0ef302bae", "8e6a4170-0e15-4f8a-bdd2-46f9dbc63b93", "540271F6-C604-4C16-8160-D5A7CAFEDF00", "49c7805b-d8cd-4308-b1c5-7a54e5ee6287"])]
|
[DataRow(["e24f6942-2210-47d7-8660-ace0ef302bae", "88b12e3d-bfec-462b-b1dc-1f4243ee7a00", "540271F6-C604-4C16-8160-D5A7CAFEDF00", "49c7805b-d8cd-4308-b1c5-7a54e5ee6287"])]
|
||||||
public async Task ProductCrudTest(string[] productIdCompanyIdUserIdUserToCompanyIdStrings)
|
public async Task ProductCrudTest(string[] productIdCompanyIdUserIdUserToCompanyIdStrings)
|
||||||
{
|
{
|
||||||
var productId = Guid.Parse(productIdCompanyIdUserIdUserToCompanyIdStrings[0]);
|
var productId = Guid.Parse(productIdCompanyIdUserIdUserToCompanyIdStrings[0]);
|
||||||
|
|
@ -235,33 +234,42 @@ namespace TIAM.Database.Test
|
||||||
|
|
||||||
await Dal.RemoveProductAsync(productId); //kitöröljük a szemetet, ha korábbról bentmaradt - J.
|
await Dal.RemoveProductAsync(productId); //kitöröljük a szemetet, ha korábbról bentmaradt - J.
|
||||||
|
|
||||||
var company = new Company(companyId, "Test unit product...", null);
|
var product = new Product(productId, companyId, ProductType.Hotel, "Test unit product...", "Test unit product description...", 25000, null);
|
||||||
|
product.AddUser(userId, 1);
|
||||||
|
|
||||||
Assert.IsTrue(await Dal.AddCompanyAsync(company));
|
Assert.IsTrue(await Dal.AddProductAsync(product));
|
||||||
Assert.IsNotNull(company);
|
Assert.IsNotNull(product);
|
||||||
|
|
||||||
company = await Dal.GetCompanyByIdAsync(companyId);
|
product = await Dal.GetProductByIdAsync(productId);
|
||||||
|
|
||||||
Assert.IsNotNull(company);
|
Assert.IsNotNull(product);
|
||||||
Assert.IsTrue(company.UserToServiceProviders.Count == 0);
|
Assert.IsNotNull(product.Profile);
|
||||||
Assert.IsTrue(company.Id == companyId);
|
Assert.IsNotNull(product.Profile.Address);
|
||||||
|
|
||||||
company.OwnerId = userId;
|
Assert.IsTrue(product.UserProductMappings.Any(x=>x.UserId == userId && x.ProductId == productId));
|
||||||
Assert.IsTrue(await Dal.UpdateCompanyAsync(company));
|
Assert.IsTrue(product.Id == productId);
|
||||||
|
|
||||||
company = await Dal.GetCompanyByIdAsync(companyId);
|
product.Price = 30000;
|
||||||
|
product.UserProductMappings[0].Permissions = 2;
|
||||||
|
Assert.IsTrue(await Dal.UpdateProductAsync(product));
|
||||||
|
|
||||||
Assert.IsNotNull(company);
|
product = await Dal.GetProductByIdAsync(productId);
|
||||||
Assert.IsNotNull(company.UserToServiceProviders);
|
|
||||||
Assert.IsTrue(company.UserToServiceProviders.Any(x=>x.UserId == userId && x.ServiceProviderId == companyId));
|
Assert.IsNotNull(product);
|
||||||
|
Assert.IsNotNull(product.UserProductMappings);
|
||||||
|
Assert.IsTrue((int)product.Price == 30000);
|
||||||
|
Assert.IsTrue(product.UserProductMappings[0].Permissions == 2);
|
||||||
|
|
||||||
company.CommissionPercent = 5;
|
var addressId = product.Profile.AddressId;
|
||||||
Assert.IsTrue(await Dal.UpdateCompanyAsync(company));
|
Assert.IsTrue(await Dal.RemoveProductAsync(product)); //mielőbb kitöröljük, h ne maradjon szemét a db-ben - J.
|
||||||
|
|
||||||
Assert.IsTrue(await Dal.RemoveCompanyAsync(company)); //mielőbb kitöröljük, h ne maradjon szemét a db-ben - J.
|
Assert.IsNull(await Dal.GetProfileByIdAsync(product.ProfileId));
|
||||||
|
Assert.IsNull(await Dal.GetAddressByIdAsync(addressId));
|
||||||
|
|
||||||
|
Assert.IsTrue((await Dal.GetUserProductMappingsByProductIdAsync(productId)).Count == 0);
|
||||||
|
|
||||||
company = await Dal.GetCompanyByIdAsync(companyId);
|
product = await Dal.GetProductByIdAsync(productId);
|
||||||
Assert.IsNull(company); //a korábbi törlés miatt NULL kell legyen - J.
|
Assert.IsNull(product); //a korábbi törlés miatt NULL kell legyen - J.
|
||||||
}
|
}
|
||||||
#endregion Product
|
#endregion Product
|
||||||
|
|
||||||
|
|
@ -374,8 +382,14 @@ namespace TIAM.Database.Test
|
||||||
company.CommissionPercent = 5;
|
company.CommissionPercent = 5;
|
||||||
Assert.IsTrue(await Dal.UpdateCompanyAsync(company));
|
Assert.IsTrue(await Dal.UpdateCompanyAsync(company));
|
||||||
|
|
||||||
|
var addressId = company.Profile.AddressId;
|
||||||
Assert.IsTrue(await Dal.RemoveCompanyAsync(company)); //mielőbb kitöröljük, h ne maradjon szemét a db-ben - J.
|
Assert.IsTrue(await Dal.RemoveCompanyAsync(company)); //mielőbb kitöröljük, h ne maradjon szemét a db-ben - J.
|
||||||
|
|
||||||
|
Assert.IsNull(await Dal.GetProfileByIdAsync(company.ProfileId));
|
||||||
|
Assert.IsNull(await Dal.GetAddressByIdAsync(addressId));
|
||||||
|
|
||||||
|
Assert.IsTrue(Dal.GetProductsByServiceProviderId(companyId).Count == 0);
|
||||||
|
|
||||||
company = await Dal.GetCompanyByIdAsync(companyId);
|
company = await Dal.GetCompanyByIdAsync(companyId);
|
||||||
Assert.IsNull(company); //a korábbi törlés miatt NULL kell legyen - J.
|
Assert.IsNull(company); //a korábbi törlés miatt NULL kell legyen - J.
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,15 @@
|
||||||
using AyCode.Core.Extensions;
|
using AyCode.Core.Extensions;
|
||||||
using AyCode.Database.DbSets.Profiles;
|
using AyCode.Database.DbSets.Profiles;
|
||||||
using AyCode.Interfaces.Addresses;
|
using AyCode.Interfaces.Addresses;
|
||||||
|
using AyCode.Interfaces.Entities;
|
||||||
using AyCode.Interfaces.Profiles;
|
using AyCode.Interfaces.Profiles;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||||
|
using TIAM.Database.DbSets.Users;
|
||||||
using TIAM.Entities.Addresses;
|
using TIAM.Entities.Addresses;
|
||||||
using TIAM.Entities.Products;
|
using TIAM.Entities.Products;
|
||||||
using TIAM.Entities.Profiles;
|
using TIAM.Entities.Profiles;
|
||||||
|
using TIAM.Entities.Users;
|
||||||
|
|
||||||
namespace TIAM.Database.DbSets.Products;
|
namespace TIAM.Database.DbSets.Products;
|
||||||
|
|
||||||
|
|
@ -16,19 +20,27 @@ public static class ProductDbSetExtensions
|
||||||
public static bool AddProduct(this IProductDbSet ctx, Product product)
|
public static bool AddProduct(this IProductDbSet ctx, Product product)
|
||||||
{
|
{
|
||||||
if (product.Id.IsNullOrEmpty()) product.Id = Guid.NewGuid();
|
if (product.Id.IsNullOrEmpty()) product.Id = Guid.NewGuid();
|
||||||
|
|
||||||
|
if (product.Profile == null!)
|
||||||
|
product.SetProfile((Activator.CreateInstance(typeof(Profile), product.ProfileId, product.Name) as Profile)!);
|
||||||
|
|
||||||
|
if (product.Profile!.Address == null!)
|
||||||
|
product.Profile.SetAddress((Activator.CreateInstance(typeof(Address), product.Profile.AddressId, product.Name) as Address)!);
|
||||||
|
|
||||||
return ctx.Products.Add(product).State == EntityState.Added;
|
return ctx.Products.Add(product).State == EntityState.Added;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool UpdateProduct(this IProductDbSet ctx, Product product)
|
public static bool UpdateProduct(this IProductDbSet ctx, Product product)
|
||||||
=> ctx.Products.Update(product).State == EntityState.Modified;
|
{
|
||||||
|
return ctx.Products.Update(product).State == EntityState.Modified;
|
||||||
|
}
|
||||||
|
|
||||||
public static bool RemoveProduct(this IProductDbSet ctx, Product product)
|
public static bool RemoveProduct(this IProductDbSet ctx, Product product)
|
||||||
{
|
{
|
||||||
ctx.RemoveProfile(product.ProfileId);
|
ctx.RemoveProfile(product.ProfileId);
|
||||||
ctx.UserProductMappings.RemoveRange(ctx.UserProductMappings.Where(x => x.ProductId == product.Id));
|
ctx.RemoveUserProductMappingsByProductId(product.Id);
|
||||||
//TODO: Transfer, etc... - J.
|
|
||||||
|
|
||||||
|
//TODO: Transfer, etc... - J.
|
||||||
return ctx.Products.Remove(product).State == EntityState.Deleted;
|
return ctx.Products.Remove(product).State == EntityState.Deleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -86,4 +86,10 @@ public static class UserProductMappingDbSetExtensions
|
||||||
|
|
||||||
return userProductMapping == null || ctx.RemoveUserProductMapping(userProductMapping);
|
return userProductMapping == null || ctx.RemoveUserProductMapping(userProductMapping);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool RemoveUserProductMappingsByProductId(this IUserProductMappingDbSet ctx, Guid productId)
|
||||||
|
{
|
||||||
|
ctx.UserProductMappings.RemoveRange(ctx.UserProductMappings.Where(x=>x.ProductId == productId));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using AyCode.Core.Extensions;
|
||||||
using TIAM.Core.Enums;
|
using TIAM.Core.Enums;
|
||||||
|
using TIAM.Entities.Profiles;
|
||||||
using TIAM.Entities.ServiceProviders;
|
using TIAM.Entities.ServiceProviders;
|
||||||
using TIAM.Entities.Users;
|
using TIAM.Entities.Users;
|
||||||
|
|
||||||
|
|
@ -30,4 +32,23 @@ public class Product : ProductBase
|
||||||
ServiceProviderId = serviceProviderId;
|
ServiceProviderId = serviceProviderId;
|
||||||
ServiceProvider = serviceProvider;
|
ServiceProvider = serviceProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetProfile(Profile profile)
|
||||||
|
{
|
||||||
|
if (profile.Id.IsNullOrEmpty()) profile.Id = Guid.NewGuid();
|
||||||
|
|
||||||
|
Profile = profile;
|
||||||
|
ProfileId = profile.Id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool HasUser(Guid userId)
|
||||||
|
=> UserProductMappings.Any(x => x.UserId == userId);
|
||||||
|
|
||||||
|
public void AddUser(Guid userId, int permissions)
|
||||||
|
{
|
||||||
|
if (UserProductMappings.Any(x => x.UserId == userId))
|
||||||
|
return;
|
||||||
|
|
||||||
|
UserProductMappings.Add(new UserProductMapping(Guid.NewGuid(), userId, Id) { Permissions = permissions });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -137,13 +137,13 @@
|
||||||
{
|
{
|
||||||
_logger.Debug($"DataItemSaving");
|
_logger.Debug($"DataItemSaving");
|
||||||
|
|
||||||
var profileId = Guid.NewGuid();
|
// var profileId = Guid.NewGuid();
|
||||||
product.Profile = new Profile(profileId, product.Name);
|
// product.Profile = new Profile(profileId, product.Name);
|
||||||
product.ProfileId = profileId;
|
// product.ProfileId = profileId;
|
||||||
|
|
||||||
var addressId = Guid.NewGuid();
|
// var addressId = Guid.NewGuid();
|
||||||
product.Profile.Address = new Address(addressId);
|
// product.Profile.Address = new Address(addressId);
|
||||||
product.Profile.AddressId = addressId;
|
// product.Profile.AddressId = addressId;
|
||||||
|
|
||||||
//((Product)e.EditModel).UserProductMappings.Add(new UserProductMapping(Guid.NewGuid, ParentData.));
|
//((Product)e.EditModel).UserProductMappings.Add(new UserProductMapping(Guid.NewGuid, ParentData.));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue