コード例 #1
0
        public override async Task <Result> Handle(NewPriceType command, CancellationToken cancellationToken)
        {
            var titleResult = Title.New(command.Title);

            if (titleResult.Failed)
            {
                return(titleResult);
            }

            var title = titleResult.Value;

            var priceTypeResult = PriceType.New(title, _policy);

            if (priceTypeResult.Failed)
            {
                return(priceTypeResult);
            }

            var priceType = priceTypeResult.Value;

            _uow.Set <PriceType>().Add(priceType);

            await _uow.SaveChangesAsync(cancellationToken);

            await _bus.PublishAsync(priceType);

            return(Ok());
        }
コード例 #2
0
        public async Task <Result> Handle(CreatePriceTypeCommand command, CancellationToken cancellationToken)
        {
            var titleResult = Title.New(command.Title);

            if (titleResult.Failed)
            {
                return(titleResult);
            }

            var title = titleResult.Value;

            var priceTypeResult = PriceType.New(title, _policy);

            if (priceTypeResult.Failed)
            {
                return(priceTypeResult);
            }

            var priceType = priceTypeResult.Value;
            await _repository.AddAsync(priceType, cancellationToken);

            await _uow.SaveChangesAsync(cancellationToken);

            await _bus.PublishAsync(priceType);

            return(Ok());
        }