public Discount CalculateDiscount(string tenantId, string offerId, DateTime from, DateTime to)
        {
            var customerId = CustomerId.From(tenantId);
            var customer   = _customerRepository.Get(customerId);
            var discount   = _discountCalculationService.Calculate(customer);

            return(Discount.From(discount.ToInt()));
        }
Exemple #2
0
        public void CreateOrder(CreateOrderRequest request)
        {
            var command = new CreateOrderCommand(CustomerId.From(request.CustomerId));

            _commandDispatcher.Dispatch(command);
            foreach (var orderItem in request.OrderItems)
            {
                _commandDispatcher.Dispatch(new AddItemToOrderCommand(command.OrderIdCreated, ProductId.From(orderItem.ProductId), orderItem.Quantity));
            }
        }
Exemple #3
0
        public CustomerDetails GetCustomerDetails(Guid customerId)
        {
            var details = _customerFinder.GetDetails(CustomerId.From(customerId));

            return(new CustomerDetails
            {
                Id = details.Id,
                FirstName = details.FirstName,
                LastName = details.LastName,
                BirthDate = details.BirthDate,
                Email = details.Email,
            });
        }
Exemple #4
0
        public async Task <Customer> GetByIdAsync(CustomerId customerId)
        {
            CustomerEntity entity = await GetEntityById(customerId);

            if (entity is null)
            {
                return(null);
            }

            return(Customer.Rehydrate
                   (
                       CustomerId.From(entity.Id),
                       entity.Gender,
                       Name.From(entity.Firstname),
                       Name.From(entity.Lastname),
                       Birthdate.From(entity.Birthdate),
                       entity.Comment
                   ));
        }
Exemple #5
0
 public void DeleteCustomer(Guid id)
 {
     _commandDispatcher.Dispatch(new DeleteCustomerCommand(CustomerId.From(id)));
 }
Exemple #6
0
 public void UpdateCustomerDetails(CustomerDetails customerDetails)
 {
     _commandDispatcher.Dispatch(new UpdateCustomerCommand(CustomerId.From(customerDetails.Id), customerDetails.FirstName, customerDetails.LastName, customerDetails.BirthDate, customerDetails.Email));
 }
        public void Choose_Should_Return_Draft()
        {
            using (var mock = AutoMock.GetLoose())
            {
                var tenantIdString  = Guid.NewGuid().ToString();
                var offerRepository = new InMemoryOfferRepository();
                mock.Provide <IOfferRepository>(offerRepository);
                var draftRepository = new InMemoryDraftRepository();
                mock.Provide <IDraftRepository>(draftRepository);
                mock.Mock <ICustomerRepository>().Setup(_ => _.Get(It.IsAny <CustomerId>())).Returns(new Customer(CustomerId.From(tenantIdString), 1));
                var discountCalculationService = new DiscountCalculationService();
                var discountService            = new DiscountService(mock.Create <ICustomerRepository>(), discountCalculationService);
                mock.Provide <IDiscountService>(discountService);
                var sut     = mock.Create <OfferService>();
                var offerId = CreateSampleOffer(mock);

                var draftId = sut.Choose(offerId.ToString(), tenantIdString, DateTime.Now.AddDays(-10), DateTime.Now.AddDays(10));

                var draft = draftRepository.Get(draftId);
                draft.Should().NotBeNull();
                draft.Id.Should().BeEquivalentTo(draftId);
            }
        }