コード例 #1
0
ファイル: OrderValidation.cs プロジェクト: Airn5475/valitru
 public ValidationRule <Order> RuleOrderMarkedAsShippedMustHaveAShippedDate()
 =>
 ValidationRule.NewRule <Order>()
 .OnlyCheckIf(order => order.OrderStatus == OrderStatuses.Shipped)
 .ValidIf(order => order.ShipDateTime.HasValue)
 .SetErrorMessage("Order is marked as shipped, but has no Ship Date/Time specified")
 .AddInvalidMember(order => order.ShipDateTime);
コード例 #2
0
ファイル: OrderValidation.cs プロジェクト: Airn5475/valitru
 public ValidationRule <Order> RuleOrderCannotHaveAShippedDateLaterThanDatePlaced()
 =>
 ValidationRule.NewRule <Order>()
 .OnlyCheckIf(order => order.ShipDateTime.HasValue)
 .ValidIf(order => order.ShipDateTime.Value >= order.OrderDateTime)
 .SetErrorMessage(order => $"Order has a Ship Date/Time of {order.ShipDateTime.Value} which is earlier than the Date/Time it was placed of { order.OrderDateTime }")
 .AddInvalidMember(order => order.OrderDateTime)
 .AddInvalidMember(order => order.ShipDateTime);
コード例 #3
0
ファイル: OrderValidation.cs プロジェクト: Airn5475/valitru
 public ValidationRule <Order> RuleCustomersCannotHaveMoreThanFiveOrdersAMonth()
 =>
 ValidationRule.NewRule <Order>()
 .OnlyCheckIf(order => !order.OrderId.HasValue)
 .ValidIf(order =>
 {
     var orders = _orderRepository.GetOrdersForCustomerForMonth(order.CustomerId, order.OrderDateTime);
     return(orders.Count() < 5);
 })
 .SetErrorMessage("Customers can only place 5 orders a month.");
コード例 #4
0
ファイル: OrderValidation.cs プロジェクト: Airn5475/valitru
 public ValidationRule <Order> RuleOrderCannotHaveDuplicateConfirmationNumber()
 =>
 ValidationRule.NewRule <Order>()
 .OnlyCheckIf(order => !string.IsNullOrWhiteSpace(order.ConfirmationNumber))
 .ValidIf(order =>
 {
     var orders = _orderRepository.GetOrdersByConfirmationNumber(order.ConfirmationNumber).Where(o => o.OrderId != order.OrderId);
     return(!orders.Any());
 })
 .StopProcessingMoreRulesIfValidationFails()
 .SetErrorMessage(order => $"The confirmation number '{order.ConfirmationNumber}' is already in use.")
 .AddInvalidMember(order => order.ConfirmationNumber);
コード例 #5
0
ファイル: OrderValidation.cs プロジェクト: Airn5475/valitru
 public ValidationRule <Order> RuleOrderPlacedDateTimeMustBeInThePast()
 =>
 ValidationRule.NewRule <Order>()
 .ValidIf(order => DateTime.Now >= order.OrderDateTime)
 .SetErrorMessage(order => $"Order has an invalid Date/Time of {order.OrderDateTime}")
 .AddInvalidMember(order => order.OrderDateTime);