This commit is contained in:
masoodafar-web
2025-11-25 01:58:45 +03:30
parent 02fc3f9122
commit 87842f0b9b
8 changed files with 4356 additions and 2191 deletions

View File

@@ -34,6 +34,8 @@ public class
if (userWallet == null)
throw new Exception("کیف پول کاربر یافت نشد.");
if (userWallet.Balance<=0 || userWallet.Balance<request.TotalAmount)
throw new Exception("موجودی کیف پول کاربر برای انجام این تراکنش کافی نیست.");
var newTransaction = new Transactions()
{
@@ -71,24 +73,34 @@ public class
};
await _context.UserOrders.AddAsync(newOrder, cancellationToken);
await _context.SaveChangesAsync(cancellationToken);
await _context.FactorDetailss.AddRangeAsync(user.UserCartss.Select(s => new FactorDetails()
var factorDetailsList = user.UserCartss.Select(s => new FactorDetails()
{
ProductId = s.ProductId,
Count = s.Count,
UnitPrice = s.Product.Price,
OrderId = newOrder.Id
}), cancellationToken);
user.UserCartss.Clear();
await _context.SaveChangesAsync(cancellationToken);
return new SubmitShopBuyOrderResponseDto()
});
await _context.FactorDetailss.AddRangeAsync(factorDetailsList, cancellationToken);
var finalResult = new SubmitShopBuyOrderResponseDto()
{
Id = newOrder.Id,
PaymentMethod = newOrder.PaymentMethod,
PaymentStatus = newOrder.PaymentStatus,
TotalAmount = newOrder.Amount,
UserAddressText = user.UserAddresss.First(f => f.IsDefault).Address,
Created = newOrder.PaymentDate
Created = newOrder.PaymentDate,
FactorDetails = factorDetailsList.Select(s => new SubmitShopBuyOrderFactorDetail()
{
Count = s.Count,
UnitPrice = s.UnitPrice,
ProductId = s.ProductId,
ProductThumbnailPath = user.UserCartss.First(f => f.ProductId == s.ProductId).Product.ThumbnailPath,
ProductTitle = user.UserCartss.First(f => f.ProductId == s.ProductId).Product.Title,
UnitDiscountPrice = 0,
}).ToList()
};
user.UserCartss.Clear();
await _context.SaveChangesAsync(cancellationToken);
return finalResult;
}
}