правки по валидации

This commit is contained in:
Olga Nemt 2024-01-25 16:52:27 +05:00
parent 672f78fca9
commit 4bd0a835fc
2 changed files with 5 additions and 6 deletions

View File

@ -237,8 +237,8 @@ namespace AsbCloudWebApi.Controllers
wellOperation.IdUser = User.GetUserId(); wellOperation.IdUser = User.GetUserId();
wellOperation.IdType = idType; wellOperation.IdType = idType;
var validationResult = awaitoperationRepository.ValidateWithDbAsync(new[] { wellOperation }, cancellationToken); var validationResult = await operationRepository.ValidateWithDbAsync(new[] { wellOperation }, cancellationToken);
if(validationResult.Any()) if (validationResult.Any())
return this.ValidationBadRequest(validationResult); return this.ValidationBadRequest(validationResult);
var result = await operationRepository.InsertRangeAsync(new[] { wellOperation }, cancellationToken); var result = await operationRepository.InsertRangeAsync(new[] { wellOperation }, cancellationToken);
@ -292,7 +292,7 @@ namespace AsbCloudWebApi.Controllers
} }
var validationResult = Validate(wellOperations, deleteBeforeInsert, cancellationToken); var validationResult = await Validate(wellOperations, deleteBeforeInsert, cancellationToken);
if (validationResult.Any()) if (validationResult.Any())
return this.ValidationBadRequest(validationResult); return this.ValidationBadRequest(validationResult);
@ -309,7 +309,7 @@ namespace AsbCloudWebApi.Controllers
/// <param name="deleteBeforeInsert"></param> /// <param name="deleteBeforeInsert"></param>
/// <param name="cancellationToken"></param> /// <param name="cancellationToken"></param>
/// <returns></returns> /// <returns></returns>
private IEnumerable<ValidationResult> Validate(IEnumerable<WellOperationDto> wellOperations, bool deleteBeforeInsert, CancellationToken cancellationToken) private async Task<IEnumerable<ValidationResult>> Validate(IEnumerable<WellOperationDto> wellOperations, bool deleteBeforeInsert, CancellationToken cancellationToken)
{ {
if (deleteBeforeInsert) if (deleteBeforeInsert)
return operationRepository.Validate(wellOperations); return operationRepository.Validate(wellOperations);

View File

@ -65,8 +65,7 @@ namespace Microsoft.AspNetCore.Mvc
/// </para> /// </para>
/// </summary> /// </summary>
/// <param name="controller"></param> /// <param name="controller"></param>
/// <param name="paramName"></param> /// <param name="validationResults"></param>
/// <param name="error"></param>
/// <returns></returns> /// <returns></returns>
public static BadRequestObjectResult ValidationBadRequest(this ControllerBase controller, IEnumerable<ValidationResult> validationResults) public static BadRequestObjectResult ValidationBadRequest(this ControllerBase controller, IEnumerable<ValidationResult> validationResults)
{ {