)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Home » Code Library » ServiceController (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: using System.Text.RegularExpressions;
    6:  
    7: namespace Ia.Wa.Controllers
    8: {
    9:     ////////////////////////////////////////////////////////////////////////////
   10:  
   11:     /// <summary publish="true">
   12:     ///
   13:     /// </summary>
   14:     /// 
   15:     /// <remarks> 
   16:     /// Copyright � 2006-2025 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   17:     ///
   18:     /// 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
   19:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   20:     ///
   21:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   22:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   23:     /// 
   24:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   25:     /// 
   26:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   27:     /// </remarks> 
   28:     public class ServiceController : Controller
   29:     {
   30:         /////////////////////////////////////////////////////////////////////////////////
   31:  
   32:         /// <summary>
   33:         ///
   34:         /// </summary>
   35:         public IActionResult Index() { return View(); }
   36:  
   37:         /////////////////////////////////////////////////////////////////////////////////
   38:  
   39:         /// <summary>
   40:         ///
   41:         /// </summary>
   42:         public IActionResult Advertisement() { return View("Advertisement"); }
   43:  
   44:         /////////////////////////////////////////////////////////////////////////////////
   45:  
   46:         /// <summary>
   47:         ///
   48:         /// </summary>
   49:         [Route("/service/api-service")]
   50:         public IActionResult ApiService() 
   51:         {
   52:             var ip = Request.HttpContext.Connection.RemoteIpAddress;
   53:  
   54:             return View((object)ip.ToString()); 
   55:         }
   56:  
   57:         /////////////////////////////////////////////////////////////////////////////////
   58:  
   59:         /// <summary>
   60:         ///
   61:         /// </summary>
   62:         public IActionResult Cloud() { return View(); }
   63:  
   64:         /////////////////////////////////////////////////////////////////////////////////
   65:  
   66:         /// <summary>
   67:         ///
   68:         /// </summary>
   69:         public IActionResult Cryptography() { return View(); }
   70:  
   71:         /////////////////////////////////////////////////////////////////////////////////
   72:  
   73:         /// <summary>
   74:         ///
   75:         /// </summary>
   76:         public IActionResult Dn() { return View(); }
   77:  
   78:         /////////////////////////////////////////////////////////////////////////////////
   79:  
   80:         /// <summary>
   81:         ///
   82:         /// </summary>
   83:         public IActionResult Ecommerce() { return View(); }
   84:  
   85:         /////////////////////////////////////////////////////////////////////////////////
   86:  
   87:         /// <summary>
   88:         ///
   89:         /// </summary>
   90:         public IActionResult GeoIp() 
   91:         {
   92:             var ip = Request.HttpContext.Connection.RemoteIpAddress.ToString();
   93:  
   94:             ViewBag.RemoteIp = ip;
   95:  
   96:             return View((object)ip.ToString()); 
   97:         }
   98:  
   99:         /////////////////////////////////////////////////////////////////////////////////
  100:  
  101:         /// <summary>
  102:         ///
  103:         /// </summary>
  104:         [HttpPost]
  105:         public IActionResult GeoIp(string ipTextInput)
  106:         {
  107:             var ip = WebUtility.HtmlEncode(ipTextInput);
  108:             ip = ip.Trim();
  109:  
  110:             ViewBag.Ip = ip;
  111:  
  112:             var result = new Ia.Cl.Models.Result(); // ProcessEmail(nameTextInput, emailTextInput, phoneTextInput, inquiryTextArea);
  113:  
  114:             var countryInfo = new Ia.Cl.Models.GeoIp.CountryInfo();
  115:  
  116:             if (Ia.Cl.Models.Default.IsValidIpv4(ip))
  117:             {
  118:                 countryInfo = Ia.Cl.Models.Http.GetAsync<Ia.Cl.Models.GeoIp.CountryInfo>("https://api.ia.com.kw", "api/geoip/countries/" + ip).Result;
  119:  
  120:                 if (countryInfo != null)
  121:                 {
  122:                     ViewBag.CountryInfoName = countryInfo.Name;
  123:                     ViewBag.CountryInfoIsoCode = countryInfo.IsoCode;
  124:                     ViewBag.FlagUrlImageUrl = @"https://cdn.ia.com.kw/image/flag/iso/32/" + countryInfo.IsoCode.ToLower() + ".png";
  125:                     ViewBag.FlagUrlImageText = countryInfo.Name;
  126:  
  127:                     result.AddSuccess("");
  128:                 }
  129:                 else
  130:                 {
  131:                     result.AddError("Could not find country from IP.");
  132:                 }
  133:             }
  134:             else
  135:             {
  136:                 result.AddError("Entered string is not in a valid IP format.");
  137:             }
  138:  
  139:             if (result.IsSuccessful)
  140:             {
  141:                 ViewBag.ResultMessage = result.Message;
  142:                 ViewBag.ResultClass = "success";
  143:             }
  144:             else
  145:             {
  146:                 ViewBag.ResultMessage = result.Message;
  147:                 ViewBag.ResultClass = "error";
  148:             }
  149:  
  150:             return View((object)ip.ToString());
  151:         }
  152:  
  153:         /////////////////////////////////////////////////////////////////////////////////
  154:  
  155:         /// <summary>
  156:         ///
  157:         /// </summary>
  158:         public IActionResult Intranet() { return View(); }
  159:  
  160:         /////////////////////////////////////////////////////////////////////////////////
  161:  
  162:         /// <summary>
  163:         ///
  164:         /// </summary>
  165:         public IActionResult Iot() { return View(); }
  166:  
  167:         /////////////////////////////////////////////////////////////////////////////////
  168:  
  169:         /// <summary>
  170:         ///
  171:         /// </summary>
  172:         [Route("/service/ip-camera")]
  173:         public IActionResult IpCamera() { return View(); }
  174:  
  175:         /////////////////////////////////////////////////////////////////////////////////
  176:  
  177:         /// <summary>
  178:         ///
  179:         /// </summary>
  180:         public IActionResult Map() { return View(); }
  181:  
  182:         /////////////////////////////////////////////////////////////////////////////////
  183:  
  184:         /// <summary>
  185:         ///
  186:         /// </summary>
  187:         [Route("/service/qr-code")]
  188:         public IActionResult QrCode() { return View(); }
  189:  
  190:         /////////////////////////////////////////////////////////////////////////////////
  191:  
  192:         /// <summary>
  193:         ///
  194:         /// </summary>
  195:         public IActionResult Regex() { return View(); }
  196:         //[Route("/service/regex")] for razor pages
  197:         //public IActionResult Regex() { return View("/Pages/Regex.cshtml"); }
  198:  
  199:         /////////////////////////////////////////////////////////////////////////////////
  200:  
  201:         /// <summary>
  202:         ///
  203:         /// </summary>
  204:         [HttpPost]
  205:         public IActionResult Regex(string textArea, string patternTextInput, string replacementTextInput)
  206:         {
  207:             string text, patternText, replacementText, l;
  208:  
  209:             var result = new Cl.Models.Result();
  210:  
  211:             text = WebUtility.HtmlEncode(textArea) ?? string.Empty;
  212:             patternText = WebUtility.HtmlEncode(patternTextInput) ?? string.Empty;
  213:             replacementText = WebUtility.HtmlEncode(replacementTextInput) ?? string.Empty;
  214:  
  215:             if (!string.IsNullOrEmpty(text))
  216:             {
  217:                 if (!string.IsNullOrEmpty(patternText))
  218:                 {
  219:                     if (!string.IsNullOrEmpty(replacementText))
  220:                     {
  221:                         try
  222:                         {
  223:                             l = System.Text.RegularExpressions.Regex.Replace(text, patternText, replacementText);
  224:  
  225:                             // now I will encode string to display HTML code on the HTML page
  226:                             ViewBag.ResultText = Cl.Models.Html.Encode(l);
  227:  
  228:                             result.AddSuccess("Successful");
  229:                         }
  230:                         catch (Exception ex)
  231:                         {
  232:                             result.AddError("Regular expression could not be evaluated: " + ex.Message);
  233:                         }
  234:                     }
  235:                     else
  236:                     {
  237:                         result.AddError("Replacement field is missing.");
  238:                     }
  239:                 }
  240:                 else
  241:                 {
  242:                     result.AddError("Pattern field is missing.");
  243:                 }
  244:             }
  245:             else
  246:             {
  247:                 result.AddError("Text field is empty.");
  248:             }
  249:  
  250:             if (result.IsSuccessful)
  251:             {
  252:                 ViewBag.ResultMessage = result.Message;
  253:                 ViewBag.ResultClass = "success";
  254:             }
  255:             else
  256:             {
  257:                 ViewBag.ResultMessage = result.Message;
  258:                 ViewBag.ResultClass = "error";
  259:             }
  260:  
  261:             return View();
  262:         }
  263:  
  264:         /////////////////////////////////////////////////////////////////////////////////
  265:  
  266:         /// <summary>
  267:         ///
  268:         /// </summary>
  269:         public IActionResult Server() { return View(); }
  270:  
  271:         /////////////////////////////////////////////////////////////////////////////////
  272:  
  273:         /// <summary>
  274:         ///
  275:         /// </summary>
  276:         public IActionResult Sms() { return View(); }
  277:  
  278:         /////////////////////////////////////////////////////////////////////////////////
  279:  
  280:         /// <summary>
  281:         ///
  282:         /// </summary>
  283:         public IActionResult Telegram() { return View(); }
  284:  
  285:         /////////////////////////////////////////////////////////////////////////////////
  286:  
  287:         /// <summary>
  288:         ///
  289:         /// </summary>
  290:         public IActionResult Unix() { return View(); }
  291:  
  292:         /////////////////////////////////////////////////////////////////////////////////
  293:  
  294:         /// <summary>
  295:         ///
  296:         /// </summary>
  297:         public IActionResult Video() { return View(); }
  298:  
  299:         /////////////////////////////////////////////////////////////////////////////////
  300:  
  301:         /// <summary>
  302:         ///
  303:         /// </summary>
  304:         public IActionResult Winform() { return View(); }
  305:  
  306:         /////////////////////////////////////////////////////////////////////////////////
  307:  
  308:         /// <summary>
  309:         ///
  310:         /// </summary>
  311:         [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
  312:         public IActionResult Error()
  313:         {
  314:             return View(new Ia.Wa.Models.ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
  315:         }
  316:  
  317:         /////////////////////////////////////////////////////////////////////////////////
  318:         /////////////////////////////////////////////////////////////////////////////////
  319:     }
  320:  
  321:     /////////////////////////////////////////////////////////////////////////////////
  322:     /////////////////////////////////////////////////////////////////////////////////
  323: }