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

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, List<string> list, 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("|", list.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, Queue<string> queue, 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.Value = string.Join("|", queue.ToArray());
 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 bool Create(string name, bool flag, out string result)
 152:          {
 153:              bool b;
 154:              Ia.Ngn.Cl.Model.Miscellaneous misc;
 155:   
 156:              b = false;
 157:              result = string.Empty;
 158:              misc = new Ia.Ngn.Cl.Model.Miscellaneous();
 159:   
 160:              misc.Name = name;
 161:              misc.Flag = flag;
 162:   
 163:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 164:              {
 165:                  misc.Created = misc.Updated = DateTime.UtcNow.AddHours(3);
 166:   
 167:                  db.Miscellaneous.Add(misc);
 168:                  db.SaveChanges();
 169:   
 170:                  b = true;
 171:              }
 172:   
 173:              return b;
 174:          }
 175:   
 176:          ////////////////////////////////////////////////////////////////////////////
 177:   
 178:          /// <summary>
 179:          ///
 180:          /// </summary>
 181:          public static Ia.Ngn.Cl.Model.Miscellaneous Read(long id)
 182:          {
 183:              Ia.Ngn.Cl.Model.Miscellaneous item;
 184:   
 185:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 186:              {
 187:                  item = (from m in db.Miscellaneous where m.Id == id select m).SingleOrDefault();
 188:              }
 189:   
 190:              return item;
 191:          }
 192:   
 193:          ////////////////////////////////////////////////////////////////////////////
 194:   
 195:          /// <summary>
 196:          ///
 197:          /// </summary>
 198:          public static string Read(string name)
 199:          {
 200:              string value;
 201:   
 202:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 203:              {
 204:                  value = (from m in db.Miscellaneous where m.Name == name select m.Value).SingleOrDefault();
 205:              }
 206:   
 207:              return value;
 208:          }
 209:   
 210:          ////////////////////////////////////////////////////////////////////////////
 211:   
 212:          /// <summary>
 213:          ///
 214:          /// </summary>
 215:          public static List<string> ReadList(string name)
 216:          {
 217:              string value;
 218:              List<string> list;
 219:   
 220:              list = new List<string>();
 221:   
 222:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 223:              {
 224:                  value = (from m in db.Miscellaneous where m.Name == name select m.Value).SingleOrDefault();
 225:   
 226:                  if (!string.IsNullOrEmpty(value))
 227:                  {
 228:                      list = new List<string>(value.Split('|').ToList());
 229:                  }
 230:              }
 231:   
 232:              return list;
 233:          }
 234:   
 235:          ////////////////////////////////////////////////////////////////////////////
 236:   
 237:          /// <summary>
 238:          ///
 239:          /// </summary>
 240:          public static Queue<string> ReadQueue(string name)
 241:          {
 242:              string value;
 243:              Queue<string> queue;
 244:   
 245:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 246:              {
 247:                  value = (from m in db.Miscellaneous where m.Name == name select m.Value).SingleOrDefault();
 248:   
 249:                  queue = new Queue<string>(value.Split('|').ToList());
 250:              }
 251:   
 252:              return queue;
 253:          }
 254:   
 255:          ////////////////////////////////////////////////////////////////////////////
 256:   
 257:          /// <summary>
 258:          ///
 259:          /// </summary>
 260:          public static bool ReadFlag(string name)
 261:          {
 262:              bool flag;
 263:   
 264:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 265:              {
 266:                  flag = (from m in db.Miscellaneous where m.Name == name select m.Flag).SingleOrDefault();
 267:              }
 268:   
 269:              return flag;
 270:          }
 271:   
 272:          ////////////////////////////////////////////////////////////////////////////
 273:   
 274:          /// <summary>
 275:          ///
 276:          /// </summary>
 277:          public static List<Ia.Ngn.Cl.Model.Miscellaneous> ReadList()
 278:          {
 279:              List<Ia.Ngn.Cl.Model.Miscellaneous> itemList;
 280:   
 281:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 282:              {
 283:                  itemList = (from m in db.Miscellaneous select m).ToList();
 284:              }
 285:   
 286:              return itemList;
 287:          }
 288:   
 289:          ////////////////////////////////////////////////////////////////////////////
 290:   
 291:          /// <summary>
 292:          ///
 293:          /// </summary>
 294:          public static bool Update(Ia.Ngn.Cl.Model.Miscellaneous item, out string result)
 295:          {
 296:              bool b;
 297:   
 298:              b = false;
 299:              result = string.Empty;
 300:   
 301:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 302:              {
 303:                  item = (from m in db.Miscellaneous where m.Id == item.Id select m).SingleOrDefault();
 304:   
 305:                  item.Updated = DateTime.UtcNow.AddHours(3);
 306:   
 307:                  db.Miscellaneous.Attach(item);
 308:   
 309:                  db.Entry(item).State = System.Data.Entity.EntityState.Modified;
 310:                  db.SaveChanges();
 311:   
 312:                  b = true;
 313:              }
 314:   
 315:              return b;
 316:          }
 317:   
 318:          ////////////////////////////////////////////////////////////////////////////
 319:   
 320:          /// <summary>
 321:          ///
 322:          /// </summary>
 323:          public static bool CreateOrUpdate(string name, string value, out string result)
 324:          {
 325:              bool b;
 326:              Ia.Ngn.Cl.Model.Miscellaneous misc;
 327:   
 328:              b = false;
 329:              result = string.Empty;
 330:   
 331:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 332:              {
 333:                  misc = (from m in db.Miscellaneous where m.Name == name select m).SingleOrDefault();
 334:   
 335:                  if (misc == null)
 336:                  {
 337:                      misc = new Ia.Ngn.Cl.Model.Miscellaneous();
 338:   
 339:                      misc.Name = name;
 340:                      misc.Value = value;
 341:                      misc.Created = misc.Updated = DateTime.UtcNow.AddHours(3);
 342:   
 343:                      db.Miscellaneous.Add(misc);
 344:                      b = true;
 345:                  }
 346:                  else
 347:                  {
 348:                      misc.Updated = DateTime.UtcNow.AddHours(3);
 349:   
 350:                      misc.Value = value;
 351:   
 352:                      db.Miscellaneous.Attach(misc);
 353:   
 354:                      db.Entry(misc).State = System.Data.Entity.EntityState.Modified;
 355:   
 356:                      b = true;
 357:                  }
 358:   
 359:                  db.SaveChanges();
 360:              }
 361:   
 362:              return b;
 363:          }
 364:   
 365:          ////////////////////////////////////////////////////////////////////////////
 366:   
 367:          /// <summary>
 368:          ///
 369:          /// </summary>
 370:          public static bool CreateOrUpdate(string name, List<string> list, out string result)
 371:          {
 372:              bool b;
 373:              Ia.Ngn.Cl.Model.Miscellaneous misc;
 374:   
 375:              b = false;
 376:              result = string.Empty;
 377:   
 378:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 379:              {
 380:                  misc = (from m in db.Miscellaneous where m.Name == name select m).SingleOrDefault();
 381:   
 382:                  if (misc == null)
 383:                  {
 384:                      misc = new Ia.Ngn.Cl.Model.Miscellaneous();
 385:   
 386:                      misc.Name = name;
 387:                      misc.Value = string.Join("|", list.ToArray());
 388:                      misc.Created = misc.Updated = DateTime.UtcNow.AddHours(3);
 389:   
 390:                      db.Miscellaneous.Add(misc);
 391:                      b = true;
 392:                  }
 393:                  else
 394:                  {
 395:                      misc.Updated = DateTime.UtcNow.AddHours(3);
 396:   
 397:                      misc.Value = string.Join("|", list.ToArray());
 398:   
 399:                      db.Miscellaneous.Attach(misc);
 400:   
 401:                      db.Entry(misc).State = System.Data.Entity.EntityState.Modified;
 402:   
 403:                      b = true;
 404:                  }
 405:   
 406:                  db.SaveChanges();
 407:              }
 408:   
 409:              return b;
 410:          }
 411:   
 412:          ////////////////////////////////////////////////////////////////////////////
 413:   
 414:          /// <summary>
 415:          ///
 416:          /// </summary>
 417:          public static bool CreateOrUpdate(string name, Queue<string> queue, out string result)
 418:          {
 419:              bool b;
 420:              Ia.Ngn.Cl.Model.Miscellaneous misc;
 421:   
 422:              b = false;
 423:              result = string.Empty;
 424:   
 425:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 426:              {
 427:                  misc = (from m in db.Miscellaneous where m.Name == name select m).SingleOrDefault();
 428:   
 429:                  if (misc == null)
 430:                  {
 431:                      misc = new Ia.Ngn.Cl.Model.Miscellaneous();
 432:   
 433:                      misc.Name = name;
 434:                      misc.Value = string.Join("|", queue.ToArray());
 435:                      misc.Created = misc.Updated = DateTime.UtcNow.AddHours(3);
 436:   
 437:                      db.Miscellaneous.Add(misc);
 438:                      b = true;
 439:                  }
 440:                  else
 441:                  {
 442:                      misc.Updated = DateTime.UtcNow.AddHours(3);
 443:   
 444:                      misc.Value = string.Join("|", queue.ToArray());
 445:   
 446:                      db.Miscellaneous.Attach(misc);
 447:   
 448:                      db.Entry(misc).State = System.Data.Entity.EntityState.Modified;
 449:   
 450:                      b = true;
 451:                  }
 452:   
 453:                  db.SaveChanges();
 454:              }
 455:   
 456:              return b;
 457:          }
 458:   
 459:          ////////////////////////////////////////////////////////////////////////////
 460:   
 461:          /// <summary>
 462:          ///
 463:          /// </summary>
 464:          public static bool CreateOrUpdateFlag(string name, bool flag, out string result)
 465:          {
 466:              bool b;
 467:              Ia.Ngn.Cl.Model.Miscellaneous misc;
 468:   
 469:              b = false;
 470:              result = string.Empty;
 471:   
 472:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 473:              {
 474:                  misc = (from m in db.Miscellaneous where m.Name == name select m).SingleOrDefault();
 475:   
 476:                  if (misc == null)
 477:                  {
 478:                      misc = new Ia.Ngn.Cl.Model.Miscellaneous();
 479:   
 480:                      misc.Name = name;
 481:                      misc.Flag = flag;
 482:                      misc.Created = misc.Updated = DateTime.UtcNow.AddHours(3);
 483:   
 484:                      db.Miscellaneous.Add(misc);
 485:                      b = true;
 486:                  }
 487:                  else
 488:                  {
 489:                      misc.Updated = DateTime.UtcNow.AddHours(3);
 490:   
 491:                      misc.Flag = flag;
 492:   
 493:                      db.Miscellaneous.Attach(misc);
 494:   
 495:                      db.Entry(misc).State = System.Data.Entity.EntityState.Modified;
 496:   
 497:                      b = true;
 498:                  }
 499:   
 500:                  db.SaveChanges();
 501:              }
 502:   
 503:              return b;
 504:          }
 505:   
 506:          ////////////////////////////////////////////////////////////////////////////
 507:   
 508:          /// <summary>
 509:          ///
 510:          /// </summary>
 511:          public static void SetFlag(string name, out string result)
 512:          {
 513:              CreateOrUpdateFlag(name, true, out result);
 514:          }
 515:   
 516:          ////////////////////////////////////////////////////////////////////////////
 517:   
 518:          /// <summary>
 519:          ///
 520:          /// </summary>
 521:          public static void ResetFlag(string name, out string result)
 522:          {
 523:              CreateOrUpdateFlag(name, false, out result);
 524:          }
 525:   
 526:          ////////////////////////////////////////////////////////////////////////////
 527:   
 528:          /// <summary>
 529:          ///
 530:          /// </summary>
 531:          public bool Update(/*Ont updatedOnt*/ object updatedObject)
 532:          {
 533:              // below: this will not update Id, Created
 534:              bool updated;
 535:   
 536:              updated = false;
 537:   
 538:              //if (this.StateId != updatedOnt.StateId) { this.StateId = updatedOnt.StateId; updated = true; }
 539:   
 540:              //if (updated) this.Updated = DateTime.UtcNow.AddHours(3);
 541:   
 542:              return updated;
 543:          }
 544:   
 545:          ////////////////////////////////////////////////////////////////////////////
 546:   
 547:          /// <summary>
 548:          ///
 549:          /// </summary>
 550:          public static bool Delete(long id, out string result)
 551:          {
 552:              bool b;
 553:   
 554:              b = false;
 555:              result = string.Empty;
 556:   
 557:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 558:              {
 559:                  var v = (from m in db.Miscellaneous where m.Id == id select m).FirstOrDefault();
 560:   
 561:                  db.Miscellaneous.Remove(v);
 562:                  db.SaveChanges();
 563:   
 564:                  b = true;
 565:              }
 566:   
 567:              return b;
 568:          }
 569:   
 570:          ////////////////////////////////////////////////////////////////////////////
 571:          ////////////////////////////////////////////////////////////////////////////
 572:      }
 573:   
 574:      ////////////////////////////////////////////////////////////////////////////
 575:      ////////////////////////////////////////////////////////////////////////////
 576:  }