forked from ddrilling/AsbCloudServer
Валидация с использованием yield
This commit is contained in:
parent
ff208a6aa8
commit
d4935b0e7b
@ -339,7 +339,7 @@ public class WellOperationRepository : IWellOperationRepository
|
|||||||
var firstOperation = wellOperationDtos
|
var firstOperation = wellOperationDtos
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
if (firstOperation is null)
|
if (firstOperation is null)
|
||||||
return Enumerable.Empty<ValidationResult>();
|
yield break;
|
||||||
|
|
||||||
var request = new WellOperationRequest()
|
var request = new WellOperationRequest()
|
||||||
{
|
{
|
||||||
@ -353,7 +353,9 @@ public class WellOperationRepository : IWellOperationRepository
|
|||||||
|
|
||||||
var wellOperationsUnion = entities.Union(wellOperationDtos).OrderBy(o => o.DateStart);
|
var wellOperationsUnion = entities.Union(wellOperationDtos).OrderBy(o => o.DateStart);
|
||||||
|
|
||||||
return Validate(wellOperationsUnion);
|
var results = Validate(wellOperationsUnion);
|
||||||
|
foreach ( var result in results)
|
||||||
|
yield return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<ValidationResult> Validate(IEnumerable<WellOperationDto> wellOperationDtos)
|
public IEnumerable<ValidationResult> Validate(IEnumerable<WellOperationDto> wellOperationDtos)
|
||||||
@ -361,12 +363,10 @@ public class WellOperationRepository : IWellOperationRepository
|
|||||||
var firstOperation = wellOperationDtos
|
var firstOperation = wellOperationDtos
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
if (firstOperation is null)
|
if (firstOperation is null)
|
||||||
return Enumerable.Empty<ValidationResult>();
|
yield break;
|
||||||
|
|
||||||
var validationResults = new List<ValidationResult>();
|
var wellOperations = wellOperationDtos.OrderBy(o => o.DateStart).ToArray();
|
||||||
|
for (var i = 1; i < wellOperations.Length; i++)
|
||||||
var wellOperations = wellOperationDtos.ToArray();
|
|
||||||
for (var i = wellOperations.Count() - 1; i >= 1; i--)
|
|
||||||
{
|
{
|
||||||
var prevOperation = wellOperations[i - 1];
|
var prevOperation = wellOperations[i - 1];
|
||||||
var currentOperation = wellOperations[i];
|
var currentOperation = wellOperations[i];
|
||||||
@ -378,20 +378,18 @@ public class WellOperationRepository : IWellOperationRepository
|
|||||||
|
|
||||||
if (prevOperationDateStart.AddDays(Gap) < currentOperationDateStart)
|
if (prevOperationDateStart.AddDays(Gap) < currentOperationDateStart)
|
||||||
{
|
{
|
||||||
validationResults.Add(new ValidationResult(
|
yield return new ValidationResult(
|
||||||
$"Разница дат между операциями не должна превышать 90 дней",
|
$"Разница дат между операциями не должна превышать 90 дней",
|
||||||
new[] { nameof(wellOperations) }));
|
new[] { nameof(wellOperations) });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prevOperationDateEnd > currentOperationDateStart)
|
if (prevOperationDateEnd > currentOperationDateStart)
|
||||||
{
|
{
|
||||||
validationResults.Add(new ValidationResult(
|
yield return new ValidationResult(
|
||||||
$"Предыдущая операция не завершена",
|
$"Предыдущая операция не завершена",
|
||||||
new[] { nameof(wellOperations) }));
|
new[] { nameof(wellOperations) });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return validationResults;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
|
Loading…
Reference in New Issue
Block a user