using AutobusApi.Application.Common.Interfaces; using AutobusApi.Domain.Entities; using MediatR; namespace AutobusApi.Application.Cities.Commands.CreateCity; public class CreateCityCommandHandler : IRequestHandler { private readonly IApplicationDbContext _dbContext; public CreateCityCommandHandler(IApplicationDbContext dbContext) { _dbContext = dbContext; } public async Task Handle( CreateCityCommand request, CancellationToken cancellationToken) { var city = new City(); city.Name = request.Name; city.RegionId = request.RegionId; _dbContext.Cities.Add(city); await _dbContext.SaveChangesAsync(cancellationToken); return city.Id; } }