SHA256
GuestLog - Added delete to GuestDocument list.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,9 @@ namespace Somnia.GuestLog.Services;
|
||||
public interface IGuestDocumentService
|
||||
{
|
||||
public Task<bool> CreateDocumentAsync(GuestDocumentDTO dto);
|
||||
public bool UpdateDocument(GuestDocumentDTO dto);
|
||||
public Task<bool> UpdateDocumentAsync(GuestDocumentDTO dto);
|
||||
public Task<bool> DeleteDocumentAsync(GuestDocumentDTO dto);
|
||||
public Task<bool> DeleteDocumentAsync(string docType, string docNum);
|
||||
|
||||
public Task<GuestDocumentDTO?> GetDtoByIdAsync(string docType, string docNum);
|
||||
public Task<IEnumerable<GuestDocumentDTO>> GetDtoListAsync();
|
||||
|
||||
Reference in New Issue
Block a user