diff --git a/AsbCloudInfrastructure/Services/WellOperationService/WellOperationImportService.cs b/AsbCloudInfrastructure/Services/WellOperationService/WellOperationImportService.cs index 152f329c..32983a64 100644 --- a/AsbCloudInfrastructure/Services/WellOperationService/WellOperationImportService.cs +++ b/AsbCloudInfrastructure/Services/WellOperationService/WellOperationImportService.cs @@ -298,7 +298,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService if (vCategory is string categoryName) { var category = Categories.Find(c => c.Name.ToLower() == categoryName.ToLower()); - if (category is null) + if (category is null || category.Id < 5000) throw new FileFormatException($"Лист {row.Worksheet.Name}. Строка {row.RowNumber()} указана некорректная операция"); operation.IdCategory = category.Id; diff --git a/AsbCloudWebApi/Controllers/WellOperationController.cs b/AsbCloudWebApi/Controllers/WellOperationController.cs index 9d8f8a2a..ac3ce0f0 100644 --- a/AsbCloudWebApi/Controllers/WellOperationController.cs +++ b/AsbCloudWebApi/Controllers/WellOperationController.cs @@ -1,4 +1,5 @@ using AsbCloudApp.Data; +using AsbCloudApp.Exceptions; using AsbCloudApp.Repositories; using AsbCloudApp.Requests; using AsbCloudApp.Services; @@ -9,6 +10,7 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.IO; +using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -202,18 +204,21 @@ namespace AsbCloudWebApi.Controllers [Permission] [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] public async Task InsertRangeAsync( - [Range(1, int.MaxValue, ErrorMessage = "Id скважины не может быть меньше 1")] int idWell, + [Range(1, int.MaxValue, ErrorMessage = "Id скважины не может быть меньше 1")] int idWell, [FromBody] IEnumerable values, CancellationToken token) { if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false)) return Forbid(); + if (values.Any(v => v.IdCategory < 5000)) + throw new ArgumentInvalidException($"Некорректная категория скважины / скважин", nameof(values)); + foreach (var value in values) { value.IdWell = idWell; value.LastUpdateDate = DateTimeOffset.UtcNow; - value.IdUser = User.GetUserId(); + value.IdUser = User.GetUserId(); } var result = await operationRepository.InsertRangeAsync(values, token) @@ -239,6 +244,9 @@ namespace AsbCloudWebApi.Controllers if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false)) return Forbid(); + if (value.IdCategory < 5000) + throw new ArgumentInvalidException($"Выбрана некорректная категория скважины", nameof(value.IdCategory)); + value.IdWell = idWell; value.Id = idOperation; value.LastUpdateDate = DateTimeOffset.UtcNow;