You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
using Common.Models.ModelValidation; using Common.Models.RequestResponse; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq;
namespace Common.Utility { public class CustomModelValidaton { public TPResponse IsModelValid<T>(T model) where T : class { var jm = new ValidationContext(model, serviceProvider: null, items: null); var results = new List<ValidationResult>(); bool IsValid = Validator.TryValidateObject(model, jm, results); if (!IsValid) { var errorList = results.Select(x => new FieldsValidation() { Name = x.MemberNames.First(), Message = x.ErrorMessage }).ToList(); TPResponse tPResponse = new TPResponse() { ResponseCode = "104", Msg = "Model Validation Failed !", Data = errorList }; return tPResponse; } return null; } } }
|