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); }