forked from ddrilling/AsbCloudServer
61 lines
2.0 KiB
C#
61 lines
2.0 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.ComponentModel.DataAnnotations;
|
|||
|
|
|||
|
namespace AsbCloudApp.Requests;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// класс с фильтрами для запроса
|
|||
|
/// </summary>
|
|||
|
public class SubsystemBaseRequest: RequestBase, IValidatableObject
|
|||
|
{
|
|||
|
private static readonly DateTimeOffset validationMinDate = new DateTimeOffset(2020,01,01,0,0,0, TimeSpan.Zero);
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Больше или равно дате
|
|||
|
/// </summary>
|
|||
|
public DateTimeOffset? GeDate { get; set; }
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Меньше или равно дате
|
|||
|
/// </summary>
|
|||
|
public DateTimeOffset? LeDate { get; set; }
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Больше или равно глубины забоя
|
|||
|
/// </summary>
|
|||
|
public double? GeDepth { get; set; }
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Меньше или равно глубины забоя
|
|||
|
/// </summary>
|
|||
|
public double? LeDepth { get; set; }
|
|||
|
|
|||
|
/// <inheritdoc/>
|
|||
|
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
|||
|
{
|
|||
|
if (GeDate.HasValue && GeDate < validationMinDate)
|
|||
|
yield return new ValidationResult(
|
|||
|
$"Должно быть больше {validationMinDate:O})",
|
|||
|
new[] { nameof(GeDate) });
|
|||
|
|
|||
|
if (LeDate.HasValue && GeDate.HasValue)
|
|||
|
{
|
|||
|
if (LeDate < GeDate)
|
|||
|
yield return new ValidationResult(
|
|||
|
$"{nameof(LeDate)} должно быть больше {nameof(GeDate)}. ({LeDate:O} < {GeDate:O})",
|
|||
|
new[] { nameof(LeDate), nameof(GeDate) });
|
|||
|
}
|
|||
|
|
|||
|
if (LeDepth.HasValue && GeDepth.HasValue)
|
|||
|
{
|
|||
|
if (LeDepth < GeDepth)
|
|||
|
yield return new ValidationResult(
|
|||
|
$"{nameof(LeDepth)} должно быть больше {nameof(GeDepth)}. ({LeDepth} < {GeDepth})",
|
|||
|
new[] { nameof(LeDepth), nameof(GeDepth) });
|
|||
|
}
|
|||
|
|
|||
|
yield break;
|
|||
|
}
|
|||
|
}
|