public async Task <string> Handle(CreateAreaCommand request, CancellationToken cancellationToken) { var city = await _distributorRepository.FindCityByIdAsync(request.CityId); if (city == null) { throw new CityNotFoundException(request.CityId); } var area = city.AddArea(request.Name); _distributorRepository.UpdateCity(city); await _distributorRepository.UnitOfWork.SaveEntitiesAsync(); return(area.Id.ToString()); }
public async Task <Unit> Handle(DeleteAreaCommand request, CancellationToken cancellationToken) { // get distributor by id var city = await _distributorRepository.FindCityByIdAsync(request.CityId); if (city == null) { throw new CityNotFoundException(request.CityId); } city.DeleteArea(request.AreaId); _distributorRepository.UpdateCity(city); // save changes in the database and rase DistributorUpdated event await _distributorRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken); return(Unit.Value); }