public virtual async Task <IActionResult> Edit(int id)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageAffiliates))
            {
                return(AccessDeniedView());
            }

            //try to get an affiliate with the specified id
            var affiliate = await _affiliateService.GetAffiliateByIdAsync(id);

            if (affiliate == null || affiliate.Deleted)
            {
                return(RedirectToAction("List"));
            }

            //prepare model
            var model = await _affiliateModelFactory.PrepareAffiliateModelAsync(null, affiliate);

            return(View(model));
        }
예제 #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);
                }
            }