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

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

Packet API Controller class.

    1: using Microsoft.AspNetCore.Mvc;
    2: using System.Net;
    3:  
    4: namespace Ia.Api.Wa.Controllers
    5: {
    6:     ////////////////////////////////////////////////////////////////////////////
    7:  
    8:     /// <summary publish="true">
    9:     /// Packet API Controller class.
   10:     /// </summary>
   11:     /// 
   12:     /// <remarks> 
   13:     /// Copyright © 2006-2024 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   14:     ///
   15:     /// 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
   16:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   17:     ///
   18:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   19:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   20:     /// 
   21:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   22:     /// 
   23:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   24:     /// </remarks> 
   25:     [ApiController]
   26:     [Route("api/packets")]
   27:     public class PacketController : ControllerBase
   28:     {
   29:         private static List<Ia.Cl.Models.Packet> packets = new List<Ia.Cl.Models.Packet>();
   30:  
   31:         ////////////////////////////////////////////////////////////////////////////
   32:  
   33:         /// <summary>
   34:         /// 
   35:         /// </summary>
   36:         [HttpPost]
   37:         [Route("")]
   38:         public HttpStatusCode PostPacket(Ia.Cl.Models.Packet packet)
   39:         {
   40:             HttpStatusCode httpStatusCode;
   41:  
   42:             if (packet != null)
   43:             {
   44:                 packets.Add(packet);
   45:  
   46:                 httpStatusCode = HttpStatusCode.OK;
   47:             }
   48:             else
   49:             {
   50:                 httpStatusCode = HttpStatusCode.BadRequest;
   51:             }
   52:  
   53:             return httpStatusCode;
   54:         }
   55:  
   56:         ////////////////////////////////////////////////////////////////////////////
   57:  
   58:         /// <summary>
   59:         /// 
   60:         /// </summary>
   61:         [HttpGet]
   62:         [Route("{id:guid}")]
   63:         public Ia.Cl.Models.Packet? GetPacket(Guid id)
   64:         {
   65:             Ia.Cl.Models.Packet? packet;
   66:  
   67:             if (packets.Count > 0)
   68:             {
   69:                 packet = (from p in packets
   70:                           where p.Id == id
   71:                           orderby p.Created descending
   72:                           select p).SingleOrDefault();
   73:  
   74:                 if (packet == null) packet = new Ia.Cl.Models.Packet();
   75:             }
   76:             else packet = default;
   77:  
   78:             return packet;
   79:         }
   80:  
   81:         ////////////////////////////////////////////////////////////////////////////
   82:  
   83:         /// <summary>
   84:         /// 
   85:         /// </summary>
   86:         [HttpGet]
   87:         [Route("recipientAssemblyProduct/{recipientAssemblyProduct}")]
   88:         public List<Ia.Cl.Models.Packet> GetPacketsByAgentRecipientAssemblyProduct(string recipientAssemblyProduct)
   89:         {
   90:             var list = (from p in packets
   91:                         where p.RecipientAssemblyProduct == recipientAssemblyProduct
   92:                         orderby p.Created descending
   93:                         select p).ToList();
   94:  
   95:             return list;
   96:         }
   97:  
   98:         ////////////////////////////////////////////////////////////////////////////
   99:  
  100:         /// <summary>
  101:         /// 
  102:         /// </summary>
  103:         [HttpGet]
  104:         [Route("senderAssemblyProduct/{senderAssemblyProduct}")]
  105:         public List<Ia.Cl.Models.Packet> GetPacketsByAgentSenderAssemblyProduct(string senderAssemblyProduct)
  106:         {
  107:             var list = (from p in packets
  108:                         where p.SenderAssemblyProduct == senderAssemblyProduct
  109:                         orderby p.Created descending
  110:                         select p).ToList();
  111:  
  112:             return list;
  113:         }
  114:  
  115:         ////////////////////////////////////////////////////////////////////////////
  116:  
  117:         /// <summary>
  118:         /// 
  119:         /// </summary>
  120:         [HttpGet]
  121:         [Route("")]
  122:         public List<Ia.Cl.Models.Packet> GetPackets()
  123:         {
  124:             return packets;
  125:         }
  126:  
  127:         ////////////////////////////////////////////////////////////////////////////
  128:         ////////////////////////////////////////////////////////////////////////////
  129:     }
  130:  
  131:     ////////////////////////////////////////////////////////////////////////////
  132:     ////////////////////////////////////////////////////////////////////////////
  133: }