예제 #1
0
파일: Order.cs 프로젝트: qizl/eShopPractise
        private void AddOrderStartedDomainEvent(string userId, string userName, int cardTypeId, string cardNumber,
                                                string cardSecurityNumber, string cardHolderName, DateTime cardExpiration)
        {
            var orderStartedDomainEvent = new OrderStartedDomainEvent(this, userId, userName, cardTypeId, cardNumber, cardSecurityNumber, cardHolderName, cardExpiration);

            this.AddDomainEvent(orderStartedDomainEvent);
        }
예제 #2
0
        public async Task Handle(OrderStartedDomainEvent notification)
        {
            var guid = _identityService.GetUserIdentity();

            var buyer = await _buyerRepository.FindAsync(guid);

            var buyerOriginallyExisted = (buyer != null);

            if (!buyerOriginallyExisted)
            {
                buyer = new Buyer(guid);
            }

            buyer.VerifyOrAddPaymentMethod(
                notification.CardNumber,
                notification.CardSecurityNumber,
                notification.CardHolder,
                notification.CardExpiration,
                notification.Order.Id);

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

            await _buyerRepository.UnitOfWork.SaveEntitiesAsync();

            _logger.CreateLogger(typeof(ValidateOrAddBuyerOnOrderStartedEventHandler)).LogTrace($"Buyer {buyerUpdated.Id} and related payment method were validated or updated for orderId: {notification.Order.Id}.");
        }
예제 #3
0
        public void Remove_event_Order_explicitly()
        {
            // Arrange
            var street             = "fakeStreet";
            var city               = "FakeCity";
            var state              = "fakeState";
            var country            = "fakeCountry";
            var zipcode            = "FakeZipCode";
            var cardTypeId         = 5;
            var cardNumber         = "12";
            var cardSecurityNumber = "123";
            var cardHolderName     = "FakeName";
            var cardExpiration     = DateTime.Now.AddYears(1);
            var address            = new Address(street, city, state, country, zipcode);
            var order              = new Order("1", "fakeName", address, cardTypeId, cardNumber, cardSecurityNumber, cardHolderName, cardExpiration);
            var @event             = new OrderStartedDomainEvent(order, "1", "fakeName", cardTypeId, cardNumber, cardSecurityNumber, cardHolderName, cardExpiration);
            var expectedResult     = 1;

            // Act
            order.AddDomainEvent(@event);
            order.RemoveDomainEvent(@event);

            // Assert
            Assert.Equal(order.DomainEvents.Count, expectedResult);
        }
예제 #4
0
        private void AddOrderStartedDomainEvent(string cardNumber, string cardHolder, string cardSecurityNumber,
                                                DateTime cardExpiration)
        {
            var orderStartedDomainEvent = new OrderStartedDomainEvent(
                this, cardNumber, cardHolder, cardSecurityNumber, cardExpiration);

            this.AddDomainEvent(orderStartedDomainEvent);
        }
예제 #5
0
        private void AddOrderStartedDomainEvent(CardType cardType, string cardNumber,
                                                string cardSecurityNumber, string cardHolderName, DateTime cardExpiration)
        {
            var orderStartedDomainEvent = new OrderStartedDomainEvent(this, cardType, cardNumber,
                                                                      cardSecurityNumber, cardHolderName, cardExpiration);

            AddDomainEvents(orderStartedDomainEvent);
        }
예제 #6
0
 public void Apply(OrderStartedDomainEvent aggregateEvent)
 {
     //_buyerId = aggregateEvent._buyerId;
     //_paymentMethodId = aggregateEvent.PaymentMethodId;
     _orderStatusId = OrderStatus.Submitted.Id;
     _orderDate     = aggregateEvent.OrderDate;
     Address        = aggregateEvent.Address;
     _orderItems    = aggregateEvent.Items.ToList();
 }
예제 #7
0
        public IExecutionResult Create(string userId, string userName, Address address, int cardTypeId, string cardNumber, string cardSecurityNumber,
                                       string cardHolderName, DateTime cardExpiration, IEnumerable <OrderItem> items, string buyerId = null)
        {
            var itemList = CreateItemList(items);

            var orderStarted = new OrderStartedDomainEvent(DateTime.UtcNow, address, userId, userName, cardTypeId, cardNumber, cardSecurityNumber, cardHolderName, cardExpiration, itemList);

            Emit(orderStarted);
            return(ExecutionResult.Success());
        }
예제 #8
0
        public Order(string userId, string userName, Address address, string buyerId = null, string paymentMethodId = null) : this()
        {
            BuyerId         = buyerId;
            PaymentMethodId = paymentMethodId;
            OrderStatusId   = OrderStatus.Submitted.Id;
            Address         = address;

            var orderStartedDomainEvent = new OrderStartedDomainEvent(this, userId, userName);

            this.AddDomainEvent(orderStartedDomainEvent);
        }
예제 #9
0
        public async Task When(OrderStartedDomainEvent @event)
        {
            var doc = new OrderDocument();

            doc.Address    = @event.Order.Address.ToAddressDocument();
            doc.OrderItems = @event.Order.OrderItems.ToOrderItemDocumenList();
            doc.OrderId    = @event.Order.Id;
            doc.OrderDate  = @event.Order.OrderDate;
            doc.Status     = @event.Order.OrderState.ToString();
            await queryStore.Upsert(doc);
        }
예제 #10
0
        public Order(string userId, string userName, Address address, int cardType, string cardNumber, string cardSecurityNumber,
                     string cardHolderName, DateTime cardExpiration, string currency, decimal currencyRate, int?buyerId = null, int?paymentMethodId = null) : this()
        {
            Address          = address;
            _buyerId         = buyerId;
            _paymentMethodId = paymentMethodId;
            Currency         = currency;
            CurrencyRate     = currencyRate;

            CreatedDate = DateTime.UtcNow;

            // Add the OrderStarterDomainEvent to the domain events collection
            // to be raised/dispatched when comitting changes into the Database [ After DbContext.SaveChanges() ]
            var orderStartedDomainEvent = new OrderStartedDomainEvent(this, userId, userName, cardType,
                                                                      cardNumber, cardSecurityNumber,
                                                                      cardHolderName, cardExpiration);

            this.AddDomainEvent(orderStartedDomainEvent);
        }
예제 #11
0
    // private Order(ILazyLoader lazyLoader, ObjectId id) : this(id)
    // {
    //  _lazyLoader = lazyLoader;
    //  _lazyLoader.Load(this, ref Items);
    // }

    private Order(
        string userId,
        Address address,
        string description
        ) : this(ObjectId.GenerateNewId())
    {
        Address     = address;
        BuyerId     = userId;
        Description = description;


        Status = OrderStatus.Submitted;

        // Add the OrderStarterDomainEvent to the domain events collection
        // to be raised/dispatched when comitting changes into the Database [ After DbContext.SaveChanges() ]
        var orderStartedDomainEvent = new OrderStartedDomainEvent(this, userId);

        AddDomainEvent(orderStartedDomainEvent);
    }
예제 #12
0
        public Order(
            string userId,
            Address address,
            string description,
            List <OrderItem> orderItems
            ) : this()
        {
            Address      = address;
            UserId       = userId;
            Description  = description;
            OrderItems   = orderItems;
            CreationTime = DateTimeOffset.Now;

            // Add the OrderStarterDomainEvent to the domain events collection
            // to be raised/dispatched when comitting changes into the Database [ After DbContext.SaveChanges() ]
            var orderStartedDomainEvent = new OrderStartedDomainEvent(this, userId);

            AddDomainEvent(orderStartedDomainEvent);
        }
예제 #13
0
        public void Remove_event_order_explicitly_raises_new_event()
        {
            //Arrange
            var street         = "fakeStreet";
            var city           = "FakeCity";
            var state          = "fakeState";
            var country        = "fakeCountry";
            var zipcode        = "FakeZipCode";
            var expectedResult = 1;

            //Act
            var fakeOrder = new Order("1", "fakeName",
                                      new Address(street, city, state, country, zipcode));
            var fakeEvent = new OrderStartedDomainEvent(fakeOrder, "fakename", "1");

            fakeOrder.AddDomainEvent(fakeEvent);
            fakeOrder.RemoveDomainEvent(fakeEvent);

            //Assert
            Assert.Equal(fakeOrder.DomainEvents.Count, expectedResult);
        }
예제 #14
0
        private void AddOrderStartedDomainEvent(string userId, string userName)
        {
            var orderStartedDomainEvent = new OrderStartedDomainEvent(this, userId, userName);

            this.AddDomainEvent(orderStartedDomainEvent);
        }
예제 #15
0
        private void AddOrderStartedDomainEvent(string emailAddress)
        {
            var orderStartedDomainEvent = new OrderStartedDomainEvent(emailAddress);

            this.AddDomainEvent(orderStartedDomainEvent);
        }
예제 #16
0
파일: Order.cs 프로젝트: zxbe/LinFx
        public Order(string userId, string userName)
        {
            var orderStartedDomainEvent = new OrderStartedDomainEvent(this, userId, userName);

            AddDomainEvent(orderStartedDomainEvent);
        }