Beispiel #1
0
        public async Task <bool> Handle(DeleteCityComamnd request, CancellationToken cancellationToken)
        {
            #if NET5_0_OR_GREATER
            await using var unitOfWork = _unitOfWorkFactory.Create();
            #else
            using var unitOfWork = _unitOfWorkFactory.Create();
            #endif

            await unitOfWork.Delete(request.Id, cancellationToken);

            await unitOfWork.Commit(cancellationToken);

            return(true);
        }
        public async Task <CityViewModel> Handle(EditCityCommand request, CancellationToken cancellationToken)
        {
            var city = _mapper.Map <City>(request.Model);

            #if NET5_0
            await using var unitOfWork = _unitOfWorkFactory.Create();
            #else
            using var unitOfWork = _unitOfWorkFactory.Create();
            #endif

            await unitOfWork.Update(city, cancellationToken);

            await unitOfWork.Commit(cancellationToken);

            return(_mapper.Map <CityViewModel>(city));
        }
Beispiel #3
0
        public async Task <CreateResultViewModel <City> > Handle(CreateCityCommand request, CancellationToken cancellationToken)
        {
            var city = _mapper.Map <City>(request.Model);

            #if NET5_0_OR_GREATER
            await using var unitOfWork = _unitOfWorkFactory.Create();
            #else
            using var unitOfWork = _unitOfWorkFactory.Create();
            #endif
            City newCity = await unitOfWork.Add(city, cancellationToken);

            // ConfigureAwait is necessary here because of possible mix of async/await and task.Wait/task.Result
            // without the configure await it would expect to return to this thread and potentially deadlock if
            // another task was using the original thread (and worse yet if that thread was waiting on the this
            // await to complete
            await unitOfWork.Commit(cancellationToken).ConfigureAwait(false);

            return(new CreateResultViewModel <City>(newCity.Id));
        }