using AutobusApi.Application.Common.Interfaces; using AutobusApi.Domain.Entities; using MediatR; namespace AutobusApi.Application.Regions.Commands.CreateRegion; public class CreateRegionCommandHandler : IRequestHandler { private readonly IApplicationDbContext _dbContext; public CreateRegionCommandHandler(IApplicationDbContext dbContext) { _dbContext = dbContext; } public async Task Handle( CreateRegionCommand request, CancellationToken cancellationToken) { var region = new Region(); region.Name = request.Name; region.CountryId = request.CountryId; _dbContext.Regions.Add(region); await _dbContext.SaveChangesAsync(cancellationToken); return region.Id; } }