forked from ddrilling/AsbCloudServer
Проверка соответствия контакта и скважины при удалении, подправлены роуты
This commit is contained in:
parent
c869dd705d
commit
494893257e
@ -55,9 +55,10 @@ namespace AsbCloudApp.Services
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Удаление контакта
|
/// Удаление контакта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="idWell">ключ скважины</param>
|
||||||
/// <param name="id">ключ скважины</param>
|
/// <param name="id">ключ скважины</param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<int> DeleteAsync(int id, CancellationToken token);
|
Task<int> DeleteAsync(int idWell, int id, CancellationToken token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,22 +70,23 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
public async Task<int> UpdateAsync(ContactDto contactDto, CancellationToken token)
|
public async Task<int> 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<Contact>();
|
var entity = contactDto.Adapt<Contact>();
|
||||||
db.Contacts.Update(entity);
|
db.Contacts.Update(entity);
|
||||||
|
|
||||||
return await db.SaveChangesAsync(token);
|
return await db.SaveChangesAsync(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<int> DeleteAsync(int id, CancellationToken token)
|
public async Task<int> DeleteAsync(int idWell, int id, CancellationToken token)
|
||||||
{
|
{
|
||||||
var contact = await db.Contacts
|
var dbContact = await GetContact(idWell, id, token);
|
||||||
.Where(c => c.Id == id)
|
if (dbContact is null)
|
||||||
.FirstOrDefaultAsync(token);
|
|
||||||
|
|
||||||
if (contact is null)
|
|
||||||
throw new ForbidException("Contact doesn't exist");
|
throw new ForbidException("Contact doesn't exist");
|
||||||
|
|
||||||
db.Contacts.Remove(contact);
|
db.Contacts.Remove(dbContact);
|
||||||
return await db.SaveChangesAsync(token);
|
return await db.SaveChangesAsync(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,6 +95,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
var contact = await db.Contacts
|
var contact = await db.Contacts
|
||||||
.Where(c => c.IdWell == idWell)
|
.Where(c => c.IdWell == idWell)
|
||||||
.Where(c => c.Id == idContact)
|
.Where(c => c.Id == idContact)
|
||||||
|
.AsNoTracking()
|
||||||
.FirstOrDefaultAsync(token);
|
.FirstOrDefaultAsync(token);
|
||||||
|
|
||||||
return contact;
|
return contact;
|
||||||
|
@ -32,7 +32,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet("types")]
|
[HttpGet("type")]
|
||||||
[ProducesResponseType(typeof(IEnumerable<CompanyTypeDto>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(IEnumerable<CompanyTypeDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> GetTypesAsync(CancellationToken token)
|
public async Task<IActionResult> GetTypesAsync(CancellationToken token)
|
||||||
{
|
{
|
||||||
@ -47,7 +47,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// <param name="contactTypeId">тип контакта</param>
|
/// <param name="contactTypeId">тип контакта</param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet("contactType/{contactTypeId}")]
|
[HttpGet("type/{contactTypeId}")]
|
||||||
[ProducesResponseType(typeof(IEnumerable<ContactDto>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(IEnumerable<ContactDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> GetAllAsync(int idWell, int contactTypeId, CancellationToken token)
|
public async Task<IActionResult> GetAllAsync(int idWell, int contactTypeId, CancellationToken token)
|
||||||
{
|
{
|
||||||
@ -134,7 +134,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var result = await wellContactsRepository.DeleteAsync(id, token);
|
var result = await wellContactsRepository.DeleteAsync(idWell, id, token);
|
||||||
|
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user