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