Major update
This commit is contained in:
25
divisions/Handlers/GetDivisionByIdQueryHandler.cs
Normal file
25
divisions/Handlers/GetDivisionByIdQueryHandler.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using Divisions.DbContexts;
|
||||
using Divisions.Entities;
|
||||
using Divisions.Queries;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Divisions.Handlers
|
||||
{
|
||||
public class GetDivisionByIdQueryHandler : IRequestHandler<GetDivisionByIdQuery, Division>
|
||||
{
|
||||
private readonly DivisionsContext _dbContext;
|
||||
|
||||
public GetDivisionByIdQueryHandler(DivisionsContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
|
||||
}
|
||||
|
||||
public async Task<Division> Handle(GetDivisionByIdQuery request, CancellationToken cancellation)
|
||||
{
|
||||
return await _dbContext.Divisions.Where(d => d.Id == request.DivisionId).FirstOrDefaultAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user