)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Home » Code Library » Tag (Ia.Cl.Models.Data.Nfc)

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

TAG NFC Near-Field Communication (NFC) Support Data functions

    1: using System.Collections.Generic;
    2: using System.Linq;
    3:  
    4: namespace Ia.Cl.Models.Data.Nfc
    5: {
    6:     ////////////////////////////////////////////////////////////////////////////
    7:  
    8:     /// <summary publish="true">
    9:     /// TAG NFC Near-Field Communication (NFC) Support Data functions
   10:     /// </summary>
   11:     /// <value>
   12:     /// https://msdn.microsoft.com/en-us/library/z1hkazw7(v=vs.100).aspx
   13:     /// </value>
   14:     /// <remarks> 
   15:     /// Copyright © 2020-2021 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   16:     ///
   17:     /// 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
   18:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   19:     ///
   20:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   21:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   22:     /// 
   23:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   24:     /// 
   25:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   26:     /// </remarks> 
   27:     public partial class Tag
   28:     {
   29:         ////////////////////////////////////////////////////////////////////////////
   30:  
   31:         /// <summary>
   32:         ///
   33:         /// </summary>
   34:         public Tag() { }
   35:  
   36:         ////////////////////////////////////////////////////////////////////////////
   37:  
   38:         /// <summary>
   39:         ///
   40:         /// </summary>
   41:         public static Ia.Cl.Models.Db.Default.PersistentStorageState CreateOrUpdate(Ia.Cl.Models.Nfc.Tag newTag)
   42:         {
   43:             Ia.Cl.Models.Db.Default.PersistentStorageState persistentStorageState;
   44:  
   45:             using (var db = new Ia.Cl.Models.IaDbContext())
   46:             {
   47:                 var tag = (from t in db.Tags where t.UId == newTag.UId select t).SingleOrDefault();
   48:  
   49:                 if (tag == null)
   50:                 {
   51:                     db.Tags.Add(newTag);
   52:  
   53:                     persistentStorageState = Ia.Cl.Models.Db.Default.PersistentStorageState.Created;
   54:                 }
   55:                 else
   56:                 {
   57:                     if (tag.Update(newTag))
   58:                     {
   59:                         db.Tags.Attach(tag);
   60:                         db.Entry(tag).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
   61:  
   62:                         persistentStorageState = Ia.Cl.Models.Db.Default.PersistentStorageState.Updated;
   63:                     }
   64:                     else
   65:                     {
   66:                         persistentStorageState = Ia.Cl.Models.Db.Default.PersistentStorageState.None;
   67:                     }
   68:                 }
   69:  
   70:                 db.SaveChanges();
   71:             }
   72:  
   73:             return persistentStorageState;
   74:         }
   75:  
   76:         ////////////////////////////////////////////////////////////////////////////
   77:  
   78:         /// <summary>
   79:         ///
   80:         /// </summary>
   81:         public static Ia.Cl.Models.Nfc.Tag Read(string id)
   82:         {
   83:             Ia.Cl.Models.Nfc.Tag item;
   84:  
   85:             using (var db = new Ia.Cl.Models.IaDbContext())
   86:             {
   87:                 item = (from t in db.Tags where t.Id == id select t).SingleOrDefault();
   88:             }
   89:  
   90:             return item;
   91:         }
   92:  
   93:         ////////////////////////////////////////////////////////////////////////////
   94:  
   95:         /// <summary>
   96:         ///
   97:         /// </summary>
   98:         public static Ia.Cl.Models.Nfc.Tag ReadByProjectIdAndUid(int projectId, string uId)
   99:         {
  100:             Ia.Cl.Models.Nfc.Tag item;
  101:  
  102:             using (var db = new Ia.Cl.Models.IaDbContext())
  103:             {
  104:                 item = (from t in db.Tags where t.ProjectId == projectId && t.UId == uId select t).SingleOrDefault();
  105:             }
  106:  
  107:             return item;
  108:         }
  109:  
  110:         ////////////////////////////////////////////////////////////////////////////
  111:  
  112:         /// <summary>
  113:         ///
  114:         /// </summary>
  115:         public static List<Ia.Cl.Models.Nfc.Tag> List()
  116:         {
  117:             List<Ia.Cl.Models.Nfc.Tag> list;
  118:  
  119:             using (var db = new Ia.Cl.Models.IaDbContext())
  120:             {
  121:                 list = (from t in db.Tags select t).ToList();
  122:             }
  123:  
  124:             return list;
  125:         }
  126:  
  127:         ////////////////////////////////////////////////////////////////////////////
  128:  
  129:         /// <summary>
  130:         ///
  131:         /// </summary>
  132:         public static List<Ia.Cl.Models.Nfc.Tag> ListByProjectId(int projectId)
  133:         {
  134:             List<Ia.Cl.Models.Nfc.Tag> list;
  135:  
  136:             using (var db = new Ia.Cl.Models.IaDbContext())
  137:             {
  138:                 list = (from t in db.Tags where t.ProjectId == projectId select t).ToList();
  139:             }
  140:  
  141:             return list;
  142:         }
  143:  
  144:         ////////////////////////////////////////////////////////////////////////////
  145:  
  146:         /// <summary>
  147:         ///
  148:         /// </summary>
  149:         public static List<Ia.Cl.Models.Nfc.Tag> ListByTypeId(int typeId)
  150:         {
  151:             List<Ia.Cl.Models.Nfc.Tag> list;
  152:  
  153:             using (var db = new Ia.Cl.Models.IaDbContext())
  154:             {
  155:                 list = (from t in db.Tags where t.TypeId == typeId select t).ToList();
  156:             }
  157:  
  158:             return list;
  159:         }
  160:  
  161:         ////////////////////////////////////////////////////////////////////////////
  162:  
  163:         /// <summary>
  164:         ///
  165:         /// </summary>
  166:         public static void DeleteByProjectId(int projectId)
  167:         {
  168:             using (var db = new Ia.Cl.Models.IaDbContext())
  169:             {
  170:                 var list = from t in db.Tags where t.ProjectId == projectId select t;
  171:  
  172:                 db.Tags.RemoveRange(list);
  173:                 db.SaveChanges();
  174:             }
  175:         }
  176:  
  177:         ////////////////////////////////////////////////////////////////////////////
  178:         ////////////////////////////////////////////////////////////////////////////
  179:     }
  180:  
  181:     ////////////////////////////////////////////////////////////////////////////
  182:     ////////////////////////////////////////////////////////////////////////////
  183: }