)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Home » Code Library » ContactController (Ia.TentPlay.Wa.Controllers)

Public general use code classes and xml files that we've compiled and used over the years:

    1: using Microsoft.AspNetCore.Mvc;
    2: using System.Diagnostics;
    3: using System.Net;
    4:  
    5: namespace Ia.TentPlay.Wa.Controllers
    6: {
    7:     ////////////////////////////////////////////////////////////////////////////
    8:  
    9:     /// <summary publish="true">
   10:     ///
   11:     /// </summary>
   12:     /// 
   13:     /// <remarks> 
   14:     /// Copyright © 2006-2025 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   15:     ///
   16:     /// This library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
   17:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   18:     ///
   19:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   20:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   21:     /// 
   22:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   23:     /// 
   24:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   25:     /// </remarks> 
   26:     public class ContactController : Controller
   27:     {
   28:         private readonly ILogger<ContactController> _logger;
   29:  
   30:         /////////////////////////////////////////////////////////////////////////////////
   31:  
   32:         /// <summary>
   33:         ///
   34:         /// </summary>
   35:         public ContactController(ILogger<ContactController> logger)
   36:         {
   37:             _logger = logger;
   38:         }
   39:  
   40:         /////////////////////////////////////////////////////////////////////////////////
   41:  
   42:         /// <summary>
   43:         ///
   44:         /// </summary>
   45:         [HttpGet]
   46:         public IActionResult Index()
   47:         {
   48:             return View();
   49:         }
   50:  
   51:         /////////////////////////////////////////////////////////////////////////////////
   52:  
   53:         /// <summary>
   54:         ///
   55:         /// </summary>
   56:         [HttpPost]
   57:         public IActionResult Index(string nameTextInput, string emailTextInput, string phoneTextInput, string inquiryTextArea)
   58:         {
   59:             var result = ProcessEmail(nameTextInput, emailTextInput, phoneTextInput, inquiryTextArea);
   60:  
   61:             if (result.IsSuccessful)
   62:             {
   63:                 ViewBag.ResultMessage = result.Message;
   64:                 ViewBag.ResultClass = "success";
   65:             }
   66:             else
   67:             {
   68:                 ViewBag.ResultMessage = result.Message;
   69:                 ViewBag.ResultClass = "error";
   70:             }
   71:  
   72:             return View();
   73:         }
   74:  
   75:         /////////////////////////////////////////////////////////////////////////////////
   76:  
   77:         /// <summary>
   78:         ///
   79:         /// </summary>
   80:         protected Ia.Cl.Models.Result ProcessEmail(string nameTextInput, string emailTextInput, string phoneTextInput, string inquiryTextArea)
   81:         {
   82:             var result = new Ia.Cl.Models.Result();
   83:  
   84:             if (!string.IsNullOrEmpty(nameTextInput))
   85:             {
   86:                 if (!string.IsNullOrEmpty(emailTextInput))
   87:                 {
   88:                     if (Ia.Cl.Models.Default.IsEmail(emailTextInput))
   89:                     {
   90:                         if (!string.IsNullOrEmpty(inquiryTextArea))
   91:                         {
   92:                             if (Ia.Cl.Models.Google.Recaptcha.Passed(Request.Form["g-recaptcha-response"]))
   93:                             {
   94:                                 var name = WebUtility.HtmlEncode(nameTextInput);
   95:                                 var email = WebUtility.HtmlEncode(emailTextInput);
   96:                                 var phone = WebUtility.HtmlEncode(phoneTextInput);
   97:                                 var inquiry = WebUtility.HtmlEncode(inquiryTextArea);
   98:  
   99:                                 result = SendMail(name, email, phone, inquiry);
  100:                             }
  101:                             else
  102:                             {
  103:                                 result.AddError("Captcha had failed.");
  104:                             }
  105:                         }
  106:                         else
  107:                         {
  108:                             result.AddError("Please enter your inquiry.");
  109:                         }
  110:                     }
  111:                     else
  112:                     {
  113:                         result.AddError("Your email is not in valid email format.");
  114:                     }
  115:                 }
  116:                 else
  117:                 {
  118:                     result.AddError("Please enter your email.");
  119:                 }
  120:             }
  121:             else
  122:             {
  123:                 result.AddError("Please enter your name.");
  124:             }
  125:  
  126:             return result;
  127:         }
  128:  
  129:         /////////////////////////////////////////////////////////////////////////////////
  130:  
  131:         /// <summary>
  132:         ///
  133:         /// </summary>
  134:         private Ia.Cl.Models.Result SendMail(string name, string email, string phone, string inquiry)
  135:         {
  136:             var message = Ia.TentPlay.Wa.Models.Ui.Default.MailTop();
  137:  
  138:             message += @"
  139: <p>A visitor to the website has an inquiry. Visitor information is below:</p>
  140:  
  141: <p>Visitor information:</p>
  142:  
  143: <table class=""form"">
  144: <tr><td>Name:</td><td>" + name + @"&nbsp;</td></tr>
  145: <tr><td>Email:</td><td>" + email + @"&nbsp;</td></tr>
  146: <tr><td>Phone:</td><td>"" + phone + @""&nbsp;</td></tr>
  147: <tr><td></td><td></td></tr>
  148: <tr><td valign=""top"">Inquery:</td><td>" + inquiry + @"</td></tr>
  149: </table>";
  150:  
  151:             message += Ia.TentPlay.Wa.Models.Ui.Default.MailBottom();
  152:  
  153:             var result = Ia.Cl.Models.Smtp.SendHtml(name, email, "A visitor to the website has an inquiry", message);//, out result);
  154:  
  155:             return result;
  156:         }
  157:  
  158:         /////////////////////////////////////////////////////////////////////////////////
  159:  
  160:         /// <summary>
  161:         ///
  162:         /// </summary>
  163:         [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
  164:         public IActionResult Error()
  165:         {
  166:             return View(new Ia.TentPlay.Wa.Models.ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
  167:         }
  168:  
  169:         /////////////////////////////////////////////////////////////////////////////////
  170:         /////////////////////////////////////////////////////////////////////////////////
  171:     }
  172:  
  173:     /////////////////////////////////////////////////////////////////////////////////
  174:     /////////////////////////////////////////////////////////////////////////////////
  175: }