65 lines
2.6 KiB
C#
65 lines
2.6 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Sarand.Net.Standard.Base.App;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using Saxonite.Net.Core.Web.Admin.Models;
|
|
using Saxonite.Net.Core.Web.Base.Models;
|
|
using Saxonite.Net.Standard.Base.App;
|
|
using Saxonite.Net.Standard.Base.Helpers;
|
|
using System;
|
|
|
|
namespace Saxonite.Net.Core.Web.Admin.Controllers
|
|
{
|
|
//=======================================================================
|
|
// Admin Reference Controller - Contact Method Ajax actions only.
|
|
//=======================================================================
|
|
partial class ReferenceController
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Validate Contact Method.
|
|
//-------------------------------------------------------------------
|
|
private class AjaxResponse_ValidateContactMethod : AjaxResponse_Data
|
|
{
|
|
public AjaxResponse_ValidateContactMethod(SaxModel_Base model) : base(model) { }
|
|
}
|
|
[HttpPost]
|
|
[Route("Reference/Ajax/ValidateContactMethod")]
|
|
public IActionResult Ajax_ValidateContactMethod(Model_ContactMethod model)
|
|
{
|
|
String fn = GetType().Name + ".Ajax_ValidateContactMethod";
|
|
String messageTitle = Localiser["caption.contact.method"];
|
|
AjaxResponse_ValidateContactMethod responseData = new AjaxResponse_ValidateContactMethod(model);
|
|
|
|
// Validate session and referrer.
|
|
if (!ValidReferer) return Forbid();
|
|
if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData);
|
|
|
|
// Validate method.
|
|
Sax.ContactMethod method = EnumUtil.ParseEnum(model.ContactMethod, Sax.ContactMethod.Unknown);
|
|
if (model.ContactMethod.IsEmpty() || (int)method < 1)
|
|
responseData.SetControlError(nameof(model.ContactMethod), Localiser["msg.validation.mandatory.value"]);
|
|
|
|
// Validate method.
|
|
if (model.ContactValue.IsEmpty())
|
|
responseData.SetControlError(nameof(model.ContactValue), Localiser["msg.validation.mandatory.value"]);
|
|
|
|
// Method specific value validation.
|
|
if (!model.ContactValue.IsEmpty() && !SaxContactMethodHelper.IsValidContactMethodValue(method, model.ContactValue))
|
|
{
|
|
// Log invalid values so that the validation can be adjusted if needed.
|
|
SaLogger.Warn(fn + " Invalid contact method value. Mathod: " + method.ToString() + ". Value: " + model.ContactValue);
|
|
responseData.SetControlError(nameof(model.ContactValue), Localiser["msg.validation.invalid.value"]);
|
|
}
|
|
|
|
if (responseData.HasControlErrors())
|
|
return Json(responseData);
|
|
|
|
// Complete response.
|
|
responseData.Success = true;
|
|
return Json(responseData);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|