Professional Applications Programmers/Consultants برمجة واستشارات تطبيقات الإنترنت
Skip Navigation LinksHome » Code Library » DefaultController

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

Default API Controller class.

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Linq;
   4:  using System.Net;
   5:  using System.Web.Http;
   6:  using System.Runtime.Serialization;
   7:   
   8:  namespace Ia.Ngn.Cl.Model.Api.Controller
   9:  {
  10:      ////////////////////////////////////////////////////////////////////////////
  11:   
  12:      /// <summary publish="true">
  13:      /// Default API Controller class.
  14:      /// </summary>
  15:      /// 
  16:      /// <remarks> 
  17:      /// Copyright © 2001-2018 Jasem Y. Al-Shamlan (info@ia.com.kw), Internet 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:      public class DefaultController : ApiController
  30:      {
  31:          ////////////////////////////////////////////////////////////////////////////
  32:   
  33:          /// <summary>
  34:          ///
  35:          /// </summary>
  36:          public DefaultController()
  37:          {
  38:          }
  39:   
  40:          ////////////////////////////////////////////////////////////////////////////
  41:   
  42:          /// <summary>
  43:          /// Check the validity of a password and return true if password is accepted for host.
  44:          /// </summary>
  45:          [HttpGet]
  46:          public bool Validate(string password, string uriString)
  47:          {
  48:              bool isValid;
  49:              Uri uri;
  50:   
  51:              if (!string.IsNullOrEmpty(uriString))
  52:              {
  53:                  try
  54:                  {
  55:                      uri = new System.Uri("http://" + uriString);
  56:   
  57:                      isValid = Ia.Cl.Model.Authentication.Validate(password, uri);
  58:                  }
  59:                  catch(UriFormatException)
  60:                  {
  61:                      isValid = false;
  62:                  }
  63:              }
  64:              else isValid = false;
  65:   
  66:              return isValid;
  67:          }
  68:   
  69:          ////////////////////////////////////////////////////////////////////////////
  70:   
  71:          /// <summary>
  72:          /// Echo the passed string
  73:          /// </summary>
  74:          [HttpGet]
  75:          public string Echo(string text)
  76:          {
  77:              return text;
  78:          }
  79:   
  80:          ////////////////////////////////////////////////////////////////////////////
  81:   
  82:          /// <summary>
  83:          /// Return current time
  84:          /// </summary>
  85:          [HttpGet]
  86:          public string Time()
  87:          {
  88:              return DateTime.UtcNow.AddHours(3).ToString("yyyy-MM-dd HH:mm:ss.fff");
  89:          }
  90:   
  91:          ////////////////////////////////////////////////////////////////////////////
  92:          ////////////////////////////////////////////////////////////////////////////
  93:      }
  94:   
  95:      ////////////////////////////////////////////////////////////////////////////
  96:      ////////////////////////////////////////////////////////////////////////////
  97:  }