Пример #1
0
            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());
            }
Пример #2
0
            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);
            }