Skip to content

Commit

Permalink
Delete product in action render
Browse files Browse the repository at this point in the history
  • Loading branch information
ipdae committed Sep 21, 2024
1 parent 4659135 commit a72f06b
Showing 1 changed file with 11 additions and 62 deletions.
73 changes: 11 additions & 62 deletions MarketService/RpcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,81 +128,39 @@ public async void RenderAction(ActionEvaluation<ActionBase> ev)
await InsertProducts(products, costumeStatSheet, crystalEquipmentGrindingSheet, crystalMonsterCollectionMultiplierSheet);
break;
}
// Update product exist = false
// delete product
case BuyProduct buyProduct:
{
var orderIds = new List<Guid>();
var productIds = new List<Guid>();
var deletedIds = new List<Guid>();
foreach (var productInfo in buyProduct.ProductInfos)
{
if (productInfo is ItemProductInfo {Legacy: true} _)
{
orderIds.Add(productInfo.ProductId);
}
else
{
productIds.Add(productInfo.ProductId);
}
deletedIds.Add(productInfo.ProductId);
}

var marketContext = await _contextFactory.CreateDbContextAsync();
if (orderIds.Any())
{
await UpdateProducts(productIds, marketContext, true);
}

if (productIds.Any())
{
await UpdateProducts(productIds, marketContext, false);
}

await DeleteProducts(deletedIds, marketContext);
break;
}
case CancelProductRegistration cancelProductRegistration:
{
var orderIds = new List<Guid>();
var productIds = new List<Guid>();
var deletedIds = new List<Guid>();
foreach (var productInfo in cancelProductRegistration.ProductInfos)
{
if (productInfo is ItemProductInfo {Legacy: true} _)
{
orderIds.Add(productInfo.ProductId);
}
else
{
productIds.Add(productInfo.ProductId);
}
deletedIds.Add(productInfo.ProductId);
}

var marketContext = await _contextFactory.CreateDbContextAsync();
if (orderIds.Any())
{
await UpdateProducts(productIds, marketContext, true);
}

if (productIds.Any())
{
await UpdateProducts(productIds, marketContext, false);
}

await DeleteProducts(deletedIds, marketContext);
break;
}
// Insert new product and Update product exist = false
// Insert new product and delete product
case ReRegisterProduct reRegisterProduct:
{
var deletedOrderIds = new List<Guid>();
var deletedProductIds = new List<Guid>();
var productIds = new List<Guid>();
var deletedIds = new List<Guid>();
foreach (var (productInfo, _) in reRegisterProduct.ReRegisterInfos)
{
if (productInfo is ItemProductInfo {Legacy: true} _)
{
deletedOrderIds.Add(productInfo.ProductId);
}
else
{
deletedProductIds.Add(productInfo.ProductId);
}
deletedIds.Add(productInfo.ProductId);
productIds.Add(random.GenerateRandomGuid());
}
var crystalEquipmentGrindingSheet = await GetSheet<CrystalEquipmentGrindingSheet>(hashBytes);
Expand All @@ -222,16 +180,7 @@ public async void RenderAction(ActionEvaluation<ActionBase> ev)

await InsertProducts(products, costumeStatSheet, crystalEquipmentGrindingSheet, crystalMonsterCollectionMultiplierSheet);
var marketContext = await _contextFactory.CreateDbContextAsync();
if (deletedOrderIds.Any())
{
await UpdateProducts(deletedOrderIds, marketContext, true);
}

if (deletedProductIds.Any())
{
await UpdateProducts(deletedProductIds, marketContext, false);
}

await DeleteProducts(deletedIds, marketContext);
break;
}
}
Expand Down

0 comments on commit a72f06b

Please sign in to comment.