using System.ComponentModel.DataAnnotations; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.Rendering; using plushealthtech.Mail; namespace plushealthtech.Pages { public class RequestDemoModel : PageModel { private readonly MailSender _mailSender; private readonly ILogger _logger; public RequestDemoModel(MailSender mailSender, ILogger logger) { _mailSender = mailSender; _logger = logger; } [BindProperty] [Required] [StringLength(200)] public string Name { get; set; } = string.Empty; [BindProperty] [Required] [EmailAddress] [StringLength(320)] public string Email { get; set; } = string.Empty; [BindProperty] [Required] [StringLength(200)] public string Organization { get; set; } = string.Empty; [BindProperty] public string? PracticeType { get; set; } [BindProperty] public string? ProductsOfInterest { get; set; } [BindProperty] [StringLength(5000)] public string? Message { get; set; } public List PracticeTypeOptions { get; } = new() { new SelectListItem { Value = string.Empty, Text = "Select a practice type…", Selected = true }, new SelectListItem { Value = "Healthcare system", Text = "Healthcare system" }, new SelectListItem { Value = "Hospital", Text = "Hospital" }, new SelectListItem { Value = "Clinic", Text = "Clinic" }, new SelectListItem { Value = "Veterinary practice", Text = "Veterinary practice" }, new SelectListItem { Value = "Other", Text = "Other" }, }; public List ProductsOfInterestOptions { get; } = new() { new SelectListItem { Value = string.Empty, Text = "Select a product area…", Selected = true }, new SelectListItem { Value = "Clinical Decision Support", Text = "Clinical Decision Support" }, new SelectListItem { Value = "Patient Management", Text = "Patient Management" }, new SelectListItem { Value = "Veterinary Solutions", Text = "Veterinary Solutions" }, new SelectListItem { Value = "Multiple / not sure", Text = "Multiple / not sure" }, }; public string? Success { get; set; } public string? Error { get; set; } public void OnGet() { Success = null; Error = null; } public async Task OnPostAsync() { if (!ModelState.IsValid) { return Page(); } var lines = new List { $"Name: {Name}", $"Email: {Email}", $"Organization: {Organization}" }; if (!string.IsNullOrWhiteSpace(PracticeType)) { lines.Add($"Practice type: {PracticeType}"); } if (!string.IsNullOrWhiteSpace(ProductsOfInterest)) { lines.Add($"Products of interest: {ProductsOfInterest}"); } if (!string.IsNullOrWhiteSpace(Message)) { lines.Add(string.Empty); lines.Add(Message); } try { await _mailSender.SendAsync($"New demo request — {Organization}", string.Join("\n", lines)); Success = $"Thanks — your demo request has been sent. We'll reach out to {Email}."; } catch (Exception ex) { // Log the full exception; never surface SMTP details to the user. _logger.LogError(ex, "Failed to send demo request from {Email} ({Organization})", Email, Organization); Error = "Your request could not be sent right now. Please try again or email us directly."; } return Page(); } } }