예제 #1
0
        /// <summary>
        /// Prepare affiliate model
        /// </summary>
        /// <param name="model">Affiliate model</param>
        /// <param name="affiliate">Affiliate</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Affiliate model</returns>
        public virtual AffiliateModel PrepareAffiliateModel(AffiliateModel model, Affiliate affiliate, bool excludeProperties = false)
        {
            //fill in model values from the entity
            if (affiliate != null)
            {
                model     = model ?? affiliate.ToModel <AffiliateModel>();
                model.Url = affiliate.GenerateUrl(_webHelper);

                //prepare nested search models
                PrepareAffiliatedOrderSearchModel(model.AffiliatedOrderSearchModel, affiliate);
                PrepareAffiliatedCustomerSearchModel(model.AffiliatedCustomerSearchModel, affiliate);

                //whether to fill in some of properties
                if (!excludeProperties)
                {
                    model.AdminComment    = affiliate.AdminComment;
                    model.FriendlyUrlName = affiliate.FriendlyUrlName;
                    model.Active          = affiliate.Active;
                    model.Address         = affiliate.Address.ToModel(model.Address);
                }
            }

            //prepare address model
            PrepareAddressModel(model.Address, affiliate?.Address);

            return(model);
        }
예제 #2
0
        public void GenerateUrl_NullFriendlyUrlName_UseId()
        {
            var       id        = "id";
            Affiliate affiliate = new Affiliate()
            {
                Id = id
            };

            Assert.AreEqual(string.Format(_webHelperFakeFormat, "affiliateid", id), affiliate.GenerateUrl(_webHelperMock.Object));
            _webHelperMock.Verify(c => c.ModifyQueryString(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Once);
        }
예제 #3
0
        public void GenerateUrl_NullFriendlyUrlName_UseId()
        {
            var       id        = "id";
            Affiliate affiliate = new Affiliate()
            {
                Id = id
            };

            _workContextMock.Setup(c => c.CurrentStore).Returns(new Domain.Stores.Store()
            {
                Url = _fakeStoreUrl
            });
            Assert.AreEqual(string.Format(_expectedFormat, "affiliateid", id), affiliate.GenerateUrl(_workContextMock.Object));
            //_webHelperMock.Verify(c => c.ModifyQueryString(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Once);
        }
예제 #4
0
        public virtual void PrepareAffiliateModel(AffiliateModel model, Affiliate affiliate, bool excludeProperties,
                                                  bool prepareEntireAddressModel = true)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            if (affiliate != null)
            {
                model.Id  = affiliate.Id;
                model.Url = affiliate.GenerateUrl(_webHelper);
                if (!excludeProperties)
                {
                    model.AdminComment    = affiliate.AdminComment;
                    model.FriendlyUrlName = affiliate.FriendlyUrlName;
                    model.Active          = affiliate.Active;
                    model.Address         = affiliate.Address.ToModel();
                }
            }

            if (prepareEntireAddressModel)
            {
                model.Address.FirstNameEnabled      = true;
                model.Address.FirstNameRequired     = true;
                model.Address.LastNameEnabled       = true;
                model.Address.LastNameRequired      = true;
                model.Address.EmailEnabled          = true;
                model.Address.EmailRequired         = true;
                model.Address.CompanyEnabled        = true;
                model.Address.CountryEnabled        = true;
                model.Address.StateProvinceEnabled  = true;
                model.Address.CityEnabled           = true;
                model.Address.CityRequired          = true;
                model.Address.StreetAddressEnabled  = true;
                model.Address.StreetAddressRequired = true;
                model.Address.StreetAddress2Enabled = true;
                model.Address.ZipPostalCodeEnabled  = true;
                model.Address.ZipPostalCodeRequired = true;
                model.Address.PhoneEnabled          = true;
                model.Address.PhoneRequired         = true;
                model.Address.FaxEnabled            = true;

                //address
                model.Address.AvailableCountries.Add(new SelectListItem {
                    Text = _localizationService.GetResource("Admin.Address.SelectCountry"), Value = ""
                });
                foreach (var c in _countryService.GetAllCountries(showHidden: true))
                {
                    model.Address.AvailableCountries.Add(new SelectListItem {
                        Text = c.Name, Value = c.Id.ToString(), Selected = (affiliate != null && c.Id == affiliate.Address.CountryId)
                    });
                }

                var states = !String.IsNullOrEmpty(model.Address.CountryId) ? _stateProvinceService.GetStateProvincesByCountryId(model.Address.CountryId, showHidden: true).ToList() : new List <StateProvince>();
                if (states.Count > 0)
                {
                    foreach (var s in states)
                    {
                        model.Address.AvailableStates.Add(new SelectListItem {
                            Text = s.Name, Value = s.Id.ToString(), Selected = (affiliate != null && s.Id == affiliate.Address.StateProvinceId)
                        });
                    }
                }
                else
                {
                    model.Address.AvailableStates.Add(new SelectListItem {
                        Text = _localizationService.GetResource("Admin.Address.OtherNonUS"), Value = ""
                    });
                }
            }
        }
        protected virtual void PrepareAffiliateModel(AffiliateModel model, Affiliate affiliate, bool excludeProperties,
                                                     bool prepareEntireAddressModel, bool prepareOrderListModel)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            if (affiliate != null)
            {
                model.Id  = affiliate.Id;
                model.Url = affiliate.GenerateUrl(_webHelper);
                if (!excludeProperties)
                {
                    model.AdminComment    = affiliate.AdminComment;
                    model.FriendlyUrlName = affiliate.FriendlyUrlName;
                    model.Active          = affiliate.Active;
                    model.Address         = affiliate.Address.ToModel();
                }
            }

            if (prepareEntireAddressModel)
            {
                model.Address.FirstNameEnabled      = true;
                model.Address.FirstNameRequired     = true;
                model.Address.LastNameEnabled       = true;
                model.Address.LastNameRequired      = true;
                model.Address.EmailEnabled          = true;
                model.Address.EmailRequired         = true;
                model.Address.CompanyEnabled        = true;
                model.Address.CountryEnabled        = true;
                model.Address.CountryRequired       = true;
                model.Address.StateProvinceEnabled  = true;
                model.Address.CityEnabled           = true;
                model.Address.CityRequired          = true;
                model.Address.StreetAddressEnabled  = true;
                model.Address.StreetAddressRequired = true;
                model.Address.StreetAddress2Enabled = true;
                model.Address.ZipPostalCodeEnabled  = true;
                model.Address.ZipPostalCodeRequired = true;
                model.Address.PhoneEnabled          = true;
                model.Address.PhoneRequired         = true;
                model.Address.FaxEnabled            = true;

                //address
                model.Address.AvailableCountries.Add(new SelectListItem {
                    Text = _localizationService.GetResource("Admin.Address.SelectCountry"), Value = "0"
                });
                foreach (var c in _countryService.GetAllCountries(showHidden: true))
                {
                    model.Address.AvailableCountries.Add(new SelectListItem {
                        Text = c.Name, Value = c.Id.ToString(), Selected = (affiliate != null && c.Id == affiliate.Address.CountryId)
                    });
                }

                var states = model.Address.CountryId.HasValue ? _stateProvinceService.GetStateProvincesByCountryId(model.Address.CountryId.Value, showHidden: true).ToList() : new List <StateProvince>();
                if (states.Any())
                {
                    foreach (var s in states)
                    {
                        model.Address.AvailableStates.Add(new SelectListItem {
                            Text = s.Name, Value = s.Id.ToString(), Selected = (affiliate != null && s.Id == affiliate.Address.StateProvinceId)
                        });
                    }
                }
                else
                {
                    model.Address.AvailableStates.Add(new SelectListItem {
                        Text = _localizationService.GetResource("Admin.Address.OtherNonUS"), Value = "0"
                    });
                }
            }

            if (!prepareOrderListModel)
            {
                return;
            }

            model.AffiliatedOrderList.AffliateId = model.Id;

            //order statuses
            model.AffiliatedOrderList.AvailableOrderStatuses = OrderStatus.Pending.ToSelectList(false).ToList();
            model.AffiliatedOrderList.AvailableOrderStatuses.Insert(0, new SelectListItem {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = "0"
            });

            //payment statuses
            model.AffiliatedOrderList.AvailablePaymentStatuses = PaymentStatus.Pending.ToSelectList(false).ToList();
            model.AffiliatedOrderList.AvailablePaymentStatuses.Insert(0, new SelectListItem {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = "0"
            });

            //shipping statuses
            model.AffiliatedOrderList.AvailableShippingStatuses = ShippingStatus.NotYetShipped.ToSelectList(false).ToList();
            model.AffiliatedOrderList.AvailableShippingStatuses.Insert(0, new SelectListItem {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = "0"
            });
        }
예제 #6
0
        public void GenerateUrl_NullWebHelper_ThrowException()
        {
            Affiliate affiliate = new Affiliate();

            Assert.ThrowsException <ArgumentNullException>(() => affiliate.GenerateUrl(null), "webHelper");
        }
예제 #7
0
        public void GenerateUrl_NullAffiliate_ThrowException()
        {
            Affiliate affiliate = null;

            Assert.ThrowsException <ArgumentNullException>(() => affiliate.GenerateUrl(null), "affiliate");
        }
예제 #8
0
        public void GenerateUrl_ValideParameters()
        {
            var       friendlyUrl = "friendlyurl";
            Affiliate affiliate   = new Affiliate()
            {
                FriendlyUrlName = friendlyUrl
            };

            Assert.AreEqual(string.Format(_webHelperFakeFormat, "affiliate", friendlyUrl), affiliate.GenerateUrl(_webHelperMock.Object));
            _webHelperMock.Verify(c => c.ModifyQueryString(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Once);
        }
        public virtual async Task PrepareAffiliateModel(AffiliateModel model, Affiliate affiliate, bool excludeProperties,
                                                        bool prepareEntireAddressModel = true)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            if (affiliate != null)
            {
                model.Id   = affiliate.Id;
                model.Name = affiliate.Name;
                model.Url  = affiliate.GenerateUrl(_workContext);
                if (!excludeProperties)
                {
                    model.AdminComment    = affiliate.AdminComment;
                    model.FriendlyUrlName = string.IsNullOrEmpty(affiliate.FriendlyUrlName) ? "" : affiliate.FriendlyUrlName.ToLowerInvariant();
                    model.Active          = affiliate.Active;
                    model.Address         = await affiliate.Address.ToModel(_countryService);
                }
            }

            if (prepareEntireAddressModel)
            {
                model.Address.FirstNameEnabled      = true;
                model.Address.FirstNameRequired     = true;
                model.Address.LastNameEnabled       = true;
                model.Address.LastNameRequired      = true;
                model.Address.EmailEnabled          = true;
                model.Address.EmailRequired         = true;
                model.Address.CompanyEnabled        = true;
                model.Address.CountryEnabled        = true;
                model.Address.StateProvinceEnabled  = true;
                model.Address.CityEnabled           = true;
                model.Address.CityRequired          = true;
                model.Address.StreetAddressEnabled  = true;
                model.Address.StreetAddressRequired = true;
                model.Address.StreetAddress2Enabled = true;
                model.Address.ZipPostalCodeEnabled  = true;
                model.Address.ZipPostalCodeRequired = true;
                model.Address.PhoneEnabled          = true;
                model.Address.PhoneRequired         = true;
                model.Address.FaxEnabled            = true;

                //address
                model.Address.AvailableCountries.Add(new SelectListItem {
                    Text = _translationService.GetResource("Admin.Address.SelectCountry"), Value = ""
                });
                foreach (var c in await _countryService.GetAllCountries(showHidden: true))
                {
                    model.Address.AvailableCountries.Add(new SelectListItem {
                        Text = c.Name, Value = c.Id.ToString(), Selected = (affiliate != null && c.Id == affiliate.Address.CountryId)
                    });
                }

                var states = !String.IsNullOrEmpty(model.Address.CountryId) ? (await _countryService.GetCountryById(model.Address.CountryId))?.StateProvinces : new List <StateProvince>();
                if (states.Count > 0)
                {
                    foreach (var s in states)
                    {
                        model.Address.AvailableStates.Add(new SelectListItem {
                            Text = s.Name, Value = s.Id.ToString(), Selected = (affiliate != null && s.Id == affiliate.Address.StateProvinceId)
                        });
                    }
                }
            }
        }
예제 #10
0
        public void GenerateUrl_ValideParameters()
        {
            var       friendlyUrl = "friendlyurl";
            Affiliate affiliate   = new Affiliate()
            {
                FriendlyUrlName = friendlyUrl
            };

            _workContextMock.Setup(c => c.CurrentStore).Returns(new Domain.Stores.Store()
            {
                Url = _fakeStoreUrl
            });
            Assert.AreEqual(string.Format(_expectedFormat, "affiliate", friendlyUrl), affiliate.GenerateUrl(_workContextMock.Object));
        }