/// <summary> /// Prepare paged affiliate list model /// </summary> /// <param name="searchModel">Affiliate search model</param> /// <returns>Affiliate list model</returns> public virtual async Task <AffiliateListModel> PrepareAffiliateListModelAsync(AffiliateSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //get affiliates var affiliates = await _affiliateService.GetAllAffiliatesAsync(searchModel.SearchFriendlyUrlName, searchModel.SearchFirstName, searchModel.SearchLastName, searchModel.LoadOnlyWithOrders, searchModel.OrdersCreatedFromUtc, searchModel.OrdersCreatedToUtc, searchModel.Page - 1, searchModel.PageSize, true); //prepare list model var model = await new AffiliateListModel().PrepareToGridAsync(searchModel, affiliates, () => { //fill in model values from the entity return(affiliates.SelectAwait(async affiliate => { var address = await _addressService.GetAddressByIdAsync(affiliate.AddressId); var affiliateModel = affiliate.ToModel <AffiliateModel>(); affiliateModel.Address = address.ToModel <AddressModel>(); affiliateModel.Address.CountryName = (await _countryService.GetCountryByAddressAsync(address))?.Name; affiliateModel.Address.StateProvinceName = (await _stateProvinceService.GetStateProvinceByAddressAsync(address))?.Name; return affiliateModel; })); }); return(model); }
public async Task CanGetAllAffiliates() { var affiliates = await _affiliateService.GetAllAffiliatesAsync(); affiliates.TotalCount.Should().Be(2); affiliates = await _affiliateService.GetAllAffiliatesAsync(showHidden : true); affiliates.TotalCount.Should().Be(3); affiliates = await _affiliateService.GetAllAffiliatesAsync(_activeDeletedAffiliate.FriendlyUrlName); affiliates.TotalCount.Should().Be(0); affiliates = await _affiliateService.GetAllAffiliatesAsync(_activeAffiliate1.FriendlyUrlName, showHidden : true); affiliates.TotalCount.Should().Be(1); var address = await _addressService.GetAddressByIdAsync(1); affiliates = await _affiliateService.GetAllAffiliatesAsync(firstName : address.FirstName, showHidden : true); affiliates.TotalCount.Should().Be(3); affiliates = await _affiliateService.GetAllAffiliatesAsync(firstName : address.FirstName); affiliates.TotalCount.Should().Be(2); affiliates = await _affiliateService.GetAllAffiliatesAsync(loadOnlyWithOrders : true, showHidden : true); affiliates.TotalCount.Should().Be(0); }