Example #1
0
        public void Can_check_taxExempt_customer_in_taxExemptCustomerRole()
        {
            var customer = new Customer
            {
                Id          = 1,
                IsTaxExempt = false
            };

            _taxService.IsTaxExempt(null, customer).Should().BeFalse();

            var customerRole = _customerRoleRepo.Table.FirstOrDefault(cr => cr.Id == 1);

            customerRole.Should().NotBeNull();

            _customerService.AddCustomerRoleMapping(new CustomerCustomerRoleMapping {
                CustomerId = customer.Id, CustomerRoleId = customerRole.Id
            });

            _taxService.IsTaxExempt(null, customer).Should().BeTrue();

            customerRole.TaxExempt = false;
            _taxService.IsTaxExempt(null, customer).Should().BeFalse();

            //if role is not active, we should ignore 'TaxExempt' property
            customerRole.Active = false;
            _taxService.IsTaxExempt(null, customer).Should().BeFalse();
        }
        private void AddValidRoles(Delta <CustomerDto> customerDelta, Customer currentCustomer)
        {
            var allCustomerRoles = CustomerService.GetAllCustomerRoles(true);

            foreach (var customerRole in allCustomerRoles)
            {
                if (customerDelta.Dto.RoleIds.Contains(customerRole.Id))
                {
                    //new role
                    if (!CustomerService.IsInCustomerRole(currentCustomer, customerRole.SystemName))
                    {
                        CustomerService.AddCustomerRoleMapping(new CustomerCustomerRoleMapping()
                        {
                            CustomerId     = currentCustomer.Id,
                            CustomerRoleId = customerRole.Id
                        });
                    }
                }
                else
                {
                    if (CustomerService.IsInCustomerRole(currentCustomer, customerRole.SystemName))
                    {
                        CustomerService.RemoveCustomerRoleMapping(currentCustomer, customerRole);
                    }
                }
            }
        }