Fix company logo missing from PDFs and add AI photo save logging

When a tenant uploads a logo it is stored in Azure Blob Storage and
LogoData (the legacy DB byte[]) is cleared. All PDF controllers were
still reading the now-null LogoData, so logos never appeared on any
PDF after upload. Fixed by injecting ICompanyLogoService into all six
affected controllers (Quotes, Invoices, Deposits, GiftCertificates,
PurchaseOrders, CatalogItems) and loading the blob-stored logo first
before falling back to the legacy DB field.

Also added structured logging to the AI photo promotion path in
QuotesController Create/Edit POST so upload failures are visible in
production logs instead of silently swallowed.

Added onclick safety net to the Create and Edit quote submit buttons
so dynamically-injected hidden fields (AiPhotoTempIds) are written
before iOS Safari collects the form data on submit.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-06 12:27:18 -04:00
parent ca4fb959aa
commit a8fb56e8ec
8 changed files with 231 additions and 22 deletions
@@ -30,19 +30,22 @@ public class GiftCertificatesController : Controller
private readonly ILogger<GiftCertificatesController> _logger;
private readonly UserManager<ApplicationUser> _userManager;
private readonly IPdfService _pdfService;
private readonly ICompanyLogoService _logoService;
public GiftCertificatesController(
IUnitOfWork unitOfWork,
IMapper mapper,
ILogger<GiftCertificatesController> logger,
UserManager<ApplicationUser> userManager,
IPdfService pdfService)
IPdfService pdfService,
ICompanyLogoService logoService)
{
_unitOfWork = unitOfWork;
_mapper = mapper;
_logger = logger;
_userManager = userManager;
_pdfService = pdfService;
_logoService = logoService;
}
/// <summary>
@@ -340,7 +343,8 @@ public class GiftCertificatesController : Controller
try
{
var pdfBytes = await _pdfService.GenerateGiftCertificatePdfAsync(dto, company?.LogoData, company?.LogoContentType, companyInfo);
var (logoData, logoContentType) = await LoadCompanyLogoAsync(company);
var pdfBytes = await _pdfService.GenerateGiftCertificatePdfAsync(dto, logoData, logoContentType, companyInfo);
return File(pdfBytes, "application/pdf", $"GiftCertificate-{cert.CertificateCode}.pdf");
}
catch (Exception ex)
@@ -390,4 +394,15 @@ public class GiftCertificatesController : Controller
list.Insert(0, new SelectListItem { Value = "", Text = "— None (non-customer recipient) —" });
ViewBag.Customers = list;
}
private async Task<(byte[]? LogoData, string? LogoContentType)> LoadCompanyLogoAsync(Company? company)
{
if (company == null) return (null, null);
if (!string.IsNullOrEmpty(company.LogoFilePath))
{
var (ok, content, contentType, _) = await _logoService.GetCompanyLogoAsync(company.LogoFilePath);
if (ok) return (content, contentType);
}
return (company.LogoData, company.LogoContentType);
}
}