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

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

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

    1: using System;
    2: using System.Collections.Generic;
    3: using System.Linq;
    4:  
    5: namespace Ia.Cl.Model.Data.Nfc
    6: {
    7:     ////////////////////////////////////////////////////////////////////////////
    8:  
    9:     /// <summary publish="true">
   10:     /// Inventory NFC Near-Field Communication (NFC) Support Data functions
   11:     /// </summary>
   12:     /// <remarks> 
   13:     /// Copyright © 2020-2021 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:     public partial class Inventory
   26:     {
   27:         ////////////////////////////////////////////////////////////////////////////
   28:  
   29:         /// <summary>
   30:         ///
   31:         /// </summary>
   32:         public Inventory() { }
   33:  
   34:         ////////////////////////////////////////////////////////////////////////////
   35:  
   36:         /// <summary>
   37:         ///
   38:         /// </summary>
   39:         public static bool Create(Ia.Cl.Model.Nfc.Inventory newInventory, out string result)
   40:         {
   41:             bool b;
   42:  
   43:             b = false;
   44:             result = string.Empty;
   45:  
   46:             using (var db = new Ia.Cl.Model.IaDbContext())
   47:             {
   48:                 newInventory.Created = newInventory.Updated = DateTime.UtcNow.AddHours(3);
   49:  
   50:                 db.Inventories.Add(newInventory);
   51:                 db.SaveChanges();
   52:  
   53:                 b = true;
   54:             }
   55:  
   56:             return b;
   57:         }
   58:  
   59:         ////////////////////////////////////////////////////////////////////////////
   60:  
   61:         /// <summary>
   62:         ///
   63:         /// </summary>
   64:         public static Ia.Cl.Model.Db.Default.PersistentStorageState CreateOrUpdate(Ia.Cl.Model.Nfc.Inventory newInventory)
   65:         {
   66:             Ia.Cl.Model.Db.Default.PersistentStorageState persistentStorageState;
   67:  
   68:             using (var db = new Ia.Cl.Model.IaDbContext())
   69:             {
   70:                 var tagId = newInventory.Id;
   71:  
   72:                 newInventory.Tag = (from t in db.Tags where t.Id == tagId select t).SingleOrDefault();
   73:  
   74:                 var inventory = (from t in db.Inventories where t.Id == newInventory.Id select t).SingleOrDefault();
   75:  
   76:                 if (inventory == null)
   77:                 {
   78:                     db.Inventories.Add(newInventory);
   79:  
   80:                     persistentStorageState = Ia.Cl.Model.Db.Default.PersistentStorageState.Created;
   81:                 }
   82:                 else
   83:                 {
   84:                     if (inventory.Update(newInventory))
   85:                     {
   86:                         db.Inventories.Attach(inventory);
   87:                         db.Entry(inventory).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
   88:  
   89:                         persistentStorageState = Ia.Cl.Model.Db.Default.PersistentStorageState.Updated;
   90:                     }
   91:                     else
   92:                     {
   93:                         persistentStorageState = Ia.Cl.Model.Db.Default.PersistentStorageState.None;
   94:                     }
   95:                 }
   96:  
   97:                 db.SaveChanges();
   98:             }
   99:  
  100:             return persistentStorageState;
  101:         }
  102:  
  103:         ////////////////////////////////////////////////////////////////////////////
  104:  
  105:         /// <summary>
  106:         ///
  107:         /// </summary>
  108:         public static Ia.Cl.Model.Nfc.Inventory Read(string id)
  109:         {
  110:             Ia.Cl.Model.Nfc.Inventory inventory;
  111:  
  112:             using (var db = new Ia.Cl.Model.IaDbContext())
  113:             {
  114:                 inventory = (from i in db.Inventories where i.Id == id select i).SingleOrDefault();
  115:             }
  116:  
  117:             return inventory;
  118:         }
  119:  
  120:         ////////////////////////////////////////////////////////////////////////////
  121:  
  122:         /// <summary>
  123:         ///
  124:         /// </summary>
  125:         public static List<Ia.Cl.Model.Nfc.Inventory> List()
  126:         {
  127:             List<Ia.Cl.Model.Nfc.Inventory> inventoryList;
  128:  
  129:             using (var db = new Ia.Cl.Model.IaDbContext())
  130:             {
  131:                 inventoryList = (from i in db.Inventories select i).ToList();
  132:             }
  133:  
  134:             return inventoryList;
  135:         }
  136:  
  137:         ////////////////////////////////////////////////////////////////////////////
  138:  
  139:         /// <summary>
  140:         ///
  141:         /// </summary>
  142:         public static List<Ia.Cl.Model.Nfc.Inventory> List(int projectId)
  143:         {
  144:             List<Ia.Cl.Model.Nfc.Inventory> inventoryList;
  145:  
  146:             using (var db = new Ia.Cl.Model.IaDbContext())
  147:             {
  148:                 inventoryList = (from i in db.Inventories where i.ProjectId == projectId select i).ToList();
  149:             }
  150:  
  151:             return inventoryList;
  152:         }
  153:  
  154:         ////////////////////////////////////////////////////////////////////////////
  155:  
  156:         /// <summary>
  157:         ///
  158:         /// </summary>
  159:         public static bool Update(Ia.Cl.Model.Nfc.Inventory updatedInventory, out string result)
  160:         {
  161:             bool b;
  162:  
  163:             b = false;
  164:             result = string.Empty;
  165:  
  166:             using (var db = new Ia.Cl.Model.IaDbContext())
  167:             {
  168:                 updatedInventory = (from i in db.Inventories where i.Id == updatedInventory.Id select i).SingleOrDefault();
  169:  
  170:                 updatedInventory.Updated = DateTime.UtcNow.AddHours(3);
  171:  
  172:                 db.Inventories.Attach(updatedInventory);
  173:  
  174:                 var v = db.Entry(updatedInventory);
  175:                 v.State = Microsoft.EntityFrameworkCore.EntityState.Modified;
  176:                 db.SaveChanges();
  177:  
  178:                 b = true;
  179:             }
  180:  
  181:             return b;
  182:         }
  183:  
  184:         ////////////////////////////////////////////////////////////////////////////
  185:  
  186:         /// <summary>
  187:         ///
  188:         /// </summary>
  189:         public static bool Delete(string id, out string result)
  190:         {
  191:             bool b;
  192:  
  193:             b = false;
  194:             result = string.Empty;
  195:  
  196:             using (var db = new Ia.Cl.Model.IaDbContext())
  197:             {
  198:                 var v = (from i in db.Inventories where i.Id == id select i).FirstOrDefault();
  199:  
  200:                 db.Inventories.Remove(v);
  201:                 db.SaveChanges();
  202:  
  203:                 b = true;
  204:             }
  205:  
  206:             return b;
  207:         }
  208:  
  209:         ////////////////////////////////////////////////////////////////////////////
  210:         ////////////////////////////////////////////////////////////////////////////
  211:     }
  212:  
  213:     ////////////////////////////////////////////////////////////////////////////
  214:     ////////////////////////////////////////////////////////////////////////////
  215: }