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

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

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