-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathUpdatePlateNumberCommandHandler.cs
More file actions
40 lines (27 loc) · 1.07 KB
/
UpdatePlateNumberCommandHandler.cs
File metadata and controls
40 lines (27 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using Mediator;
using Microsoft.EntityFrameworkCore;
using OpenAlprWebhookProcessor.Data;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace OpenAlprWebhookProcessor.Features.LicensePlates.Commands.UpdatePlateNumber;
public class UpdatePlateNumberCommandHandler : ICommandHandler<UpdatePlateNumberCommand>
{
private readonly ProcessorContext _context;
public UpdatePlateNumberCommandHandler(ProcessorContext context)
{
_context = context;
}
public async ValueTask<Unit> Handle(UpdatePlateNumberCommand request, CancellationToken cancellationToken)
{
var plateGroup = await _context.PlateGroups
.FirstOrDefaultAsync(x => x.Id == request.PlateId, cancellationToken);
if (plateGroup == null)
{
throw new InvalidOperationException($"Plate with ID {request.PlateId} not found");
}
plateGroup.BestNumber = request.PlateNumber;
await _context.SaveChangesAsync(cancellationToken);
return Unit.Value;
}
}