Exemplo n.º 1
0
        public async Task <Result <Void> > HandleAsync(EditBucketCommand command, CancellationToken cancellationToken = default)
        {
            Assert.IsNotNull(command, nameof(command));
            cancellationToken.ThrowIfCancellationRequested();

            var userId       = _userContext.UserId;
            var bucketDomain = await _bucketRepository.GetAsync(p => p.Id == command.Id && p.UserId == userId, cancellationToken);

            if (bucketDomain is null)
            {
                return(this.NotFound("Bucket not found."));
            }

            if (command.CurrencyId.HasValue &&
                command.CurrencyId != bucketDomain.CurrencyId)
            {
                if (await _currencyReadOnlyRepository.ExistAsync(command.CurrencyId.Value, cancellationToken) == false)
                {
                    return(this.NotFound("Currency not found."));
                }

                bucketDomain.CurrencyId = command.CurrencyId.Value;
            }

            bucketDomain.PictureId = command.PictureId ?? bucketDomain.PictureId;
            bucketDomain.Title     = command.Title ?? bucketDomain.Title;

            await _bucketRepository.UpdateAsync(bucketDomain, cancellationToken);

            return(this.Ok());
        }
Exemplo n.º 2
0
        public async Task <Result <int> > HandleAsync(CreateWalletCommand command, CancellationToken cancellationToken = default)
        {
            Assert.IsNotNull(command, nameof(command));
            cancellationToken.ThrowIfCancellationRequested();

            if (await _currencyRepository.ExistAsync(command.CurrencyId, cancellationToken) == false)
            {
                return(this.NotFound("Currency not found."));
            }

            var domainWallet = _walletMapper.Map(command);

            domainWallet.UserId = _userContext.UserId;
            domainWallet        = await _repository.CreateAsync(domainWallet, cancellationToken);

            return(this.Ok(domainWallet.Id));
        }
        public async Task <Result <int> > HandleAsync(CreateBucketCommand command, CancellationToken cancellationToken = default)
        {
            Assert.IsNotNull(command, nameof(command));
            cancellationToken.ThrowIfCancellationRequested();

            if (await _currencyRepository.ExistAsync(command.CurrencyId, cancellationToken) == false)
            {
                return(this.NotFound("Currency not found."));
            }

            var userId = _userContext.UserId;

            var bucketDomain = _mapperDefinition.Map(command);

            bucketDomain.UserId = userId;
            bucketDomain        = await _bucketRepository.CreateAsync(bucketDomain, cancellationToken);

            return(this.Ok(bucketDomain.Id));
        }