Merge pull request 'Добавить валидацию id категории операции >= 5000.' (#58) from feature/deny-category-choose into dev

Reviewed-on: http://test.digitaldrilling.ru:8080/DDrilling/AsbCloudServer/pulls/58
This commit is contained in:
Никита Фролов 2023-06-06 15:53:33 +05:00
commit b05fa001c3
3 changed files with 8 additions and 7 deletions

View File

@ -8,10 +8,7 @@ namespace AsbCloudApp.Data
/// Операции на скважине (заведенные пользователем) /// Операции на скважине (заведенные пользователем)
/// </summary> /// </summary>
public class WellOperationDto : ItemInfoDto, IId, IWellRelated public class WellOperationDto : ItemInfoDto, IId, IWellRelated
{ {
/// <inheritdoc/> /// <inheritdoc/>
public int Id { get; set; } public int Id { get; set; }
@ -34,6 +31,7 @@ namespace AsbCloudApp.Data
/// id категории операции /// id категории операции
/// </summary> /// </summary>
[Required] [Required]
[Range(5000, int.MaxValue)]
public int IdCategory { get; set; } public int IdCategory { get; set; }
/// <summary> /// <summary>

View File

@ -45,6 +45,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
if (categories is null) if (categories is null)
{ {
categories = db.WellOperationCategories categories = db.WellOperationCategories
.Where(c => c.Id >= 5000)
.AsNoTracking() .AsNoTracking()
.ToList(); .ToList();
} }
@ -299,7 +300,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
{ {
var category = Categories.Find(c => c.Name.ToLower() == categoryName.ToLower()); var category = Categories.Find(c => c.Name.ToLower() == categoryName.ToLower());
if (category is null) if (category is null)
throw new FileFormatException($"Лист {row.Worksheet.Name}. Строка {row.RowNumber()} указана некорректная операция"); throw new FileFormatException($"Лист {row.Worksheet.Name}. Строка {row.RowNumber()} указана некорректная операция ({categoryName})");
operation.IdCategory = category.Id; operation.IdCategory = category.Id;
operation.CategoryName = category.Name; operation.CategoryName = category.Name;

View File

@ -1,4 +1,5 @@
using AsbCloudApp.Data; using AsbCloudApp.Data;
using AsbCloudApp.Exceptions;
using AsbCloudApp.Repositories; using AsbCloudApp.Repositories;
using AsbCloudApp.Requests; using AsbCloudApp.Requests;
using AsbCloudApp.Services; using AsbCloudApp.Services;
@ -9,6 +10,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.IO; using System.IO;
using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -202,7 +204,7 @@ namespace AsbCloudWebApi.Controllers
[Permission] [Permission]
[ProducesResponseType(typeof(IEnumerable<WellOperationDto>), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(IEnumerable<WellOperationDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> InsertRangeAsync( public async Task<IActionResult> InsertRangeAsync(
[Range(1, int.MaxValue, ErrorMessage = "Id скважины не может быть меньше 1")] int idWell, [Range(1, int.MaxValue, ErrorMessage = "Id скважины не может быть меньше 1")] int idWell,
[FromBody] IEnumerable<WellOperationDto> values, [FromBody] IEnumerable<WellOperationDto> values,
CancellationToken token) CancellationToken token)
{ {
@ -213,7 +215,7 @@ namespace AsbCloudWebApi.Controllers
{ {
value.IdWell = idWell; value.IdWell = idWell;
value.LastUpdateDate = DateTimeOffset.UtcNow; value.LastUpdateDate = DateTimeOffset.UtcNow;
value.IdUser = User.GetUserId(); value.IdUser = User.GetUserId();
} }
var result = await operationRepository.InsertRangeAsync(values, token) var result = await operationRepository.InsertRangeAsync(values, token)