diff --git a/src/MaksIT.Core/Abstractions/Webapi/PatchRequestModelBase.cs b/src/MaksIT.Core/Abstractions/Webapi/PatchRequestModelBase.cs index fefe6c5..458094b 100644 --- a/src/MaksIT.Core/Abstractions/Webapi/PatchRequestModelBase.cs +++ b/src/MaksIT.Core/Abstractions/Webapi/PatchRequestModelBase.cs @@ -1,12 +1,19 @@ -using System.Reflection; +using System.ComponentModel.DataAnnotations; +using System.Reflection; using MaksIT.Core.Webapi.Models; namespace MaksIT.Core.Abstractions.Webapi; -public abstract class PatchRequestModelBase : RequestModelBase { - public bool HasNonNullPatchField => GetType() +public abstract class PatchRequestModelBase : RequestModelBase, IValidatableObject { + private bool HasNonNullPatchField => GetType() .GetProperties(BindingFlags.Public | BindingFlags.Instance) .Where(prop => prop.PropertyType.IsGenericType && prop.PropertyType.GetGenericTypeDefinition() == typeof(PatchField<>)) .Any(prop => prop.GetValue(this) != null); + + public virtual IEnumerable Validate(ValidationContext validationContext) { + if (!HasNonNullPatchField) { + yield return new ValidationResult("At least one patch field must be provided", new string[] { "PatchField" }); + } + } } diff --git a/src/MaksIT.Core/MaksIT.Core.csproj b/src/MaksIT.Core/MaksIT.Core.csproj index b3ce5ad..2e889ad 100644 --- a/src/MaksIT.Core/MaksIT.Core.csproj +++ b/src/MaksIT.Core/MaksIT.Core.csproj @@ -8,7 +8,7 @@ MaksIT.Core - 1.2.0 + 1.2.1 Maksym Sadovnychyy MAKS-IT MaksIT.Core