using Microsoft.AspNetCore.Mvc; using QRRapidoApp.Models; using QRRapidoApp.Services; using System.Diagnostics; using System.Security.Claims; using Microsoft.Extensions.Localization; namespace QRRapidoApp.Controllers { public class HomeController : Controller { private readonly ILogger _logger; private readonly AdDisplayService _adDisplayService; private readonly IUserService _userService; private readonly IConfiguration _config; private readonly IStringLocalizer _localizer; public HomeController(ILogger logger, AdDisplayService adDisplayService, IUserService userService, IConfiguration config, IStringLocalizer localizer) { _logger = logger; _adDisplayService = adDisplayService; _userService = userService; _config = config; _localizer = localizer; } public async Task Index() { var userId = User?.FindFirst(ClaimTypes.NameIdentifier)?.Value; ViewBag.ShowAds = await _adDisplayService.ShouldShowAds(userId); ViewBag.IsPremium = await _adDisplayService.HasValidPremiumSubscription(userId ?? ""); ViewBag.IsAuthenticated = User.Identity?.IsAuthenticated ?? false; ViewBag.UserName = User.Identity?.Name ?? ""; _adDisplayService.SetViewBagAds(ViewBag); // SEO and Analytics data ViewBag.Title = _config["App:TaglinePT"]; ViewBag.Keywords = _config["SEO:KeywordsPT"]; ViewBag.Description = _localizer["QRGenerateDescription"]; // User stats for logged in users if (!string.IsNullOrEmpty(userId)) { ViewBag.DailyQRCount = await _userService.GetDailyQRCountAsync(userId); ViewBag.MonthlyQRCount = await _userService.GetQRCountThisMonthAsync(userId); } return View(); } public IActionResult Privacy() { var userId = User?.FindFirst(ClaimTypes.NameIdentifier)?.Value; ViewBag.ShowAds = _adDisplayService.ShouldShowAds(userId).Result; ViewBag.IsPremium = _adDisplayService.HasValidPremiumSubscription(userId ?? "").Result; ViewBag.IsAuthenticated = User.Identity?.IsAuthenticated ?? false; ViewBag.UserName = User.Identity?.Name ?? ""; ViewBag.Title = _localizer["PrivacyPolicyTitle"]; ViewBag.Description = _localizer["PrivacyPolicyDescription"]; _adDisplayService.SetViewBagAds(ViewBag); return View(); } public IActionResult Terms() { var userId = User?.FindFirst(ClaimTypes.NameIdentifier)?.Value; ViewBag.ShowAds = _adDisplayService.ShouldShowAds(userId).Result; ViewBag.IsPremium = _adDisplayService.HasValidPremiumSubscription(userId ?? "").Result; ViewBag.IsAuthenticated = User.Identity?.IsAuthenticated ?? false; ViewBag.UserName = User.Identity?.Name ?? ""; ViewBag.Title = _localizer["TermsOfUseTitle"]; ViewBag.Description = _localizer["TermsOfUseDescription"]; _adDisplayService.SetViewBagAds(ViewBag); return View(); } [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); } // Dynamic QR redirect endpoint [Route("d/{id}")] public async Task DynamicRedirect(string id) { try { _adDisplayService.SetViewBagAds(ViewBag); // This would lookup the dynamic QR content from cache/database // For now, return a placeholder return Redirect("https://qrrapido.site"); } catch { return NotFound(); } } // Health check endpoint [Route("health")] public IActionResult Health() { return Ok(new { status = "healthy", timestamp = DateTime.UtcNow }); } // Sitemap endpoint for SEO [Route("sitemap.xml")] public IActionResult Sitemap() { var sitemap = $@" https://qrrapido.site/ {DateTime.UtcNow:yyyy-MM-dd} daily 1.0 https://qrrapido.site/pt/ {DateTime.UtcNow:yyyy-MM-dd} daily 0.9 https://qrrapido.site/es/ {DateTime.UtcNow:yyyy-MM-dd} daily 0.9 https://qrrapido.site/Premium/Upgrade {DateTime.UtcNow:yyyy-MM-dd} weekly 0.8 https://qrrapido.site/privacy {DateTime.UtcNow:yyyy-MM-dd} monthly 0.5 https://qrrapido.site/terms {DateTime.UtcNow:yyyy-MM-dd} monthly 0.5 "; return Content(sitemap, "application/xml"); } } public class ErrorViewModel { public string? RequestId { get; set; } public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); } }