Exemple #1
0
        static void ListAndIncludeValidation(AddCustomerDto2 dto)
        {
            var validator = new AddCustomerDto2Validator();
            var validRes  = validator.Validate(dto);

            if (!validRes.IsValid)
            {
                //first error message
                Console.WriteLine(validRes.Errors.FirstOrDefault());
                ////all error messages
                //Console.WriteLine(validRes.ToString(","));
                //Console.WriteLine(string.Join(",", validRes.Errors.Select(x => x.ErrorMessage)));
                //Console.WriteLine(string.Join(",", validRes.Errors));
            }

            //save code ...
        }
Exemple #2
0
        static void Main(string[] args)
        {
            var addCusDto = new AddCustomerDto();

            AddCustomer(addCusDto);

            AddCustomerWithFluentValidation(addCusDto);

            var addCusDto2 = new AddCustomerDto2
            {
                Address = new Address(),
                Hobbies = new List <string> {
                    "", "coding"
                }
            };

            ListAndIncludeValidation(addCusDto2);

            Console.ReadKey();
        }