35 lines
1.2 KiB
C#
35 lines
1.2 KiB
C#
|
|
using Microsoft.AspNetCore.Mvc;
|
||
|
|
using SoroushAsadi.Services;
|
||
|
|
|
||
|
|
namespace SoroushAsadi.Pages;
|
||
|
|
|
||
|
|
[Microsoft.AspNetCore.Mvc.IgnoreAntiforgeryToken]
|
||
|
|
public class IndexModel : BasePageModel
|
||
|
|
{
|
||
|
|
public string BlogReadMore { get; private set; } = "Read";
|
||
|
|
public string BlogReadSuffix { get; private set; } = "min";
|
||
|
|
|
||
|
|
public void OnGet()
|
||
|
|
{
|
||
|
|
BlogReadMore = IsFa ? "ادامه" : "Read";
|
||
|
|
BlogReadSuffix = IsFa ? "دقیقه" : "min";
|
||
|
|
}
|
||
|
|
|
||
|
|
public async Task<IActionResult> OnPostContactAsync(
|
||
|
|
[FromServices] EmailService email,
|
||
|
|
string name, string company, string service,
|
||
|
|
string budget, string message)
|
||
|
|
{
|
||
|
|
if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(service) ||
|
||
|
|
string.IsNullOrWhiteSpace(budget) || string.IsNullOrWhiteSpace(message))
|
||
|
|
return BadRequest(new { error = "Missing required fields" });
|
||
|
|
|
||
|
|
var err = await email.SendContactAsync(
|
||
|
|
new EmailService.ContactForm(name, company ?? "", service, budget, message, Locale));
|
||
|
|
|
||
|
|
return err is null
|
||
|
|
? new JsonResult(new { ok = true })
|
||
|
|
: StatusCode(502, new { error = err });
|
||
|
|
}
|
||
|
|
}
|