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()); }
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()); }