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