コード例 #1
0
        public async Task HandleAsync(CreateProduct command, ICorrelationContext context)
        {
            Console.WriteLine($"Create product {command.Name}");
            await _productRepository.AddAsync(new Product(command.Id, command.Name, command.Category, command.Price));

            await _busPublisher.PublishEventAsync(new ProductCreated(command.Id, command.Name, command.Category, command.Price), context);
        }
コード例 #2
0
 public async Task HandleAsync(ContributionCalculatedEvent @event)
 {
     await _handler.Handle(async() =>
     {
         string number = await _accountService.CreatePolicyAccountAsync(@event);
         await _busPublisher.PublishEventAsync(new PolicyAccountCreatedEvent(@event.PolicyId, number));
     }).ExecuteAsync();
 }
コード例 #3
0
        public async Task HandleAsync(CreatePolicyAccountCommand command)
        {
            await _handler.Handle(async() =>
            {
                System.Console.WriteLine(command);

                await _busPublisher.PublishEventAsync(new PolicyAccountCreatedEvent(command.PolicyId, command.Number));
            })
            .ExecuteAsync();
        }
コード例 #4
0
        public async Task SignUpAsync(Guid id, string email, string password, string role = Role.User)
        {
            var user = await _userRepository.GetAsync(email);

            if (user != null)
            {
                var reason = $"Email: '{email}' is already in use.";
                var code   = Codes.EmailInUse;
                await _busPublisher.PublishEventAsync(new SignUpRejected(user.Id, reason, code),
                                                      new CorrelationContext());

                throw new DShopException(code, reason);
            }
            user = new User(id, email, role);
            user.SetPassword(password, _passwordHasher);
            await _userRepository.CreateAsync(user);

            await _busPublisher.PublishEventAsync(new SignedUp(id, email), new CorrelationContext());
        }
コード例 #5
0
        public async Task HandleAsync(PolicyCreatedEvent @event)
        {
            await _handler.Handle(async() =>
            {
                //todo: calcluate contribution
                decimal value = new System.Random().Next(100, 9999);

                await _busPublisher.PublishEventAsync(new ContributionCalculatedEvent(@event.PolicyId, value));
            }).ExecuteAsync();
        }
コード例 #6
0
        public async Task HandleAsync(SignUpUser command, ICorrelationContext context)
        {
            var user = await _identityService.SignUpAsync(command.Email, command.Password);

            await _busPublisher
            .PublishEventAsync(
                new UserRegistered
            {
                Id    = user.Id,
                Email = command.Email
            }, context);
        }
コード例 #7
0
 public async Task HandleAsync(CreatePolicyCommand command)
 {
     await _handler.Handle(async() =>
     {
         var response = await _policyService.CreatePolicyAsync(command);
         await _busPublisher.PublishEventAsync(new PolicyCreatedEvent(response.PolicyId, command.ProductsCodes));
     })
     .OnError((ex) =>
     {
         throw ex;
     })
     .ExecuteAsync();
 }
コード例 #8
0
        public async Task HandleAsync(CloseBookmakingCommand command)
        {
            var bookMatch = await _bookMatchRepository.FindByUserAndMatchIdsAsync(command.UserId, command.MatchId);

            if (bookMatch == null)
            {
                throw new BrokenBusinessRuleException(new DoesNotExistException());
            }
            bookMatch.Close();

            //TODO: Add Outbox pattern
            await _busPublisher.PublishEventAsync(
                new CloseBookmakingEvent(
                    Guid.NewGuid(),
                    SystemTime.Now(),
                    command.MatchId,
                    command.UserId));
        }
コード例 #9
0
        public async Task HandleAsync(AddFriend command, ICorrelationContext context)
        {
            var model = new UsersFriends()
            {
                FriendId = command.FriendId,
                UserId   = command.UserId
            };

            await _usersFriendsRepository.AddFriend(model);

            await _busPublisher.PublishEventAsync(
                new FriendAdded()
            {
                Id       = command.Id,
                FriendId = command.FriendId,
                UserId   = command.UserId
            }, context);
        }
コード例 #10
0
        public async Task SignUpAsync(Guid id, string email, string password, string role = Role.User)
        {
            var user = await _userRepository.GetAsync(email);

            if (user != null)
            {
                throw new DShopException(Codes.EmailInUse,
                                         $"Email: '{email}' is already in use.");
            }
            if (string.IsNullOrWhiteSpace(role))
            {
                role = Role.User;
            }
            user = new User(id, email, role);
            user.SetPassword(password, _passwordHasher);
            await _userRepository.CreateAsync(user);

            await _busPublisher.PublishEventAsync(new SignedUp(id, email), CorrelationContext.Empty);
        }
コード例 #11
0
 public async Task HandleAsync(AddCity command)
 {
     _logger.LogInformation($"Add city: {command.Name}");
     await _busPublisher.PublishEventAsync(new CityAdded { Name = command.Name });
 }