Beispiel #1
0
 public static IRuleBuilderOptions <T, Guid> ProductExists <T>(this IRuleBuilderInitial <T, Guid> builder, IProductsClient client)
 {
     return(builder.MustAsync(async(Guid productId, CancellationToken cancellationToken) =>
     {
         var product = await client.GetProductAsync(productId, cancellationToken);
         return product != null;
     }).WithErrorCode("ProductNotExists"));
 }
 public static IRuleBuilderOptions <T, Guid> ProductExists <T>(this IRuleBuilderInitial <T, Guid> builder, ICatalogDbContext context)
 {
     return(builder.MustAsync(async(Guid productId, CancellationToken cancellationToken) =>
     {
         var product = await context.Products.FindAsync(new object[] { productId }, cancellationToken);
         return product != null;
     }).WithErrorCode("ProductNotExists"));
 }
 public static IRuleBuilderOptions <T, Guid> OrderExists <T>(this IRuleBuilderInitial <T, Guid> builder, IBasketDbContext context, IUserContextManager userContextManager)
 {
     return(builder.MustAsync(async(Guid orderId, CancellationToken cancellationToken) =>
     {
         var customerEmail = userContextManager.GetCurrentUserEmail();
         var order = await context.Orders.FirstOrDefaultAsync(x => x.Id == orderId && x.CustomerEmail == customerEmail, cancellationToken);
         return order != null;
     }).WithErrorCode("OrderNotExists"));
 }
Beispiel #4
0
 public static IRuleBuilderOptions <TRequest, Guid> EntityExists <TRequest, TEntity>(
     this IRuleBuilderInitial <TRequest, Guid> ruleBuilderInitial,
     IArpaContext arpaContext,
     string propertyName) where TEntity : BaseEntity
 {
     return(ruleBuilderInitial
            .MustAsync(async(id, cancellation) => (await arpaContext.EntityExistsAsync <TEntity>(id, cancellation)))
            .OnFailure((_) => throw new NotFoundException(typeof(TEntity).Name, propertyName)));
 }