public async Task <Unit> Handle(RemoveDistributorAreasCommand request, CancellationToken cancellationToken)
            {
                var distributorFromRepo = await _distributorRepository.FindByIdAsync(request.DistributorId);

                if (distributorFromRepo == null)
                {
                    throw new DistributorNotFoundException(request.DistributorId);
                }


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

                    if (area == null)
                    {
                        throw new AreaNotFoundException(areaId);
                    }
                    distributorFromRepo.RemoveArea(area);
                }

                _distributorRepository.Update(distributorFromRepo);

                await _distributorRepository.UnitOfWork.SaveEntitiesSeveralTransactionsAsync(cancellationToken);

                return(Unit.Value);
            }
Пример #2
0
            public async Task <DistributorVM> Handle(DistributorByIdQuery request, CancellationToken cancellationToken)
            {
                var distributorFromRepo = await _distributorsRepository.FindByIdAsync(request.DistributorId);

                if (distributorFromRepo == null)
                {
                    throw new DistributorNotFoundException(request.DistributorId);
                }

                var distributorToReturn = _mapper.Map <DistributorVM>(distributorFromRepo);

                return(distributorToReturn);
            }
            public async Task <Unit> Handle(UpdateDistributorUserCommand request, CancellationToken cancellationToken)
            {
                var distributorFromRepo = await _distributorRepository.FindByIdAsync(request.DistributorId);

                if (distributorFromRepo == null)
                {
                    throw new DistributorNotFoundException(request.DistributorId);
                }


                distributorFromRepo.UpdateDistributorUser(request.DistributorUserId, request.DistributorId);

                _distributorRepository.Update(distributorFromRepo);

                await _distributorRepository.UnitOfWork.SaveEntitiesSeveralTransactionsAsync(cancellationToken);

                return(Unit.Value);
            }
Пример #4
0
            public async Task <Unit> Handle(DeleteDistributorUserCommand request, CancellationToken cancellationToken)
            {
                // get distributor by id
                var distributorFromRepo = await _distributorRepository.FindByIdAsync(request.DistributorId);

                if (distributorFromRepo == null)
                {
                    throw new DistributorNotFoundException(request.DistributorId);
                }

                // delete distributorUser to distributor
                distributorFromRepo.DeleteDistributorUser(request.DistributorUserId);

                // update distributor with the new distributorUser deleted
                _distributorRepository.Update(distributorFromRepo);

                // save changes in the database and rase DistributorUpdated event
                await _distributorRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken);

                return(Unit.Value);
            }
Пример #5
0
            public async Task <string> Handle(CreateDistributorUserCommand request, CancellationToken cancellationToken)
            {
                var distributor = await _distributorRepository.FindByIdAsync(request.DistributorId);

                if (distributor == null)
                {
                    throw new DistributorNotFoundException(request.DistributorId);
                }


                var accountId = await CreateUserAccountAsync(request, distributor.Id.ToString());


                distributor.CreateUser(accountId, request.FullName, request.Email);

                _distributorRepository.Update(distributor);

                await _distributorRepository.UnitOfWork.SaveEntitiesAsync();

                return(accountId);
            }