ReferenciaCatastralAttribute.cs
1 using System.ComponentModel.DataAnnotations;
2 
3 namespace sage.ew.contabilidad.Validations
4 {
5  internal class ReferenciaCatastralRequiredAttribute : RequiredAttribute
6  {
7  protected override ValidationResult IsValid(object value, ValidationContext validationContext)
8  {
9  RefCatastral _refCatastral = validationContext.ObjectInstance as RefCatastral;
10  string lcReferencia = string.Empty;
11  if (!string.IsNullOrEmpty(value.ToString()))
12  {
13  if (value.ToString().Trim().Length < 20)
14  return new ValidationResult("La referencia catastral debe tener como mínimo 20 caracteres.", new string[] { validationContext.MemberName });
15  }
16  else
17  {
18  if (_refCatastral._Situacion == 4)
19  {
20  // Territorio Canarias
21  if (_refCatastral._Territorio == 1 || _refCatastral._Territorio == 3)
22  return new ValidationResult("Es necesario indicar la referencia catastral del inmueble.", new string[] { validationContext.MemberName });
23  }
24  else
25  {
26  if (_refCatastral._Situacion != 3 && _refCatastral._Territorio < 2)
27  return new ValidationResult("Es necesario indicar la referencia catastral del inmueble.", new string[] { validationContext.MemberName });
28  }
29  }
30 
31  return ValidationResult.Success;
32  // return base.IsValid(value, validationContext);
33 
34  }
35  }
36 }
Clase Referencias catastrales
Definition: RefCatastral.cs:20