Ejemplo n.º 1
0
            public async Task <string> Handle(CreateDistributorCommand request, CancellationToken cancellationToken)
            {
                var distributor = new Distributor(request.Name);

                foreach (var areaId in request.AreasIds)
                {
                    var area = await _distributorRepository.FindAreaById(areaId);

                    if (area == null)
                    {
                        throw new AreaNotFoundException(areaId);
                    }
                    distributor.AddArea(area);
                }

                _distributorRepository.Add(distributor);

                await _distributorRepository.UnitOfWork.SaveEntitiesAsync();

                return(distributor.Id.ToString());
            }