using Azure; using CPRNIMS.Domain.UIContracts.Account; 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? response; private readonly ISMTP _sMTP; public SMTPMgmtController(ErrorLogHelper errorMessageService, IWebHostEnvironment webHostEnvironment, TokenHelper tokenHelper , ISMTP sMTP,IAccount account ) : base(errorMessageService, webHostEnvironment,tokenHelper, account) { _sMTP = sMTP; } public async Task Index() { return await IsAuthenTicated(); } #region Get public async Task GetAllSmtp() { try { var viewModels = new SMTPCredentialVM(); response = await _sMTP.GetAllSmtp(GetUser(), viewModels); if (response == null) { response = new List(); 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 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 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 } }