Exemple #1
0
        public async Task CanValidateFriendlyUrlName()
        {
            var friendlyUrlName = await _affiliateService.ValidateFriendlyUrlNameAsync(_activeAffiliate1, _activeAffiliate2.FriendlyUrlName);

            friendlyUrlName.Should().Be(_activeAffiliate2.FriendlyUrlName.ToLowerInvariant());

            friendlyUrlName = await _affiliateService.ValidateFriendlyUrlNameAsync(_activeAffiliate1, "not/valid/url*name");

            friendlyUrlName.Should().Be("notvalidurlname");
        }
        public virtual async Task <IActionResult> Create(AffiliateModel model, bool continueEditing)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageAffiliates))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var address = model.Address.ToEntity <Address>();

                address.CreatedOnUtc = DateTime.UtcNow;

                //some validation
                if (address.CountryId == 0)
                {
                    address.CountryId = null;
                }
                if (address.StateProvinceId == 0)
                {
                    address.StateProvinceId = null;
                }

                await _addressService.InsertAddressAsync(address);

                var affiliate = model.ToEntity <Affiliate>();

                //validate friendly URL name
                var friendlyUrlName = await _affiliateService.ValidateFriendlyUrlNameAsync(affiliate, model.FriendlyUrlName);

                affiliate.FriendlyUrlName = friendlyUrlName;
                affiliate.AddressId       = address.Id;

                await _affiliateService.InsertAffiliateAsync(affiliate);

                //activity log
                await _customerActivityService.InsertActivityAsync("AddNewAffiliate",
                                                                   string.Format(await _localizationService.GetResourceAsync("ActivityLog.AddNewAffiliate"), affiliate.Id), affiliate);

                _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Affiliates.Added"));

                return(continueEditing ? RedirectToAction("Edit", new { id = affiliate.Id }) : RedirectToAction("List"));
            }

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

            //if we got this far, something failed, redisplay form
            return(View(model));
        }