コード例 #1
0
        public async Task SetUp()
        {
            _affiliateService = GetService <IAffiliateService>();
            _addressService   = GetService <IAddressService>();
            _activeAffiliate1 = new Affiliate
            {
                Active          = true,
                AddressId       = 1,
                AdminComment    = "Test admin comment",
                FriendlyUrlName = "TestActiveAffiliate1"
            };
            _activeAffiliate2 = new Affiliate
            {
                Active          = true,
                AddressId       = 1,
                AdminComment    = "Test admin comment",
                FriendlyUrlName = "TestActiveAffiliate2"
            };
            _notActiveAffiliate = new Affiliate
            {
                Active          = false,
                AddressId       = 1,
                AdminComment    = "Test admin comment",
                FriendlyUrlName = "TestNotActiveAffiliate"
            };
            _activeDeletedAffiliate = new Affiliate
            {
                Active          = true,
                AddressId       = 1,
                AdminComment    = "Test admin comment",
                FriendlyUrlName = "TestActiveDeletedAffiliate",
                Deleted         = true
            };
            _notActiveDeletedAffiliate = new Affiliate
            {
                Active          = false,
                AddressId       = 1,
                AdminComment    = "Test admin comment",
                FriendlyUrlName = "TestNotActiveDeletedAffiliate",
                Deleted         = true
            };

            await _affiliateService.InsertAffiliateAsync(_activeAffiliate1);

            await _affiliateService.InsertAffiliateAsync(_notActiveAffiliate);

            await _affiliateService.InsertAffiliateAsync(_activeDeletedAffiliate);

            await _affiliateService.InsertAffiliateAsync(_notActiveDeletedAffiliate);
        }
コード例 #2
0
        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));
        }