private void MustHaveShippingAddress(IOrder order, IValidationResults results) { if (order.ShippingAddress == null) { results.AddError(ValidationErrorTypes.ShippingAddressRequired, "Must have a shipping address."); } }
private void MustHaveOrderlines(IOrder order, IValidationResults results) { if (order.OrderLines.Count() < 1) { results.AddError(ValidationErrorTypes.OrderlinesRequired, "Must have at least one orderline."); } }
/// <summary> /// Adds all results to the IValidationResults list /// </summary> private static void CopyModelErrors(IEnumerable <ValidationResult> fromList, IValidationResults toList) { foreach (var result in fromList) { string key = result.MemberNames.FirstOrDefault(); // hint: good place for doing string manipulation (eg. translation) string errorMessage = result.ErrorMessage + " (own Validator!)"; toList.AddError(key, errorMessage); } }