Esempio n. 1
0
        public async Task CanGetAffiliateByFriendlyUrlName()
        {
            var affiliate = await _affiliateService.GetAffiliateByFriendlyUrlNameAsync(_activeAffiliate1.FriendlyUrlName);

            affiliate.Should().NotBeNull();
            affiliate.Active.Should().BeTrue();
            affiliate.FriendlyUrlName.Should().Be(_activeAffiliate1.FriendlyUrlName);
        }
Esempio n. 2
0
            /// <summary>
            /// Called asynchronously before the action, after model binding is complete.
            /// </summary>
            /// <param name="context">A context for action filters</param>
            /// <returns>A task that on completion indicates the necessary filter actions have been executed</returns>
            private async Task CheckAffiliateAsync(ActionExecutingContext context)
            {
                if (context == null)
                {
                    throw new ArgumentNullException(nameof(context));
                }

                //check request query parameters
                var request = context.HttpContext.Request;

                if (request?.Query == null || !request.Query.Any())
                {
                    return;
                }

                if (!await DataSettingsManager.IsDatabaseInstalledAsync())
                {
                    return;
                }

                //try to find by ID
                var customer = await _workContext.GetCurrentCustomerAsync();

                var affiliateIds = request.Query[AFFILIATE_ID_QUERY_PARAMETER_NAME];

                if (int.TryParse(affiliateIds.FirstOrDefault(), out var affiliateId) && affiliateId > 0 && affiliateId != customer.AffiliateId)
                {
                    var affiliate = await _affiliateService.GetAffiliateByIdAsync(affiliateId);
                    await SetCustomerAffiliateIdAsync(affiliate, customer);

                    return;
                }

                //try to find by friendly name
                var affiliateNames = request.Query[AFFILIATE_FRIENDLYURLNAME_QUERY_PARAMETER_NAME];
                var affiliateName  = affiliateNames.FirstOrDefault();

                if (!string.IsNullOrEmpty(affiliateName))
                {
                    var affiliate = await _affiliateService.GetAffiliateByFriendlyUrlNameAsync(affiliateName);
                    await SetCustomerAffiliateIdAsync(affiliate, customer);
                }
            }