From 494893257ee6ead98677c5d9facf43c2a74a4bd7 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Mon, 16 Oct 2023 11:48:59 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA?= =?UTF-8?q?=D0=B0=20=D1=81=D0=BE=D0=BE=D1=82=D0=B2=D0=B5=D1=82=D1=81=D1=82?= =?UTF-8?q?=D0=B2=D0=B8=D1=8F=20=D0=BA=D0=BE=D0=BD=D1=82=D0=B0=D0=BA=D1=82?= =?UTF-8?q?=D0=B0=20=D0=B8=20=D1=81=D0=BA=D0=B2=D0=B0=D0=B6=D0=B8=D0=BD?= =?UTF-8?q?=D1=8B=20=D0=BF=D1=80=D0=B8=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B8,=20=D0=BF=D0=BE=D0=B4=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D1=8B=20=D1=80=D0=BE=D1=83=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Services/IWellContactService.cs | 3 ++- .../Services/WellContactService.cs | 16 +++++++++------- .../Controllers/WellContactController.cs | 6 +++--- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/AsbCloudApp/Services/IWellContactService.cs b/AsbCloudApp/Services/IWellContactService.cs index 8cbe8328..2c4026e1 100644 --- a/AsbCloudApp/Services/IWellContactService.cs +++ b/AsbCloudApp/Services/IWellContactService.cs @@ -55,9 +55,10 @@ namespace AsbCloudApp.Services /// /// Удаление контакта /// + /// ключ скважины /// ключ скважины /// /// - Task DeleteAsync(int id, CancellationToken token); + Task DeleteAsync(int idWell, int id, CancellationToken token); } } diff --git a/AsbCloudInfrastructure/Services/WellContactService.cs b/AsbCloudInfrastructure/Services/WellContactService.cs index 7a2a5a07..baf96ad9 100644 --- a/AsbCloudInfrastructure/Services/WellContactService.cs +++ b/AsbCloudInfrastructure/Services/WellContactService.cs @@ -70,22 +70,23 @@ namespace AsbCloudInfrastructure.Services public async Task UpdateAsync(ContactDto contactDto, CancellationToken token) { + var dbContact = await GetContact(contactDto.IdWell, contactDto.Id, token); + if (dbContact is null) + throw new ForbidException("Contact doesn't exist"); + var entity = contactDto.Adapt(); db.Contacts.Update(entity); return await db.SaveChangesAsync(token); } - public async Task DeleteAsync(int id, CancellationToken token) + public async Task DeleteAsync(int idWell, int id, CancellationToken token) { - var contact = await db.Contacts - .Where(c => c.Id == id) - .FirstOrDefaultAsync(token); - - if (contact is null) + var dbContact = await GetContact(idWell, id, token); + if (dbContact is null) throw new ForbidException("Contact doesn't exist"); - db.Contacts.Remove(contact); + db.Contacts.Remove(dbContact); return await db.SaveChangesAsync(token); } @@ -94,6 +95,7 @@ namespace AsbCloudInfrastructure.Services var contact = await db.Contacts .Where(c => c.IdWell == idWell) .Where(c => c.Id == idContact) + .AsNoTracking() .FirstOrDefaultAsync(token); return contact; diff --git a/AsbCloudWebApi/Controllers/WellContactController.cs b/AsbCloudWebApi/Controllers/WellContactController.cs index edca6742..7fef14f2 100644 --- a/AsbCloudWebApi/Controllers/WellContactController.cs +++ b/AsbCloudWebApi/Controllers/WellContactController.cs @@ -32,7 +32,7 @@ namespace AsbCloudWebApi.Controllers /// /// /// - [HttpGet("types")] + [HttpGet("type")] [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] public async Task GetTypesAsync(CancellationToken token) { @@ -47,7 +47,7 @@ namespace AsbCloudWebApi.Controllers /// тип контакта /// /// - [HttpGet("contactType/{contactTypeId}")] + [HttpGet("type/{contactTypeId}")] [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] public async Task GetAllAsync(int idWell, int contactTypeId, CancellationToken token) { @@ -134,7 +134,7 @@ namespace AsbCloudWebApi.Controllers if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false)) return Forbid(); - var result = await wellContactsRepository.DeleteAsync(id, token); + var result = await wellContactsRepository.DeleteAsync(idWell, id, token); return Ok(result); }