feat StayExport - Added delete for StayExports.

This commit is contained in:
2026-09-06 22:24:25 +02:00
parent 6fe5a5e5a3
commit 4b72e3b3d3
6 changed files with 84 additions and 11 deletions
@@ -1,5 +1,6 @@
using FluentValidation;
using Microsoft.EntityFrameworkCore;
using Somnia.GuestLog.Enums.Services;
using Somnia.GuestLog.Infrastructure;
using Somnia.GuestLog.Models;
using Somnia.GuestLog.Models.DTOs;
@@ -59,6 +60,33 @@ public class StayExportFileEntityService(
throw new NotImplementedException();
}
public async Task<Result> DeleteStayExportAsync(StayExportFileDTO dto)
{
try
{
using var dbContext = contextFactory.CreateDbContext();
int deletedCount = await dbContext.StayExportFiles
.Where(e => e.Id == dto.Id)
.ExecuteDeleteAsync();
if (deletedCount == 0)
{
logger.LogWarning("StayExportFileService - DeleteStayExportAsync: Error deleting StayExport. Entity not found with ID: '{ID}'", dto.Id);
return Result.Fail(ResultCode.NotFound);
}
logger.LogInformation(
"StayExportFileService - DeleteStayExportAsync: StayExport deleted with Id: '{id}'.", dto.Id);
return Result.Ok();
}
catch (Exception ex)
{
logger.LogError(ex, "StayExportFileService - DeleteStayExportAsync: Error creating GuestDocument");
return Result.FailUnknownError();
}
}
public async Task<StayExportFileDTO?> GetDtoByIdAsync(long id)
{