GuestLog - Added delete to GuestDocument list.

This commit is contained in:
2026-06-22 18:21:06 +02:00
parent 9f44ff6e3d
commit d93ba3d9ee
3 changed files with 75 additions and 10 deletions
@@ -69,16 +69,51 @@ public class GuestDocumentService(
}
}
public bool UpdateDocument(GuestDocumentDTO dto)
public Task<bool> UpdateDocumentAsync(GuestDocumentDTO dto)
{
throw new NotImplementedException();
}
public Task<bool> DeleteDocumentAsync(GuestDocumentDTO dto)
{
if (dto.DocumentType is null || dto.DocumentNum is null)
{
throw new InvalidOperationException("GuestDocumentService - DeleteDocument: A DTO without key can't be deleted!");
}
return DeleteDocumentAsync(dto.DocumentType, dto.DocumentNum);
}
public async Task<bool> DeleteDocumentAsync(string docType, string docNum)
{
using var dbContext = contextFactory.CreateDbContext();
GuestDocument? dbItem = await dbContext.GuestDocuments.FindAsync(docType, docNum);
if (dbItem is null)
{
logger.LogWarning("GuestDocumentService - DeleteDocument: Error deleting GuestDocument. Entity not found with key: '{key}-{key2}'", docType, docNum);
return false;
}
try
{
dbContext.GuestDocuments.Remove(dbItem);
await dbContext.SaveChangesAsync();
logger.LogInformation("GuestDocumentService - DeleteDocument: GuestDocument deleted: '{id}'", dbItem.GetFullKey());
return true;
}
catch (Exception ex)
{
logger.LogError(ex, "GuestDocumentService - CreateDocument: Error deleting GuestDocument: '{id}'", dbItem.GetFullKey());
return false;
}
}
public async Task<GuestDocumentDTO?> GetDtoByIdAsync(string docType, string docNum)
{
using var dbContext = contextFactory.CreateDbContext();
GuestDocument? dbItem = await dbContext.GuestDocuments.FindAsync(new { docType, docNum });
GuestDocument? dbItem = await dbContext.GuestDocuments.FindAsync(docType, docNum);
return dbItem is not null ? GetDtoFromDb(dbItem) : null;
}