QrRapido/Views/Shared/_AdSpace.cshtml
Ricardo Carneiro 8b3da7cb0a
All checks were successful
Deploy QR Rapido / test (push) Successful in 3m59s
Deploy QR Rapido / build-and-push (push) Successful in 12m31s
Deploy QR Rapido / deploy-staging (push) Has been skipped
Deploy QR Rapido / deploy-production (push) Successful in 2m17s
feat: Criação de tutoriais e remoçaõ de anuncios.
2025-10-18 23:18:12 -03:00

166 lines
6.1 KiB
Plaintext

@using QRRapidoApp.Services
@using QRRapidoApp.Services.Ads
@using QRRapidoApp.Models.Ads
@using Microsoft.Extensions.Localization
@using System.Globalization
@model dynamic
@inject AdDisplayService AdService
@inject IAdSlotConfigurationProvider SlotProvider
@inject IStringLocalizer<QRRapidoApp.Resources.SharedResource> Localizer
@{
var userId = User?.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier)?.Value;
var showAds = await AdService.ShouldShowAds(userId);
var rawPosition = (ViewBag.position ?? Model?.position ?? "header")?.ToString()?.ToLowerInvariant();
var position = string.IsNullOrWhiteSpace(rawPosition) ? "header" : rawPosition;
var currentCulture = CultureInfo.CurrentUICulture?.Name;
var slotConfig = SlotProvider.GetSlot(position, currentCulture);
var adSenseClientId = ViewBag.AdSenseTag as string;
var adSenseEnabled = ViewBag.AdSenseEnabled is bool enabled && enabled;
var defaultAdSenseSlot = position switch
{
"header" => "QR19750801",
"sidebar" => "QR19750802",
"footer" => "QR19750803",
"content" => "QR19750804",
_ => "QR19750801"
};
var adSenseSlot = slotConfig.AdSenseSlotId ?? defaultAdSenseSlot;
var isAffiliateProvider = string.Equals(slotConfig.Provider, "Affiliate", StringComparison.OrdinalIgnoreCase);
var affiliateContent = isAffiliateProvider ? slotConfig.Affiliate : null;
var containerCss = position switch
{
"header" => "ad-container ad-header mb-4",
"sidebar" => "ad-container ad-sidebar mb-4",
"footer" => "ad-container ad-footer mt-5 mb-4",
"content" => "ad-container ad-content my-4",
_ => "ad-container mb-4"
};
var shouldRenderAdSense = !isAffiliateProvider && adSenseEnabled && !string.IsNullOrWhiteSpace(adSenseClientId);
var shouldRenderAffiliate = isAffiliateProvider && affiliateContent != null && !affiliateContent.IsEmpty();
var renderedAdSense = false;
}
@if (showAds)
{
switch (position)
{
case "header":
if (shouldRenderAffiliate)
{
@await Html.PartialAsync("_AffiliateAd", new AffiliateAdViewModel
{
SlotKey = position,
ContainerCssClass = containerCss,
Content = affiliateContent!
})
}
else if (shouldRenderAdSense)
{
<!-- Placeholder for Adsterra ad - 728x90 Banner -->
<div class="@containerCss" style="display: none;">
<!-- Adsterra code will go here when approved -->
</div>
}
break;
case "sidebar":
if (shouldRenderAffiliate)
{
@await Html.PartialAsync("_AffiliateAd", new AffiliateAdViewModel
{
SlotKey = position,
ContainerCssClass = containerCss,
Content = affiliateContent!
})
}
else if (shouldRenderAdSense)
{
<!-- Placeholder for Adsterra ad - 300x250 Rectangle -->
<div class="@containerCss" style="display: none;">
<!-- Adsterra code will go here when approved -->
</div>
}
break;
case "footer":
if (shouldRenderAffiliate)
{
@await Html.PartialAsync("_AffiliateAd", new AffiliateAdViewModel
{
SlotKey = position,
ContainerCssClass = containerCss,
Content = affiliateContent!
})
}
else if (shouldRenderAdSense)
{
<!-- Placeholder for Adsterra ad - 728x90 Banner -->
<div class="@containerCss" style="display: none;">
<!-- Adsterra code will go here when approved -->
</div>
}
break;
case "content":
if (shouldRenderAffiliate)
{
@await Html.PartialAsync("_AffiliateAd", new AffiliateAdViewModel
{
SlotKey = position,
ContainerCssClass = containerCss,
Content = affiliateContent!
})
}
else if (shouldRenderAdSense)
{
<!-- Placeholder for Adsterra ad - Responsive -->
<div class="@containerCss" style="display: none;">
<!-- Adsterra code will go here when approved -->
</div>
}
break;
default:
if (shouldRenderAffiliate)
{
@await Html.PartialAsync("_AffiliateAd", new AffiliateAdViewModel
{
SlotKey = position,
ContainerCssClass = containerCss,
Content = affiliateContent!
})
}
else if (shouldRenderAdSense)
{
<!-- Placeholder for Adsterra ad - 728x90 Banner -->
<div class="@containerCss" style="display: none;">
<!-- Adsterra code will go here when approved -->
</div>
}
break;
}
@* AdSense lazy-load script removed - will be replaced with Adsterra when approved *@
}
else if (User.Identity.IsAuthenticated)
{
var isPremium = await AdService.HasValidPremiumSubscription(userId);
if (isPremium)
{
<div class="alert alert-success ad-free-notice mb-3">
<i class="fas fa-crown text-warning"></i>
<span><strong>@Localizer["PremiumUserNoAds"]</strong></span>
</div>
}
else
{
<div class="alert alert-info upgrade-notice mb-3">
<i class="fas fa-star text-warning"></i>
<span><strong>@Localizer["UpgradePremiumRemoveAds"]</strong></span>
<a href="/Pagamento/SelecaoPlano" class="btn btn-sm btn-warning ms-2">
<i class="fas fa-crown"></i> @Localizer["PremiumBenefitsShort"]
</a>
</div>
}
}