forked from ddrilling/AsbCloudServer
74 lines
2.5 KiB
C#
74 lines
2.5 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel.DataAnnotations;
|
||
using System.Linq;
|
||
|
||
namespace AsbCloudApp.Requests
|
||
{
|
||
/// <summary>
|
||
/// класс с фильтрами для запроса
|
||
/// </summary>
|
||
public class SubsystemTimeRequest: RequestBase, IValidatableObject
|
||
{
|
||
private static readonly DateTime validationMinDate = new DateTime(2020,01,01,0,0,0,DateTimeKind.Utc);
|
||
|
||
/// <summary>
|
||
/// идентификатор скважины
|
||
/// </summary>
|
||
[Required]
|
||
public int IdWell { get; set; }
|
||
|
||
/// <summary>
|
||
/// идентификатор подсистемы
|
||
/// </summary>
|
||
public IEnumerable<int> IdsSubsystems { get; set; } = Enumerable.Empty<int>();
|
||
|
||
/// <summary>
|
||
/// Больше или равно дате
|
||
/// </summary>
|
||
public DateTime? GeDate { get; set; }
|
||
|
||
/// <summary>
|
||
/// Меньше или равно дате
|
||
/// </summary>
|
||
public DateTime? LtDate { get; set; }
|
||
|
||
/// <summary>
|
||
/// Больше или равно глубины забоя
|
||
/// </summary>
|
||
public double? GtDepth { get; set; }
|
||
|
||
/// <summary>
|
||
/// Меньше или равно глубины забоя
|
||
/// </summary>
|
||
public double? LtDepth { get; set; }
|
||
|
||
/// <inheritdoc/>
|
||
public IEnumerable<ValidationResult> 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;
|
||
}
|
||
}
|
||
}
|