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

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

    1: using Ia.Wa.Models;
    2: using Microsoft.AspNetCore.Mvc;
    3: using System.Diagnostics;
    4: using System.Net;
    5:  
    6: namespace Ia.Wa.Controllers
    7: {
    8:     ////////////////////////////////////////////////////////////////////////////
    9:  
   10:     /// <summary publish="true">
   11:     ///
   12:     /// </summary>
   13:     /// 
   14:     /// <remarks> 
   15:     /// Copyright © 2006-2025 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   16:     ///
   17:     /// 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
   18:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   19:     ///
   20:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   21:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   22:     /// 
   23:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   24:     /// 
   25:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   26:     /// </remarks> 
   27:     public class ContactController : Controller
   28:     {
   29:         /////////////////////////////////////////////////////////////////////////////////
   30:  
   31:         /// <summary>
   32:         ///
   33:         /// </summary>
   34:         [HttpGet]
   35:         public IActionResult Index()
   36:         {
   37:             return View();
   38:         }
   39:  
   40:         /////////////////////////////////////////////////////////////////////////////////
   41:  
   42:         /// <summary>
   43:         ///
   44:         /// </summary>
   45:         [HttpPost]
   46:         public IActionResult Index(string nameTextInput, string emailTextInput, string phoneTextInput, string inquiryTextArea)
   47:         {
   48:             var result = ProcessEmail(nameTextInput, emailTextInput, phoneTextInput, inquiryTextArea);
   49:  
   50:             if (result.IsSuccessful)
   51:             {
   52:                 ViewBag.ResultMessage = result.Message;
   53:                 ViewBag.ResultClass = "success";
   54:             }
   55:             else
   56:             {
   57:                 ViewBag.ResultMessage = result.Message;
   58:                 ViewBag.ResultClass = "error";
   59:             }
   60:  
   61:             return View();
   62:         }
   63:  
   64:         /////////////////////////////////////////////////////////////////////////////////
   65:  
   66:         /// <summary>
   67:         ///
   68:         /// </summary>
   69:         protected Ia.Cl.Models.Result ProcessEmail(string nameTextInput, string emailTextInput, string phoneTextInput, string inquiryTextArea)
   70:         {
   71:             var result = new Ia.Cl.Models.Result();
   72:  
   73:             if (!string.IsNullOrEmpty(nameTextInput))
   74:             {
   75:                 if (!string.IsNullOrEmpty(emailTextInput))
   76:                 {
   77:                     if (Ia.Cl.Models.Default.IsEmail(emailTextInput))
   78:                     {
   79:                         if (!string.IsNullOrEmpty(inquiryTextArea))
   80:                         {
   81:                             if (Ia.Cl.Models.Google.Recaptcha.Passed(Request.Form["g-recaptcha-response"]))
   82:                             {
   83:                                 var name = WebUtility.HtmlEncode(nameTextInput);
   84:                                 var email = WebUtility.HtmlEncode(emailTextInput);
   85:                                 var phone = WebUtility.HtmlEncode(phoneTextInput);
   86:                                 var inquiry = WebUtility.HtmlEncode(inquiryTextArea);
   87:  
   88:                                 result = SendMail(name, email, phone, inquiry);
   89:                             }
   90:                             else
   91:                             {
   92:                                 result.AddError("Captcha had failed.");
   93:                             }
   94:                         }
   95:                         else
   96:                         {
   97:                             result.AddError("Please enter your inquiry.");
   98:                         }
   99:                     }
  100:                     else
  101:                     {
  102:                         result.AddError("Your email is not in valid email format.");
  103:                     }
  104:                 }
  105:                 else
  106:                 {
  107:                     result.AddError("Please enter your email.");
  108:                 }
  109:             }
  110:             else
  111:             {
  112:                 result.AddError("Please enter your name.");
  113:             }
  114:  
  115:             return result;
  116:         }
  117:  
  118:         /////////////////////////////////////////////////////////////////////////////////
  119:  
  120:         /// <summary>
  121:         ///
  122:         /// </summary>
  123:         private Ia.Cl.Models.Result SendMail(string name, string email, string phone, string inquiry)
  124:         {
  125:             var message = Ia.Wa.Models.Ui.Default.MailTop();
  126:  
  127:             message += @"
  128: <p>A visitor to the website has an inquiry. Visitor information is below:</p>
  129:  
  130: <p>Visitor information:</p>
  131:  
  132: <table class=""form"">
  133: <tr><td>Name:</td><td>" + name + @"&nbsp;</td></tr>
  134: <tr><td>Email:</td><td>" + email + @"&nbsp;</td></tr>
  135: <tr><td>Phone:</td><td>" + phone + @"&nbsp;</td></tr>
  136: <tr><td></td><td></td></tr>
  137: <tr><td valign=""top"">Inquery:</td><td>" + inquiry + @"</td></tr>
  138: </table>";
  139:  
  140:             message += Ia.Wa.Models.Ui.Default.MailBottom();
  141:  
  142:             var applicationContact = Ia.Cl.Models.ApplicationConfiguration.GetSetting("AppSettings:ApplicationContact");
  143:             var applicationEmail = Ia.Cl.Models.ApplicationConfiguration.GetSetting("AppSettings:ApplicationEmail");
  144:  
  145:             return Ia.Cl.Models.Smtp.SendHtml(applicationContact, applicationEmail, "A visitor to the website has an inquiry", message);//, out result);
  146:         }
  147:  
  148:         /////////////////////////////////////////////////////////////////////////////////
  149:         /////////////////////////////////////////////////////////////////////////////////
  150:  
  151:         /// <summary>
  152:         ///
  153:         /// </summary>
  154:         [HttpGet]
  155:         [Route("/contact/mailing-list")]
  156:         public IActionResult MailingList()
  157:         {
  158:             return View();
  159:         }
  160:  
  161:         /////////////////////////////////////////////////////////////////////////////////
  162:  
  163:         /// <summary>
  164:         ///
  165:         /// </summary>
  166:         [HttpPost]
  167:         [Route("/contact/mailing-list")]
  168:         public IActionResult MailingList(string emailTextInput)
  169:         {
  170:             var result = ProcessMailingList(emailTextInput);
  171:  
  172:             if (result.IsSuccessful)
  173:             {
  174:                 ViewBag.ResultMessage = result.Message;
  175:                 ViewBag.ResultClass = "success";
  176:             }
  177:             else
  178:             {
  179:                 ViewBag.ResultMessage = result.Message;
  180:                 ViewBag.ResultClass = "error";
  181:             }
  182:  
  183:             return View();
  184:         }
  185:  
  186:         /////////////////////////////////////////////////////////////////////////////////
  187:  
  188:         /// <summary>
  189:         ///
  190:         /// </summary>
  191:         protected Ia.Cl.Models.Result ProcessMailingList(string emailTextInput)
  192:         {
  193:             var result = new Ia.Cl.Models.Result();
  194:  
  195:             if (!string.IsNullOrEmpty(emailTextInput))
  196:             {
  197:                 if (Ia.Cl.Models.Default.IsEmail(emailTextInput))
  198:                 {
  199:                     if (Ia.Cl.Models.Google.Recaptcha.Passed(Request.Form["g-recaptcha-response"]))
  200:                     {
  201:                         var email = WebUtility.HtmlEncode(emailTextInput);
  202:  
  203:                         result = SendMail("Unknown", email, string.Empty, "Request to join mailing list");
  204:                     }
  205:                     else
  206:                     {
  207:                         result.AddError("Captcha had failed.");
  208:                     }
  209:                 }
  210:                 else
  211:                 {
  212:                     result.AddError("Your email is not in valid email format.");
  213:                 }
  214:             }
  215:             else
  216:             {
  217:                 result.AddError("Please enter your email.");
  218:             }
  219:  
  220:             return result;
  221:         }
  222:  
  223:         /////////////////////////////////////////////////////////////////////////////////
  224:         /////////////////////////////////////////////////////////////////////////////////
  225:  
  226:         /// <summary>
  227:         ///
  228:         /// </summary>
  229:         public IActionResult Career()
  230:         {
  231:             return View();
  232:         }
  233:  
  234:         /////////////////////////////////////////////////////////////////////////////////
  235:  
  236:         /// <summary>
  237:         ///
  238:         /// </summary>
  239:         public IActionResult Support()
  240:         {
  241:             return View();
  242:         }
  243:  
  244:         /////////////////////////////////////////////////////////////////////////////////
  245:  
  246:         /// <summary>
  247:         ///
  248:         /// </summary>
  249:         [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
  250:         public IActionResult Error()
  251:         {
  252:             return View(new Ia.Wa.Models.ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
  253:         }
  254:  
  255:         /////////////////////////////////////////////////////////////////////////////////
  256:         /////////////////////////////////////////////////////////////////////////////////
  257:     }
  258:  
  259:     /////////////////////////////////////////////////////////////////////////////////
  260:     /////////////////////////////////////////////////////////////////////////////////
  261: }