public async Task CanGenerateUrl() { var url = await _affiliateService.GenerateUrlAsync(_activeAffiliate1); url.Should().Be($"http://{NopTestsDefaults.HostIpAddress}/?{NopAffiliateDefaults.AffiliateQueryParameter}={_activeAffiliate1.FriendlyUrlName}"); _notActiveDeletedAffiliate.FriendlyUrlName = string.Empty; url = await _affiliateService.GenerateUrlAsync(_notActiveDeletedAffiliate); url.Should().Be($"http://{NopTestsDefaults.HostIpAddress}/?{NopAffiliateDefaults.AffiliateIdQueryParameter}={_notActiveDeletedAffiliate.Id}"); }
/// <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 async Task <AffiliateModel> PrepareAffiliateModelAsync(AffiliateModel model, Affiliate affiliate, bool excludeProperties = false) { //fill in model values from the entity if (affiliate != null) { model ??= affiliate.ToModel <AffiliateModel>(); model.Url = await _affiliateService.GenerateUrlAsync(affiliate); //prepare nested search models await PrepareAffiliatedOrderSearchModelAsync(model.AffiliatedOrderSearchModel, affiliate); PrepareAffiliatedCustomerSearchModel(model.AffiliatedCustomerSearchModel, affiliate); //prepare address model var address = await _addressService.GetAddressByIdAsync(affiliate.AddressId); model.Address = address.ToModel(model.Address); await _baseAdminModelFactory.PrepareAddressModelAsync(model.Address, address); //whether to fill in some of properties if (!excludeProperties) { model.AdminComment = affiliate.AdminComment; model.FriendlyUrlName = affiliate.FriendlyUrlName; model.Active = affiliate.Active; } } else { await _baseAdminModelFactory.PrepareAddressModelAsync(model.Address); } return(model); }
/// <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> /// A task that represents the asynchronous operation /// The task result contains the affiliate model /// </returns> public virtual async Task <AffiliateModel> PrepareAffiliateModelAsync(AffiliateModel model, Affiliate affiliate, bool excludeProperties = false) { //fill in model values from the entity if (affiliate != null) { model ??= affiliate.ToModel <AffiliateModel>(); model.Url = await _affiliateService.GenerateUrlAsync(affiliate); //prepare nested search models await PrepareAffiliatedOrderSearchModelAsync(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; } } //prepare address model var address = await _addressService.GetAddressByIdAsync(affiliate?.AddressId ?? 0); if (!excludeProperties && address != null) { model.Address = address.ToModel(model.Address); } await _addressModelFactory.PrepareAddressModelAsync(model.Address, address); model.Address.FirstNameRequired = true; model.Address.LastNameRequired = true; model.Address.EmailRequired = true; model.Address.CountryRequired = true; model.Address.CountyRequired = true; model.Address.CityRequired = true; model.Address.StreetAddressRequired = true; model.Address.ZipPostalCodeRequired = true; model.Address.PhoneRequired = true; return(model); }