diff --git a/AsbCloudInfrastructure/Services/WellService.cs b/AsbCloudInfrastructure/Services/WellService.cs index 105cb5b3..6a805560 100644 --- a/AsbCloudInfrastructure/Services/WellService.cs +++ b/AsbCloudInfrastructure/Services/WellService.cs @@ -106,18 +106,18 @@ namespace AsbCloudInfrastructure.Services public async Task GetOrDefaultStatAsync(int idWell, CancellationToken token) { - var entity = await GetOrDefaultAsync(idWell, token); + var well = await GetOrDefaultAsync(idWell, token); - if (entity is null) + if (well is null) return null; - var dto = wellInfoService.FirstOrDefault(well => well.Id == idWell); + var wellInfo = wellInfoService.FirstOrDefault(well => well.Id == idWell); - if (dto is null) - return entity.Adapt(); + if (wellInfo is null) + return well.Adapt(); - dto.IdState = entity.IdState; - return dto; + wellInfo.IdState = well.IdState; + return wellInfo; } public async Task> GetAsync(WellRequest request, CancellationToken token) diff --git a/AsbCloudWebApi/Controllers/WellController.cs b/AsbCloudWebApi/Controllers/WellController.cs index 51e215ca..2a0ad437 100644 --- a/AsbCloudWebApi/Controllers/WellController.cs +++ b/AsbCloudWebApi/Controllers/WellController.cs @@ -1,4 +1,5 @@ using AsbCloudApp.Data; +using AsbCloudApp.Exceptions; using AsbCloudApp.Services; using AsbCloudDb.Model; using Microsoft.AspNetCore.Authorization; @@ -136,7 +137,11 @@ namespace AsbCloudWebApi.Controllers return Forbid(); var dto = await wellService.GetOrDefaultAsync(idWell, token); - dto!.IdState = idState; + + if (dto is null) + return this.ValidationBadRequest(nameof(idWell), $"Скважина с id: {idWell} недоступна"); + + dto.IdState = idState; var result = await wellService.UpdateAsync(dto, token) .ConfigureAwait(false);