using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; namespace AsbCloudApp.Requests { /// /// класс с фильтрами для запроса /// public class SubsystemTimeRequest: RequestBase, IValidatableObject { private static readonly DateTime validationMinDate = new DateTime(2020,01,01,0,0,0,DateTimeKind.Utc); /// /// идентификатор скважины /// [Required] public int IdWell { get; set; } /// /// идентификатор подсистемы /// public IEnumerable IdsSubsystems { get; set; } = Enumerable.Empty(); /// /// Больше или равно дате /// public DateTime? GeDate { get; set; } /// /// Меньше или равно дате /// public DateTime? LtDate { get; set; } /// /// Больше или равно глубины забоя /// public double? GtDepth { get; set; } /// /// Меньше или равно глубины забоя /// public double? LtDepth { get; set; } /// public IEnumerable Validate(ValidationContext validationContext) { if (GeDate.HasValue && GeDate < validationMinDate) yield return new ValidationResult( $"Должно быть больше {validationMinDate:O})", new[] { nameof(GeDate) }); if (LtDate.HasValue && GeDate.HasValue) { if (LtDate < GeDate) yield return new ValidationResult( $"{nameof(LtDate)} должно быть больше {nameof(GeDate)}. ({LtDate:O} < {GeDate:O})", new[] { nameof(LtDate), nameof(GeDate) }); } if (LtDepth.HasValue && GtDepth.HasValue) { if (LtDepth < GtDepth) yield return new ValidationResult( $"{nameof(LtDepth)} должно быть больше {nameof(GtDepth)}. ({LtDepth} < {GtDepth})", new[] { nameof(LtDepth), nameof(GtDepth) }); } yield break; } } }