ProcessMapPlanBaseController<TDto>.Parse() sets IdWell for result dtos

This commit is contained in:
ngfrolov 2024-03-11 16:26:58 +05:00
parent 5c99d4ff57
commit 63638219a2
Signed by: ng.frolov
GPG Key ID: E99907A0357B29A7

View File

@ -53,12 +53,13 @@ public abstract class ProcessMapPlanBaseController<TDto> : ControllerBase
[HttpPost] [HttpPost]
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)] [ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
public async Task<IActionResult> InsertRange([FromRoute] int idWell, IEnumerable<TDto> dtos, CancellationToken token) public async Task<IActionResult> InsertRange([FromRoute][Range(0,int.MaxValue)] int idWell, IEnumerable<TDto> dtos, CancellationToken token)
{ {
if (idWell == 0 || dtos.Any(d => d.IdWell != idWell))
return this.ValidationBadRequest(nameof(dtos), "all dtos should contain same idWell");
var idUser = await AssertUserHasAccessToWell(idWell, token); var idUser = await AssertUserHasAccessToWell(idWell, token);
foreach (var dto in dtos)
dto.IdWell = idWell;
var result = await repository.InsertRange(idUser, dtos, token); var result = await repository.InsertRange(idUser, dtos, token);
return Ok(result); return Ok(result);
} }
@ -75,11 +76,11 @@ public abstract class ProcessMapPlanBaseController<TDto> : ControllerBase
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
public async Task<IActionResult> ClearAndInsertRange([FromRoute] int idWell, IEnumerable<TDto> dtos, CancellationToken token) public async Task<IActionResult> ClearAndInsertRange([FromRoute] int idWell, IEnumerable<TDto> dtos, CancellationToken token)
{ {
if (idWell == 0 || dtos.Any(d => d.IdWell != idWell))
return this.ValidationBadRequest(nameof(dtos), "all dtos should contain same idWell");
var idUser = await AssertUserHasAccessToWell(idWell, token); var idUser = await AssertUserHasAccessToWell(idWell, token);
foreach (var dto in dtos)
dto.IdWell = idWell;
var request = new ProcessMapPlanBaseRequestWithWell(idWell); var request = new ProcessMapPlanBaseRequestWithWell(idWell);
var result = await repository.ClearAndInsertRange(idUser, request, dtos, token); var result = await repository.ClearAndInsertRange(idUser, request, dtos, token);
return Ok(result); return Ok(result);
@ -189,15 +190,14 @@ public abstract class ProcessMapPlanBaseController<TDto> : ControllerBase
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
public async Task<IActionResult> UpdateOrInsertRange([FromRoute] int idWell, IEnumerable<TDto> dtos, CancellationToken token) public async Task<IActionResult> UpdateOrInsertRange([FromRoute] int idWell, IEnumerable<TDto> dtos, CancellationToken token)
{ {
var first = dtos.FirstOrDefault(); if (!dtos.Any())
if (first is null)
return NoContent(); return NoContent();
if (idWell == 0 || dtos.Any(d => d.IdWell != idWell))
return this.ValidationBadRequest(nameof(dtos), "all dtos should contain same idWell");
var idUser = await AssertUserHasAccessToWell(idWell, token); var idUser = await AssertUserHasAccessToWell(idWell, token);
foreach (var dto in dtos)
dto.IdWell = idWell;
var result = await repository.UpdateOrInsertRange(idUser, dtos, token); var result = await repository.UpdateOrInsertRange(idUser, dtos, token);
return Ok(result); return Ok(result);
} }
@ -223,6 +223,9 @@ public abstract class ProcessMapPlanBaseController<TDto> : ControllerBase
try try
{ {
var dto = parserService.Parse(stream, IParserOptionsRequest.Empty()); var dto = parserService.Parse(stream, IParserOptionsRequest.Empty());
foreach (var item in dto.Item)
item.Item.IdWell = idWell;
return Ok(dto); return Ok(dto);
} }
catch (FileFormatException ex) catch (FileFormatException ex)