28 lines
804 B
C#
28 lines
804 B
C#
using Heimdall.Application.Common;
|
|||
|
|
using MediatR;
|
||
|
|
|
||
|
|
namespace Heimdall.Application.Cameras.Commands.DeleteCamera;
|
||
|
|
|
||
|
|
public record DeleteCameraCommand(Guid Id) : IRequest<ServiceResult>;
|
||
|
|
|
||
|
|
public class DeleteCameraCommandHandler : IRequestHandler<DeleteCameraCommand, ServiceResult>
|
||
|
|
{
|
||
|
|
private readonly IApplicationDbContext _db;
|
||
|
|
|
||
|
|
public DeleteCameraCommandHandler(IApplicationDbContext db)
|
||
|
|
{
|
||
|
|
_db = db;
|
||
|
|
}
|
||
|
|
|
||
|
|
public async Task<ServiceResult> Handle(DeleteCameraCommand request, CancellationToken ct)
|
||
|
|
{
|
||
|
|
var camera = await _db.Cameras.FindAsync([request.Id], ct);
|
||
|
|
if (camera is null)
|
||
|
|
return ServiceResult.NotFound("Camera not found");
|
||
|
|
|
||
|
|
camera.SoftDelete();
|
||
|
|
await _db.SaveChangesAsync(ct);
|
||
|
|
|
||
|
|
return ServiceResult.Success();
|
||
|
|
}
|
||
|
|
}
|