fluentvalidation

(Best Practice) FluentValidation and Checking Duplicate Entities

江枫思渺然 提交于 2020-08-04 03:38:50
问题 I have a table (junction table) with 3 primary keys so when I want to check duplicate records , I must check 3 properties together I wrote a method like this private bool IsDuplicate(long roleId, long componentGroupId, long operationId) { var business = new RoleGroupBusiness(); var result = business.Where(x => x.RoleID == roleId && x.ComponentGroupID == componentGroupId && x.OperationID == operationId).Any(); return result; } and I have a FluentValidator class like this : public class

FluentValidation rule for null object

☆樱花仙子☆ 提交于 2020-07-31 07:24:34
问题 I've been trying to work out how to create a FluentValidation rule that checks if the instance of an object it's validating is not null, prior to validating it's properties. I'd rather encapsulate this null validation in the Validator rather then doing it in the calling code. See example code below with comments where the required logic is needed: namespace MyNamespace { using FluentValidation; public class Customer { public string Surname { get; set; } } public class CustomerValidator:

Use custom validation responses with fluent validation

≯℡__Kan透↙ 提交于 2020-07-17 08:05:44
问题 Hello I am trying to get custom validation response for my webApi using .NET Core. Here I want to have response model like [{ ErrorCode: ErrorField: ErrorMsg: }] I have a validator class and currently we just check ModalState.IsValid for validation Error and pass on the modelstate object as BadRequest. But new requirement wants us to have ErrorCodes for each validation failure. My sample Validator Class public class TestModelValidator : AbstractValidator<TestModel>{ public TestModelValidator

Use custom validation responses with fluent validation

安稳与你 提交于 2020-07-17 08:05:12
问题 Hello I am trying to get custom validation response for my webApi using .NET Core. Here I want to have response model like [{ ErrorCode: ErrorField: ErrorMsg: }] I have a validator class and currently we just check ModalState.IsValid for validation Error and pass on the modelstate object as BadRequest. But new requirement wants us to have ErrorCodes for each validation failure. My sample Validator Class public class TestModelValidator : AbstractValidator<TestModel>{ public TestModelValidator

Use custom validation responses with fluent validation

孤人 提交于 2020-07-17 08:05:06
问题 Hello I am trying to get custom validation response for my webApi using .NET Core. Here I want to have response model like [{ ErrorCode: ErrorField: ErrorMsg: }] I have a validator class and currently we just check ModalState.IsValid for validation Error and pass on the modelstate object as BadRequest. But new requirement wants us to have ErrorCodes for each validation failure. My sample Validator Class public class TestModelValidator : AbstractValidator<TestModel>{ public TestModelValidator

Is it possible to use ReactiveUI bindings in WPF for validating user input with only INotifyDataErrorInfo?

本秂侑毒 提交于 2020-05-29 05:15:12
问题 We're using ReactiveUI.WPF 11.0.1 in our .Net Core WPF application. We're looking into replacing all XAML-based bindings with ReactiveUI-based bindings. There is a ViewModel for the domain type that implements INotifyPropertyChanged and INotifyDataErrorInfo: public class ItemViewModel : INotifyPropertyChanged, INotifyDataErrorInfo { private string Error => string.IsNullOrEmpty(Name) ? "Empty name" : string.Empty; private string _name; public string Name { get => _name; set { _name = value;

Fluent Validation - pass parameter to collection validator

六眼飞鱼酱① 提交于 2020-01-24 04:11:20
问题 I'm using fluent validation i ASP.NET MVC application and I've had a problem. This is my rule: RuleFor(x => x.SimpleList) .SetCollectionValidator(new SimpleListValidator()) .When(x => x.Type == SimpleEnum.SpecificType); I want to pass x.Type param to SimpleListValidator, how can I do this? Some kind of extension method? It should looks like: RuleFor(x => x.SimpleList) .SetCollectionValidator(new SimpleListValidator(x => x.Type)) .When(x => x.Type == SimpleEnum.SpecificType); 回答1: After you

Griffin localization and Fluent Validation

二次信任 提交于 2020-01-17 07:08:11
问题 I am new to Griffin localization, it seems very cool. However, examples are only showing me how to translate MVC validation attributes. I am using minimum if not none of the mvc validation attributes. My idea is (try) not to validate and report messages twice at data layer and UI layer. I create validators at data layer with with Fluent Validation. Could you please give me a quick pointer (if it exists) how we can integrate Griffin Localization with Fluent Validation at data layer? 回答1:

MVC5 comparing two nullable dates with fluent validation

荒凉一梦 提交于 2020-01-16 03:52:43
问题 How can I write a rule in fluent validation to check two nullable dates in that the start date needs to be earlier than the end date. I am thinking along the line of RuleFor(c => c.StartDate) .NotEmpty() if the start date is not empty and end date not empty then compare 回答1: Something like this- RuleFor(ac => ac.StartDate) .NotEmpty().WithMessage("*Required") RuleFor(ac => ac.EndDate) .NotEmpty().WithMessage("*Required") .GreaterThan(r => r.StartDate); Note- The datatypes must be same for

MVC5 comparing two nullable dates with fluent validation

大兔子大兔子 提交于 2020-01-16 03:52:01
问题 How can I write a rule in fluent validation to check two nullable dates in that the start date needs to be earlier than the end date. I am thinking along the line of RuleFor(c => c.StartDate) .NotEmpty() if the start date is not empty and end date not empty then compare 回答1: Something like this- RuleFor(ac => ac.StartDate) .NotEmpty().WithMessage("*Required") RuleFor(ac => ac.EndDate) .NotEmpty().WithMessage("*Required") .GreaterThan(r => r.StartDate); Note- The datatypes must be same for