Beispiel #1
0
        public async Task <IdentityResult> CreateUserAsync(UserCreationDto userCreationDto)
        {
            var user           = Mapper.Map <User>(userCreationDto);
            var identityResult = await _userManager.CreateAsync(user, userCreationDto.Password);

            if (!identityResult.Errors.Any())
            {
                _eventsManager.EnqueueEvent(new UserRegisteredEvent
                {
                    Username = user.Name,
                    Email    = user.Email,
                    Password = userCreationDto.Password,
                    Token    = await _userManager.GenerateEmailConfirmationTokenAsync(user)
                });
            }

            return(identityResult);
        }
        public async Task CreateOrderAsync(OrderCreationDto orderCreationDto)
        {
            var order = Mapper.Map <Order>(orderCreationDto);

            foreach (var dishId in orderCreationDto.Dishes)
            {
                var dish = await _dishesRepository.GetByIdAsync(dishId);

                order.Dishes.Add(new OrderDish {
                    Dish = dish
                });
            }
            await _ordersRepository.AddAsync(order);

            await UnitOfWork.CommitAsync();

            _eventsManager.EnqueueEvent(new OrderCreatedEvent());
        }