我想请求你的帮助。我想验证我的删除请求类。规则是:
"删除只允许一个价格最高的元素 每种产品的数据库"
。 repositoryEntities不为null,但结果为:枚举没有产生任何结果。
您可以查看下面的代码,让我知道出了什么问题吗?
private void CanIDelete(DeleteProductRequest entity, CustomContext context)
{
var repositoryEntities = _productRepository.Queryable.Where(s => s.TypeOfProductId.Equals(entity.TypeOfProductId) && !s.IsDeleted);
if (repositoryEntities != null)
{
var theBiggestPriceInDatabase = Decimal.MinValue;
foreach (var repositoryEntity in repositoryEntities)
{
if (theBiggestPriceInDatabase < repositoryEntity.Price)
{
theBiggestPriceInDatabase = repositoryEntity.Price;
continue;
}
if (entity.Price != theBiggestPriceInDatabase)
{
context.AddFailure("Deletion allowed only for one product 'with the biggest price' in database for each type of product");
return;
}
}
}