public async Task Handle(OrderStartedDomainEvent orderStartedEvent, CancellationToken cancellationToken)
        {
            var  cardTypeId             = (orderStartedEvent.CardTypeId != 0) ? orderStartedEvent.CardTypeId : 1;
            var  buyer                  = _buyerRepository.Find(orderStartedEvent.UserId);
            bool buyerOriginallyExisted = (buyer != null);

            if (!buyerOriginallyExisted)
            {
                buyer = new Buyer(orderStartedEvent.UserId, orderStartedEvent.UserName);
            }

            buyer.VerifyOrAddPaymentMethod(cardTypeId,
                                           $"Payment Method on {DateTime.UtcNow}",
                                           orderStartedEvent.CardNumber,
                                           orderStartedEvent.CardSecurityNumber,
                                           orderStartedEvent.CardHolderName,
                                           orderStartedEvent.CardExpiration,
                                           orderStartedEvent.Order.Id);

            var buyerUpdated = buyerOriginallyExisted ?
                               _buyerRepository.Update(buyer) :
                               _buyerRepository.Add(buyer);

            _buyerRepository.UnitOfWork.SaveEntities();

            //Not showing the implementation of this event handler in other aggregate roots
            var statusChangedToSubmittedIntegrationEvent
                = new OrderStatusChangedToSubmittedIntegrationEvent(
                      orderStartedEvent.Order.Id, orderStartedEvent.Order.OrderStatus.Name, buyer.Name);

            _orderingIntegrationEventService.PublishThroughEventBus(statusChangedToSubmittedIntegrationEvent);

            _logger.LogInformation($"Buyer {buyerUpdated.Id} and related payment method were validated or updated for orderId: " +
                                   $"{orderStartedEvent.Order.Id}.");
        }
コード例 #2
0
        public ActionResult GetBuyerInformation(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(UserList());
            }
            var buyer = _buyerRepository.Find(id);

            return(View(buyer));
        }
コード例 #3
0
        public IActionResult Get()
        {
            StringValues hearderValues;
            var          firstValue = string.Empty;

            if (Request.Headers.TryGetValue("id", out hearderValues))
            {
                firstValue = hearderValues.FirstOrDefault();
            }
            long id   = Convert.ToInt64(firstValue);
            var  item = _repository.Find(id);

            if (item == null)
            {
                return(NotFound());
            }


            #region  Interactions List
            // Rate list for the user that he commented for this product
            List <Interaction> InteractionList = new List <Interaction>();
            var InteractionQuery = from interaction in _interactionRepository.GetAll()
                                   where interaction.UserId == item.UserId
                                   select interaction;
            foreach (var interaction in InteractionQuery)
            {
                Interaction UserRate = new Interaction();
                UserRate         = interaction;
                UserRate.Product = null;
                UserRate.User    = null;
                InteractionList.Add(UserRate);
            }
            item.Interactions = InteractionList;
            #endregion

            // Unset variables that are unused
            InteractionList  = null;
            InteractionQuery = null;

            return(new ObjectResult(item));
        }
コード例 #4
0
 public IEnumerable <Buyer> FindByName(string name)
 {
     return(_repository.Find(BuyerQueries.FindByName(name)).ToList());
 }