100 lines
3.2 KiB
C#
100 lines
3.2 KiB
C#
using Azure;
|
|
using CPRNIMS.Domain.UIContracts.SMTP;
|
|
using CPRNIMS.Infrastructure.Entities.Items;
|
|
using CPRNIMS.Infrastructure.Helper;
|
|
using CPRNIMS.Infrastructure.ViewModel.Account;
|
|
using CPRNIMS.Infrastructure.ViewModel.Canvass;
|
|
using CPRNIMS.Infrastructure.ViewModel.Items;
|
|
using CPRNIMS.Infrastructure.ViewModel.SMTP;
|
|
using CPRNIMS.WebApps.Controllers.Base;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace CPRNIMS.WebApps.Controllers.SMTP
|
|
{
|
|
public class SMTPMgmtController : BaseMethod
|
|
{
|
|
List<SMTPCredentialVM>? response;
|
|
private readonly ISMTP _sMTP;
|
|
public SMTPMgmtController(ErrorLogHelper errorMessageService,
|
|
IWebHostEnvironment webHostEnvironment, TokenHelper tokenHelper
|
|
, ISMTP sMTP
|
|
)
|
|
: base(errorMessageService, webHostEnvironment,tokenHelper)
|
|
{
|
|
_sMTP = sMTP;
|
|
}
|
|
public async Task<IActionResult> Index()
|
|
{
|
|
await IsAuthenTicated();
|
|
return View();
|
|
}
|
|
#region Get
|
|
public async Task<IActionResult> GetAllSmtp()
|
|
{
|
|
try
|
|
{
|
|
var viewModels = new SMTPCredentialVM();
|
|
response = await _sMTP.GetAllSmtp(GetUser(), viewModels);
|
|
if (response == null)
|
|
{
|
|
response = new List<SMTPCredentialVM>();
|
|
ViewBag.UserRoles = UserRoles;
|
|
return Json(new { success = false, data = response });
|
|
}
|
|
ViewBag.UserRoles = UserRoles;
|
|
return Json(new { success = true, data = response });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var message = ex.InnerException?.ToString() ?? ex.Message.ToString();
|
|
throw;
|
|
}
|
|
}
|
|
[HttpPost]
|
|
public async Task<IActionResult> GetMySMTP(SMTPCredentialVM viewModels)
|
|
{
|
|
try
|
|
{
|
|
response = await _sMTP.GetMySmtp(GetUser(), viewModels);
|
|
if (response == null)
|
|
{
|
|
|
|
ViewBag.UserRoles = UserRoles;
|
|
return Json(new { success = false, data = response });
|
|
}
|
|
//To manage the table buttons
|
|
ViewBag.UserRoles = UserRoles;
|
|
return Json(new { success = true, data = response });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var message = ex.InnerException?.ToString() ?? ex.Message.ToString();
|
|
throw;
|
|
}
|
|
}
|
|
#endregion
|
|
#region Post Put
|
|
public async Task<IActionResult> PostPutSmtp(SMTPCredentialVM viewModel)
|
|
{
|
|
try
|
|
{
|
|
var postPutSmtp = await _sMTP.PostPutSmtp(GetUser(), viewModel);
|
|
|
|
if (postPutSmtp.StatusResponse != "Error")
|
|
{
|
|
return Json(new { success = true });
|
|
}
|
|
|
|
return Json(new { success = false, Response = postPutSmtp.Message });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var message = ex.InnerException?.ToString() ?? ex.Message.ToString();
|
|
|
|
throw;
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|