شركة التطبيقات المتكاملة لتصميم النظم البرمجية الخاصة

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » Miscellaneous

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

Miscellaneous Entity Framework class for Next Generation Network (NGN) data model.

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Linq;
   4:   
   5:  namespace Ia.Ngn.Cl.Model.Data
   6:  {
   7:      ////////////////////////////////////////////////////////////////////////////
   8:   
   9:      /// <summary publish="true">
  10:      /// Miscellaneous Entity Framework class for Next Generation Network (NGN) data model.
  11:      /// </summary>
  12:      /// 
  13:      /// <remarks> 
  14:      /// Copyright © 2006-2019 Jasem Y. Al-Shamlan (info@ia.com.kw), Internet Applications - Kuwait. All Rights Reserved.
  15:      ///
  16:      /// 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
  17:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  18:      ///
  19:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  20:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  21:      /// 
  22:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  23:      /// 
  24:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  25:      /// </remarks> 
  26:      public partial class Miscellaneous
  27:      {
  28:          /// <summary/>
  29:          public Miscellaneous() { }
  30:   
  31:          ////////////////////////////////////////////////////////////////////////////
  32:   
  33:          /// <summary>
  34:          ///
  35:          /// </summary>
  36:          public static bool Create(Ia.Ngn.Cl.Model.Miscellaneous item, out string result)
  37:          {
  38:              bool b;
  39:   
  40:              b = false;
  41:              result = string.Empty;
  42:   
  43:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  44:              {
  45:                  item.Created = item.Updated = DateTime.UtcNow.AddHours(3);
  46:   
  47:                  db.Miscellaneous.Add(item);
  48:                  db.SaveChanges();
  49:   
  50:                  b = true;
  51:              }
  52:   
  53:              return b;
  54:          }
  55:   
  56:          ////////////////////////////////////////////////////////////////////////////
  57:   
  58:          /// <summary>
  59:          ///
  60:          /// </summary>
  61:          public static bool Create(string name, string value, out string result)
  62:          {
  63:              bool b;
  64:              Ia.Ngn.Cl.Model.Miscellaneous misc;
  65:   
  66:              b = false;
  67:              result = string.Empty;
  68:              misc = new Ia.Ngn.Cl.Model.Miscellaneous();
  69:   
  70:              misc.Name = name;
  71:              misc.Value = value;
  72:   
  73:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  74:              {
  75:                  misc.Created = misc.Updated = DateTime.UtcNow.AddHours(3);
  76:   
  77:                  db.Miscellaneous.Add(misc);
  78:                  db.SaveChanges();
  79:   
  80:                  b = true;
  81:              }
  82:   
  83:              return b;
  84:          }
  85:   
  86:          ////////////////////////////////////////////////////////////////////////////
  87:   
  88:          /// <summary>
  89:          ///
  90:          /// </summary>
  91:          public static bool Create(string name, Queue<string> queue, out string result)
  92:          {
  93:              bool b;
  94:              Ia.Ngn.Cl.Model.Miscellaneous misc;
  95:   
  96:              b = false;
  97:              result = string.Empty;
  98:              misc = new Ia.Ngn.Cl.Model.Miscellaneous();
  99:   
 100:              misc.Name = name;
 101:              misc.Value = string.Join(",", queue.ToArray());
 102:   
 103:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 104:              {
 105:                  misc.Created = misc.Updated = DateTime.UtcNow.AddHours(3);
 106:   
 107:                  db.Miscellaneous.Add(misc);
 108:                  db.SaveChanges();
 109:   
 110:                  b = true;
 111:              }
 112:   
 113:              return b;
 114:          }
 115:   
 116:          ////////////////////////////////////////////////////////////////////////////
 117:   
 118:          /// <summary>
 119:          ///
 120:          /// </summary>
 121:          public static bool Create(string name, bool flag, out string result)
 122:          {
 123:              bool b;
 124:              Ia.Ngn.Cl.Model.Miscellaneous misc;
 125:   
 126:              b = false;
 127:              result = string.Empty;
 128:              misc = new Ia.Ngn.Cl.Model.Miscellaneous();
 129:   
 130:              misc.Name = name;
 131:              misc.Flag = flag;
 132:   
 133:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 134:              {
 135:                  misc.Created = misc.Updated = DateTime.UtcNow.AddHours(3);
 136:   
 137:                  db.Miscellaneous.Add(misc);
 138:                  db.SaveChanges();
 139:   
 140:                  b = true;
 141:              }
 142:   
 143:              return b;
 144:          }
 145:   
 146:          ////////////////////////////////////////////////////////////////////////////
 147:   
 148:          /// <summary>
 149:          ///
 150:          /// </summary>
 151:          public static Ia.Ngn.Cl.Model.Miscellaneous Read(long id)
 152:          {
 153:              Ia.Ngn.Cl.Model.Miscellaneous item;
 154:   
 155:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 156:              {
 157:                  item = (from m in db.Miscellaneous where m.Id == id select m).SingleOrDefault();
 158:              }
 159:   
 160:              return item;
 161:          }
 162:   
 163:          ////////////////////////////////////////////////////////////////////////////
 164:   
 165:          /// <summary>
 166:          ///
 167:          /// </summary>
 168:          public static string Read(string name)
 169:          {
 170:              string value;
 171:   
 172:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 173:              {
 174:                  value = (from m in db.Miscellaneous where m.Name == name select m.Value).SingleOrDefault();
 175:              }
 176:   
 177:              return value;
 178:          }
 179:   
 180:          ////////////////////////////////////////////////////////////////////////////
 181:   
 182:          /// <summary>
 183:          ///
 184:          /// </summary>
 185:          public static Queue<string> ReadQueue(string name)
 186:          {
 187:              string value;
 188:              Queue<string> queue;
 189:   
 190:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 191:              {
 192:                  value = (from m in db.Miscellaneous where m.Name == name select m.Value).SingleOrDefault();
 193:   
 194:                  queue = new Queue<string>(value.Split(',').ToList());
 195:              }
 196:   
 197:              return queue;
 198:          }
 199:   
 200:          ////////////////////////////////////////////////////////////////////////////
 201:   
 202:          /// <summary>
 203:          ///
 204:          /// </summary>
 205:          public static bool ReadFlag(string name)
 206:          {
 207:              bool flag;
 208:   
 209:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 210:              {
 211:                  flag = (from m in db.Miscellaneous where m.Name == name select m.Flag).SingleOrDefault();
 212:              }
 213:   
 214:              return flag;
 215:          }
 216:   
 217:          ////////////////////////////////////////////////////////////////////////////
 218:   
 219:          /// <summary>
 220:          ///
 221:          /// </summary>
 222:          public static List<Ia.Ngn.Cl.Model.Miscellaneous> ReadList()
 223:          {
 224:              List<Ia.Ngn.Cl.Model.Miscellaneous> itemList;
 225:   
 226:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 227:              {
 228:                  itemList = (from m in db.Miscellaneous select m).ToList();
 229:              }
 230:   
 231:              return itemList;
 232:          }
 233:   
 234:          ////////////////////////////////////////////////////////////////////////////
 235:   
 236:          /// <summary>
 237:          ///
 238:          /// </summary>
 239:          public static bool Update(Ia.Ngn.Cl.Model.Miscellaneous item, out string result)
 240:          {
 241:              bool b;
 242:   
 243:              b = false;
 244:              result = string.Empty;
 245:   
 246:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 247:              {
 248:                  item = (from m in db.Miscellaneous where m.Id == item.Id select m).SingleOrDefault();
 249:   
 250:                  item.Updated = DateTime.UtcNow.AddHours(3);
 251:   
 252:                  db.Miscellaneous.Attach(item);
 253:   
 254:                  db.Entry(item).State = System.Data.Entity.EntityState.Modified;
 255:                  db.SaveChanges();
 256:   
 257:                  b = true;
 258:              }
 259:   
 260:              return b;
 261:          }
 262:   
 263:          ////////////////////////////////////////////////////////////////////////////
 264:   
 265:          /// <summary>
 266:          ///
 267:          /// </summary>
 268:          public static bool CreateOrUpdate(string name, string value, out string result)
 269:          {
 270:              bool b;
 271:              Ia.Ngn.Cl.Model.Miscellaneous misc;
 272:   
 273:              b = false;
 274:              result = string.Empty;
 275:   
 276:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 277:              {
 278:                  misc = (from m in db.Miscellaneous where m.Name == name select m).SingleOrDefault();
 279:   
 280:                  if (misc == null)
 281:                  {
 282:                      misc = new Ia.Ngn.Cl.Model.Miscellaneous();
 283:   
 284:                      misc.Name = name;
 285:                      misc.Value = value;
 286:                      misc.Created = misc.Updated = DateTime.UtcNow.AddHours(3);
 287:   
 288:                      db.Miscellaneous.Add(misc);
 289:                      b = true;
 290:                  }
 291:                  else
 292:                  {
 293:                      misc.Updated = DateTime.UtcNow.AddHours(3);
 294:   
 295:                      misc.Value = value;
 296:   
 297:                      db.Miscellaneous.Attach(misc);
 298:   
 299:                      db.Entry(misc).State = System.Data.Entity.EntityState.Modified;
 300:   
 301:                      b = true;
 302:                  }
 303:   
 304:                  db.SaveChanges();
 305:              }
 306:   
 307:              return b;
 308:          }
 309:   
 310:          ////////////////////////////////////////////////////////////////////////////
 311:   
 312:          /// <summary>
 313:          ///
 314:          /// </summary>
 315:          public static bool CreateOrUpdate(string name, Queue<string> queue, out string result)
 316:          {
 317:              bool b;
 318:              Ia.Ngn.Cl.Model.Miscellaneous misc;
 319:   
 320:              b = false;
 321:              result = string.Empty;
 322:   
 323:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 324:              {
 325:                  misc = (from m in db.Miscellaneous where m.Name == name select m).SingleOrDefault();
 326:   
 327:                  if (misc == null)
 328:                  {
 329:                      misc = new Ia.Ngn.Cl.Model.Miscellaneous();
 330:   
 331:                      misc.Name = name;
 332:                      misc.Value = string.Join(",", queue.ToArray());
 333:                      misc.Created = misc.Updated = DateTime.UtcNow.AddHours(3);
 334:   
 335:                      db.Miscellaneous.Add(misc);
 336:                      b = true;
 337:                  }
 338:                  else
 339:                  {
 340:                      misc.Updated = DateTime.UtcNow.AddHours(3);
 341:   
 342:                      misc.Value = string.Join(",", queue.ToArray());
 343:   
 344:                      db.Miscellaneous.Attach(misc);
 345:   
 346:                      db.Entry(misc).State = System.Data.Entity.EntityState.Modified;
 347:   
 348:                      b = true;
 349:                  }
 350:   
 351:                  db.SaveChanges();
 352:              }
 353:   
 354:              return b;
 355:          }
 356:   
 357:          ////////////////////////////////////////////////////////////////////////////
 358:   
 359:          /// <summary>
 360:          ///
 361:          /// </summary>
 362:          public static bool CreateOrUpdateFlag(string name, bool flag, out string result)
 363:          {
 364:              bool b;
 365:              Ia.Ngn.Cl.Model.Miscellaneous misc;
 366:   
 367:              b = false;
 368:              result = string.Empty;
 369:   
 370:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 371:              {
 372:                  misc = (from m in db.Miscellaneous where m.Name == name select m).SingleOrDefault();
 373:   
 374:                  if (misc == null)
 375:                  {
 376:                      misc = new Ia.Ngn.Cl.Model.Miscellaneous();
 377:   
 378:                      misc.Name = name;
 379:                      misc.Flag = flag;
 380:                      misc.Created = misc.Updated = DateTime.UtcNow.AddHours(3);
 381:   
 382:                      db.Miscellaneous.Add(misc);
 383:                      b = true;
 384:                  }
 385:                  else
 386:                  {
 387:                      misc.Updated = DateTime.UtcNow.AddHours(3);
 388:   
 389:                      misc.Flag = flag;
 390:   
 391:                      db.Miscellaneous.Attach(misc);
 392:   
 393:                      db.Entry(misc).State = System.Data.Entity.EntityState.Modified;
 394:   
 395:                      b = true;
 396:                  }
 397:   
 398:                  db.SaveChanges();
 399:              }
 400:   
 401:              return b;
 402:          }
 403:   
 404:          ////////////////////////////////////////////////////////////////////////////
 405:   
 406:          /// <summary>
 407:          ///
 408:          /// </summary>
 409:          public static void SetFlag(string name, out string result)
 410:          {
 411:              CreateOrUpdateFlag(name, true, out result);
 412:          }
 413:   
 414:          ////////////////////////////////////////////////////////////////////////////
 415:   
 416:          /// <summary>
 417:          ///
 418:          /// </summary>
 419:          public static void ResetFlag(string name, out string result)
 420:          {
 421:              CreateOrUpdateFlag(name, false, out result);
 422:          }
 423:   
 424:          ////////////////////////////////////////////////////////////////////////////
 425:   
 426:          /// <summary>
 427:          ///
 428:          /// </summary>
 429:          public bool Update(/*Ont updatedOnt*/ object updatedObject)
 430:          {
 431:              // below: this will not update Id, Created
 432:              bool updated;
 433:   
 434:              updated = false;
 435:   
 436:              //if (this.StateId != updatedOnt.StateId) { this.StateId = updatedOnt.StateId; updated = true; }
 437:   
 438:              //if (updated) this.Updated = DateTime.UtcNow.AddHours(3);
 439:   
 440:              return updated;
 441:          }
 442:   
 443:          ////////////////////////////////////////////////////////////////////////////
 444:   
 445:          /// <summary>
 446:          ///
 447:          /// </summary>
 448:          public static bool Delete(long id, out string result)
 449:          {
 450:              bool b;
 451:   
 452:              b = false;
 453:              result = string.Empty;
 454:   
 455:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 456:              {
 457:                  var v = (from m in db.Miscellaneous where m.Id == id select m).FirstOrDefault();
 458:   
 459:                  db.Miscellaneous.Remove(v);
 460:                  db.SaveChanges();
 461:   
 462:                  b = true;
 463:              }
 464:   
 465:              return b;
 466:          }
 467:   
 468:          ////////////////////////////////////////////////////////////////////////////
 469:          ////////////////////////////////////////////////////////////////////////////
 470:      }
 471:   
 472:      ////////////////////////////////////////////////////////////////////////////
 473:      ////////////////////////////////////////////////////////////////////////////
 474:  }