This commit is contained in:
2023-07-28 21:18:18 +03:00
parent 5ecefe5756
commit 90f0386bfe
53 changed files with 3067 additions and 267 deletions
@@ -0,0 +1,35 @@
namespace MyOffice.Web.Infrastructure.Attributes
{
using System.ComponentModel.DataAnnotations;
using Core.Extensions;
public class AsGuidAttribute: ValidationAttribute
{
private readonly bool _nullable;
public AsGuidAttribute(bool nullable = false)
{
_nullable = nullable;
}
protected override ValidationResult? IsValid(object? value, ValidationContext validationContext)
{
if (value == null && _nullable)
{
return ValidationResult.Success;
}
if (value == null || value.ToString().IsMissing())
{
return new ValidationResult("Id parameter is not valid");
}
if (!Guid.TryParse(value.ToString(), out _))
{
return new ValidationResult("Id parameter is not valid");
}
return ValidationResult.Success;
}
}
}