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

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » Service2

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

Service support class for Optical Fiber Network (OFN) data model.

   1:  using Microsoft.EntityFrameworkCore;
   2:  using Microsoft.EntityFrameworkCore.Internal;
   3:  using System;
   4:  using System.Collections;
   5:  using System.Collections.Generic;
   6:  using System.Data;
   7:  using System.Linq;
   8:   
   9:  namespace Ia.Ngn.Cl.Model.Data
  10:  {
  11:      ////////////////////////////////////////////////////////////////////////////
  12:   
  13:      /// <summary publish="true">
  14:      /// Service support class for Optical Fiber Network (OFN) data model.
  15:      /// </summary>
  16:      /// 
  17:      /// <remarks> 
  18:      /// Copyright © 2006-2021 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
  19:      ///
  20:      /// 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
  21:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  22:      ///
  23:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  24:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  25:      /// 
  26:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  27:      /// 
  28:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  29:      /// </remarks> 
  30:      public class Service2
  31:      {
  32:          public Service2() { }
  33:   
  34:          ////////////////////////////////////////////////////////////////////////////
  35:   
  36:          /// <summary>
  37:          ///
  38:          /// </summary>
  39:          public static Ia.Ngn.Cl.Model.Service2 Read(string service)
  40:          {
  41:              Ia.Ngn.Cl.Model.Service2 service2;
  42:   
  43:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  44:              {
  45:                  service2 = (from s in db.Service2
  46:                              where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && s.Service == service
  47:                              select s).SingleOrDefault();
  48:              }
  49:   
  50:              return service2;
  51:          }
  52:   
  53:          ////////////////////////////////////////////////////////////////////////////
  54:   
  55:          /// <summary>
  56:          ///
  57:          /// </summary>
  58:          public static List<Ia.Ngn.Cl.Model.Service2> ReadList(List<string> serviceList)
  59:          {
  60:              List<Ia.Ngn.Cl.Model.Service2> list;
  61:   
  62:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  63:              {
  64:                  if (serviceList.Count > 0)
  65:                  {
  66:                      list = (from s in db.Service2
  67:                              where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && serviceList.Contains(s.Service)
  68:                              select s).ToList();
  69:                  }
  70:                  else list = new List<Ia.Ngn.Cl.Model.Service2>();
  71:              }
  72:   
  73:              return list;
  74:          }
  75:   
  76:          ////////////////////////////////////////////////////////////////////////////
  77:   
  78:          /// <summary>
  79:          ///
  80:          /// </summary>
  81:          public static Ia.Ngn.Cl.Model.Service2 ReadMsan(string service)
  82:          {
  83:              Ia.Ngn.Cl.Model.Service2 service2;
  84:   
  85:  #if DEBUG
  86:              var dummyVarToDrawRefractorToBelow = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.Dn("0000000");
  87:  #endif
  88:   
  89:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  90:              {
  91:                  service2 = (from s in db.Service2
  92:                              join evpu in db.EmsVoipPstnUsers on "+965" + s.Service equals evpu.DN // see: Ia.Ngn.Cl.Model.Business.NumberFormatConverter.Dn()
  93:                              where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && s.Service == service
  94:                              select s).SingleOrDefault();
  95:              }
  96:   
  97:              return service2;
  98:          }
  99:   
 100:          ////////////////////////////////////////////////////////////////////////////
 101:   
 102:          /// <summary>
 103:          ///
 104:          /// </summary>
 105:          public static List<Ia.Ngn.Cl.Model.Service2> ReadMsanList(List<string> serviceList)
 106:          {
 107:              List<Ia.Ngn.Cl.Model.Service2> list;
 108:   
 109:  #if DEBUG
 110:              var dummyVarToDrawRefractorToBelow = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.Dn("0000000");
 111:  #endif
 112:   
 113:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 114:              {
 115:                  if (serviceList.Count > 0)
 116:                  {
 117:                      list = (from s in db.Service2
 118:                              join evpu in db.EmsVoipPstnUsers on "+965" + s.Service equals evpu.DN // see: Ia.Ngn.Cl.Model.Business.NumberFormatConverter.Dn()
 119:                              where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && serviceList.Contains(s.Service)
 120:                              select s).ToList();
 121:   
 122:                  }
 123:                  else list = new List<Ia.Ngn.Cl.Model.Service2>();
 124:              }
 125:   
 126:              return list;
 127:          }
 128:   
 129:          ////////////////////////////////////////////////////////////////////////////
 130:   
 131:          /// <summary>
 132:          ///
 133:          /// </summary>
 134:          public static Ia.Ngn.Cl.Model.Service2 ReadPstn(string service)
 135:          {
 136:              Ia.Ngn.Cl.Model.Service2 service2;
 137:   
 138:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 139:              {
 140:                  service2 = (from s in db.Service2
 141:                              where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.PstnService && s.Service == service
 142:                              select s).SingleOrDefault();
 143:              }
 144:   
 145:              return service2;
 146:          }
 147:   
 148:          ////////////////////////////////////////////////////////////////////////////
 149:   
 150:          /// <summary>
 151:          ///
 152:          /// </summary>
 153:          public static List<Ia.Ngn.Cl.Model.Service2> ReadPstnList(List<string> serviceList)
 154:          {
 155:              List<Ia.Ngn.Cl.Model.Service2> list;
 156:   
 157:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 158:              {
 159:                  if (serviceList.Count > 0)
 160:                  {
 161:                      list = (from s in db.Service2
 162:                              where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.PstnService && serviceList.Contains(s.Service)
 163:                              select s).ToList();
 164:                  }
 165:                  else list = new List<Ia.Ngn.Cl.Model.Service2>();
 166:              }
 167:   
 168:              return list;
 169:          }
 170:   
 171:          ////////////////////////////////////////////////////////////////////////////
 172:   
 173:          /// <summary>
 174:          ///
 175:          /// </summary>
 176:          public static Ia.Ngn.Cl.Model.Service2 Read(long number)
 177:          {
 178:              Ia.Ngn.Cl.Model.Service2 service;
 179:   
 180:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 181:              {
 182:                  service = (from s in db.Service2
 183:                             where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && s.Service == number.ToString()
 184:                             select s).SingleOrDefault();
 185:              }
 186:   
 187:              return service;
 188:          }
 189:   
 190:          ////////////////////////////////////////////////////////////////////////////
 191:   
 192:          /// <summary>
 193:          ///
 194:          /// </summary>
 195:          public static Ia.Ngn.Cl.Model.Service2 ReadByIdIncludeAccess(string serviceId)
 196:          {
 197:              Ia.Ngn.Cl.Model.Service2 service2;
 198:   
 199:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 200:              {
 201:                  service2 = (from s in db.Service2.Include(a => a.Access)
 202:                              where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && s.Id == serviceId
 203:                              select s).AsNoTracking().SingleOrDefault();
 204:              }
 205:   
 206:              return service2;
 207:          }
 208:   
 209:          ////////////////////////////////////////////////////////////////////////////
 210:   
 211:          /// <summary>
 212:          ///
 213:          /// </summary>
 214:          public static Ia.Ngn.Cl.Model.Service2 ReadWithAccess(string service)
 215:          {
 216:              Ia.Ngn.Cl.Model.Service2 service2;
 217:   
 218:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 219:              {
 220:                  service2 = (from s in db.Service2.Include(a => a.Access)
 221:                              where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && s.Service == service
 222:                              select s).SingleOrDefault();
 223:              }
 224:   
 225:              return service2;
 226:          }
 227:   
 228:          ////////////////////////////////////////////////////////////////////////////
 229:   
 230:          /// <summary>
 231:          ///
 232:          /// </summary>
 233:          public static List<Ia.Ngn.Cl.Model.Service2> List()
 234:          {
 235:              List<Ia.Ngn.Cl.Model.Service2> serviceList;
 236:   
 237:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 238:              {
 239:                  serviceList = (from s in db.Service2
 240:                                 where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService
 241:                                 select s).ToList();
 242:              }
 243:   
 244:              return serviceList;
 245:          }
 246:   
 247:          ////////////////////////////////////////////////////////////////////////////
 248:   
 249:          /// <summary>
 250:          ///
 251:          /// </summary>
 252:          public static List<string> List(List<int> domainList)
 253:          {
 254:              List<string> stringDomainList;
 255:              List<string> serviceList;
 256:   
 257:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 258:              {
 259:                  if (domainList.Count > 0)
 260:                  {
 261:                      stringDomainList = new List<string>();
 262:   
 263:                      foreach (int i in domainList) stringDomainList.Add(i.ToString());
 264:   
 265:                      serviceList = (from s in db.Service2
 266:                                     where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && stringDomainList.Any(u => s.Service.StartsWith(u.ToString()))
 267:                                     select s.Service).ToList();
 268:                  }
 269:                  else serviceList = new List<string>();
 270:              }
 271:   
 272:              return serviceList;
 273:          }
 274:   
 275:          ////////////////////////////////////////////////////////////////////////////
 276:   
 277:          /// <summary>
 278:          ///
 279:          /// </summary>
 280:          public static List<string> ServiceList
 281:          {
 282:              get
 283:              {
 284:                  List<string> list;
 285:   
 286:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 287:                  {
 288:                      list = (from s in db.Service2
 289:                              where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService
 290:                              select s.Service).ToList();
 291:                  }
 292:   
 293:                  return list;
 294:              }
 295:          }
 296:   
 297:          ////////////////////////////////////////////////////////////////////////////
 298:   
 299:          /// <summary>
 300:          ///
 301:          /// </summary>
 302:          public static List<string> ImsServiceList
 303:          {
 304:              get
 305:              {
 306:                  List<string> list;
 307:   
 308:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 309:                  {
 310:                      list = (from s in db.Service2
 311:                              where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService
 312:                              select s.Service).ToList();
 313:                  }
 314:   
 315:                  return list;
 316:              }
 317:          }
 318:   
 319:          ////////////////////////////////////////////////////////////////////////////
 320:   
 321:          /// <summary>
 322:          ///
 323:          /// </summary>
 324:          public static bool IsImsService(string service)
 325:          {
 326:              bool isImsService;
 327:   
 328:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 329:              {
 330:                  isImsService = (from s in db.Service2
 331:                                  where s.Service == service && s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService
 332:                                  select s.Service).Any();
 333:              }
 334:   
 335:              return isImsService;
 336:          }
 337:   
 338:          ////////////////////////////////////////////////////////////////////////////
 339:   
 340:          /// <summary>
 341:          ///
 342:          /// </summary>
 343:          public static List<string> ImsServiceWithAccessNullList
 344:          {
 345:              get
 346:              {
 347:                  List<string> list;
 348:   
 349:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 350:                  {
 351:                      list = (from s in db.Service2
 352:                              where s.Access == null && s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService
 353:                              select s.Service).ToList();
 354:                  }
 355:   
 356:                  return list;
 357:              }
 358:          }
 359:   
 360:          ////////////////////////////////////////////////////////////////////////////
 361:   
 362:          /// <summary>
 363:          ///
 364:          /// </summary>
 365:          public static List<string> MsanServiceList
 366:          {
 367:              get
 368:              {
 369:                  List<string> list;
 370:   
 371:  #if DEBUG
 372:                  var dummyVarToDrawRefractorToBelow = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.Dn("0000000");
 373:  #endif
 374:   
 375:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 376:                  {
 377:                      list = (from s in db.Service2
 378:                              join evpu in db.EmsVoipPstnUsers on "+965" + s.Service equals evpu.DN // see: Ia.Ngn.Cl.Model.Business.NumberFormatConverter.Dn()
 379:                              where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService
 380:                              select s.Service).ToList();
 381:                  }
 382:   
 383:                  return list;
 384:              }
 385:          }
 386:   
 387:          ////////////////////////////////////////////////////////////////////////////
 388:   
 389:          /// <summary>
 390:          /// 
 391:          /// </summary>
 392:          public static List<string> PstnServiceList
 393:          {
 394:              get
 395:              {
 396:                  List<string> list;
 397:   
 398:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 399:                  {
 400:                      list = (from s in db.Service2
 401:                              where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.PstnService
 402:                              select s.Service).ToList();
 403:                  }
 404:   
 405:                  return list.ToList();
 406:              }
 407:          }
 408:   
 409:          ////////////////////////////////////////////////////////////////////////////
 410:   
 411:          /// <summary>
 412:          ///
 413:          /// </summary>
 414:          public static bool IsPstnService(string service)
 415:          {
 416:              bool isPstnService;
 417:   
 418:   
 419:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 420:              {
 421:                  isPstnService = (from s in db.Service2
 422:                                   where s.Service == service && s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.PstnService
 423:                                   select s.Service).Any();
 424:              }
 425:   
 426:              return isPstnService;
 427:          }
 428:   
 429:          ////////////////////////////////////////////////////////////////////////////
 430:   
 431:          /// <summary>
 432:          /// 
 433:          /// </summary>
 434:          public static List<string> ServiceIdList
 435:          {
 436:              get
 437:              {
 438:                  List<string> list;
 439:   
 440:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 441:                  {
 442:                      list = (from s in db.Service2 /*where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService*/ select s.Id).ToList();
 443:                  }
 444:   
 445:                  return list.ToList();
 446:              }
 447:          }
 448:   
 449:          ////////////////////////////////////////////////////////////////////////////
 450:   
 451:          /// <summary>
 452:          /// 
 453:          /// </summary>
 454:          public static List<string> ImsServiceIdList
 455:          {
 456:              get
 457:              {
 458:                  List<string> list;
 459:   
 460:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 461:                  {
 462:                      list = (from s in db.Service2
 463:                              where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService
 464:                              select s.Id).ToList();
 465:                  }
 466:   
 467:                  return list.ToList();
 468:              }
 469:          }
 470:   
 471:          ////////////////////////////////////////////////////////////////////////////
 472:   
 473:          /// <summary>
 474:          /// 
 475:          /// </summary>
 476:          public static List<string> PstnServiceIdList
 477:          {
 478:              get
 479:              {
 480:                  List<string> list;
 481:   
 482:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 483:                  {
 484:                      list = (from s in db.Service2
 485:                              where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.PstnService
 486:                              select s.Id).ToList();
 487:                  }
 488:   
 489:                  return list.ToList();
 490:              }
 491:          }
 492:   
 493:          ////////////////////////////////////////////////////////////////////////////
 494:   
 495:          /// <summary>
 496:          ///
 497:          /// </summary>
 498:          public static List<Ia.Ngn.Cl.Model.Business.ServiceAccessIpOntCreated> ServiceOntList
 499:          {
 500:              get
 501:              {
 502:                  List<Ia.Ngn.Cl.Model.Business.ServiceAccessIpOntCreated> list;
 503:   
 504:                  var ontAccessIdToOntForOltIdListDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntDictionary;
 505:   
 506:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 507:                  {
 508:                      list = (from s in db.Service2
 509:                              where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService
 510:                              select new Ia.Ngn.Cl.Model.Business.ServiceAccessIpOntCreated { ServiceId = s.Id, Service = s.Service, AccessId = s.Access != null ? s.Access.Id : string.Empty, CreatedDateTime = s.Created }).AsNoTracking().ToList();
 511:                  }
 512:   
 513:                  foreach (var l in list)
 514:                  {
 515:                      l.Ont = ontAccessIdToOntForOltIdListDictionary.ContainsKey(l.AccessId) ? ontAccessIdToOntForOltIdListDictionary[l.AccessId] : null;
 516:                  }
 517:   
 518:                  return list;
 519:              }
 520:          }
 521:   
 522:          ////////////////////////////////////////////////////////////////////////////
 523:   
 524:          /// <summary>
 525:          ///
 526:          /// </summary>
 527:          public static List<Ia.Ngn.Cl.Model.Business.ServiceAccessIpOntCreated> ServiceOntBySiteIdList(int siteId)
 528:          {
 529:              List<Ia.Ngn.Cl.Model.Business.ServiceAccessIpOntCreated> list;
 530:   
 531:              var ontAccessIdToOntForOltIdListDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntDictionary;
 532:   
 533:              var site = (from s in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.SiteList
 534:                          where s.Id == siteId
 535:                          select s).SingleOrDefault();
 536:   
 537:              if (site != null)
 538:              {
 539:                  var siteRouterDomainList = (from r in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.RouterList
 540:                                              where r.Site.Id == site.Id
 541:                                              select r).SelectMany(d => d.DomainList).ToList();
 542:   
 543:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 544:                  {
 545:                      var list0 = (from s in db.Service2
 546:                                   where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService
 547:                                   select new Ia.Ngn.Cl.Model.Business.ServiceAccessIpOntCreated { ServiceId = s.Id, Service = s.Service, AccessId = s.Access != null ? s.Access.Id : string.Empty, CreatedDateTime = s.Created }).AsNoTracking().ToList();
 548:   
 549:                      list = new List<Ia.Ngn.Cl.Model.Business.ServiceAccessIpOntCreated>();
 550:   
 551:                      foreach (var l in list0)
 552:                      {
 553:                          if (!string.IsNullOrEmpty(l.AccessId))
 554:                          {
 555:                              if (ontAccessIdToOntForOltIdListDictionary.ContainsKey(l.AccessId))
 556:                              {
 557:                                  l.Ont = ontAccessIdToOntForOltIdListDictionary[l.AccessId];
 558:   
 559:                                  if (l.Ont.Pon.PonGroup.Olt.Odf.Router.Site.Id == siteId)
 560:                                  {
 561:                                      list.Add(l);
 562:                                  }
 563:                                  else
 564:                                  {
 565:   
 566:                                  }
 567:                              }
 568:                              else
 569:                              {
 570:   
 571:                              }
 572:                          }
 573:                          else
 574:                          {
 575:                              if (siteRouterDomainList.Any(u => l.Service.StartsWith(u.ToString())))
 576:                              {
 577:                                  list.Add(l);
 578:                              }
 579:                          }
 580:                      }
 581:                  }
 582:   
 583:                  var msanServiceList = Ia.Ngn.Cl.Model.Data.Huawei.Default.MsanServiceListBySiteId(siteId);
 584:   
 585:                  foreach (var msanService in msanServiceList)
 586:                  {
 587:                      list.Add(new Business.ServiceAccessIpOntCreated { Service = msanService, AccessId = string.Empty });
 588:                  }
 589:              }
 590:              else
 591:              {
 592:                  list = new List<Ia.Ngn.Cl.Model.Business.ServiceAccessIpOntCreated>();
 593:              }
 594:   
 595:              return list;
 596:          }
 597:   
 598:          ////////////////////////////////////////////////////////////////////////////
 599:   
 600:          /// <summary>
 601:          ///
 602:          /// </summary>
 603:          public static List<Ia.Ngn.Cl.Model.Business.ServiceAccessIpOntCreated> ServiceOntByAreaIdList(int areaId)
 604:          {
 605:              List<Ia.Ngn.Cl.Model.Business.ServiceAccessIpOntCreated> list;
 606:   
 607:              var ontAccessIdToOntForOltIdListDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntDictionary;
 608:   
 609:              var area = (from a in Ia.Ngn.Cl.Model.Data.Service.KuwaitOfnAreaList
 610:                          where a.Id == areaId
 611:                          select a).SingleOrDefault();
 612:   
 613:              if (area != null)
 614:              {
 615:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 616:                  {
 617:                      var list0 = (from s in db.Service2
 618:                                   where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService
 619:                                   select new Ia.Ngn.Cl.Model.Business.ServiceAccessIpOntCreated { ServiceId = s.Id, Service = s.Service, AccessId = s.Access != null ? s.Access.Id : string.Empty }).AsNoTracking().ToList();
 620:   
 621:                      list = new List<Ia.Ngn.Cl.Model.Business.ServiceAccessIpOntCreated>();
 622:   
 623:                      foreach (var l in list0)
 624:                      {
 625:                          if (!string.IsNullOrEmpty(l.AccessId))
 626:                          {
 627:                              if (ontAccessIdToOntForOltIdListDictionary.ContainsKey(l.AccessId))
 628:                              {
 629:                                  l.Ont = ontAccessIdToOntForOltIdListDictionary[l.AccessId];
 630:   
 631:                                  if (l.Ont.Pon.PonGroup.Symbol == area.Symbol)
 632:                                  {
 633:                                      list.Add(l);
 634:                                  }
 635:                                  else
 636:                                  {
 637:   
 638:                                  }
 639:                              }
 640:                              else
 641:                              {
 642:   
 643:                              }
 644:                          }
 645:                          else
 646:                          {
 647:                          }
 648:                      }
 649:                  }
 650:              }
 651:              else
 652:              {
 653:                  list = new List<Ia.Ngn.Cl.Model.Business.ServiceAccessIpOntCreated>();
 654:              }
 655:   
 656:              return list;
 657:          }
 658:   
 659:          ////////////////////////////////////////////////////////////////////////////
 660:   
 661:          /// <summary>
 662:          ///
 663:          /// </summary>
 664:          public static List<Ia.Ngn.Cl.Model.Business.ServiceAccessIpOntCreated> ServiceOntByDomainList(string domain)
 665:          {
 666:              List<Ia.Ngn.Cl.Model.Business.ServiceAccessIpOntCreated> list;
 667:   
 668:              var ontAccessIdToOntForOltIdListDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntDictionary;
 669:   
 670:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 671:              {
 672:                  var list0 = (from s in db.Service2
 673:                               where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && s.Service.StartsWith(domain)
 674:                               select new Ia.Ngn.Cl.Model.Business.ServiceAccessIpOntCreated { ServiceId = s.Id, Service = s.Service, AccessId = s.Access != null ? s.Access.Id : string.Empty }).AsNoTracking().ToList();
 675:   
 676:                  list = new List<Ia.Ngn.Cl.Model.Business.ServiceAccessIpOntCreated>();
 677:   
 678:                  foreach (var l in list0)
 679:                  {
 680:                      if (!string.IsNullOrEmpty(l.AccessId))
 681:                      {
 682:                          if (ontAccessIdToOntForOltIdListDictionary.ContainsKey(l.AccessId))
 683:                          {
 684:                              l.Ont = ontAccessIdToOntForOltIdListDictionary[l.AccessId];
 685:   
 686:                              list.Add(l);
 687:                          }
 688:                          else
 689:                          {
 690:   
 691:                          }
 692:                      }
 693:                      else
 694:                      {
 695:                      }
 696:                  }
 697:              }
 698:   
 699:              return list;
 700:          }
 701:   
 702:          ////////////////////////////////////////////////////////////////////////////
 703:   
 704:          /// <summary>
 705:          ///
 706:          /// </summary>
 707:          public static List<Ia.Ngn.Cl.Model.Service2> WithinSiteList(int siteId)
 708:          {
 709:              List<Ia.Ngn.Cl.Model.Service2> list;
 710:   
 711:              var site = (from s in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.SiteList
 712:                          where s.Id == siteId
 713:                          select s).SingleOrDefault();
 714:   
 715:              if (site != null)
 716:              {
 717:                  var siteRouterDomainList = (from r in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.RouterList
 718:                                              where r.Site.Id == site.Id
 719:                                              select r).SelectMany(d => d.DomainList).ToList();
 720:   
 721:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 722:                  {
 723:                      var list0 = (from s in db.Service2
 724:                                   select s).Include(u => u.Access).ToList();
 725:   
 726:                      list = (from s in list0
 727:                              where siteRouterDomainList.Any(u => s.Service.StartsWith(u.ToString()))
 728:                              select s).ToList();
 729:                  }
 730:              }
 731:              else
 732:              {
 733:                  list = new List<Ia.Ngn.Cl.Model.Service2>();
 734:              }
 735:   
 736:              return list;
 737:          }
 738:   
 739:          ////////////////////////////////////////////////////////////////////////////
 740:   
 741:          /// <summary>
 742:          /// 
 743:          /// </summary>
 744:          public static List<Ia.Ngn.Cl.Model.Service2> PstnService2List
 745:          {
 746:              get
 747:              {
 748:                  List<Ia.Ngn.Cl.Model.Service2> list;
 749:   
 750:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 751:                  {
 752:                      list = (from s in db.Service2
 753:                              where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.PstnService
 754:                              select s).Include(s => s.Access).ToList();
 755:                  }
 756:   
 757:                  return list.ToList();
 758:              }
 759:          }
 760:   
 761:          ////////////////////////////////////////////////////////////////////////////
 762:   
 763:          /// <summary>
 764:          /// 
 765:          /// </summary>
 766:          public static Dictionary<string, int> ServiceIdToPortDictionary
 767:          {
 768:              get
 769:              {
 770:                  Dictionary<string, int> dictionary;
 771:   
 772:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 773:                  {
 774:                      dictionary = (from s in db.Service2
 775:                                    where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && s.Access != null
 776:                                    select new { s.Id, s.Port }).ToDictionary(m => m.Id, m => m.Port);
 777:                  }
 778:   
 779:                  return dictionary;
 780:              }
 781:          }
 782:   
 783:          ////////////////////////////////////////////////////////////////////////////
 784:   
 785:          /// <summary>
 786:          ///
 787:          /// </summary>
 788:          public static Ia.Ngn.Cl.Model.Access ReadAccess(string id)
 789:          {
 790:              Ia.Ngn.Cl.Model.Access access;
 791:   
 792:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 793:              {
 794:                  access = (from s in db.Service2
 795:                            where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && s.Id == id
 796:                            select s.Access).SingleOrDefault();
 797:              }
 798:   
 799:              return access;
 800:          }
 801:   
 802:          ////////////////////////////////////////////////////////////////////////////
 803:   
 804:          /// <summary>
 805:          ///
 806:          /// </summary>
 807:          public static Dictionary<string, int> ServicePortDictionary
 808:          {
 809:              get
 810:              {
 811:                  Dictionary<string, int> dictionary;
 812:   
 813:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 814:                  {
 815:                      dictionary = (from s in db.Service2
 816:                                    where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && s.Port > -1
 817:                                    select new { s.Service, s.Port }).ToDictionary(m => m.Service, m => m.Port);
 818:                  }
 819:   
 820:                  return dictionary;
 821:              }
 822:          }
 823:   
 824:          ////////////////////////////////////////////////////////////////////////////
 825:   
 826:          /// <summary>
 827:          ///
 828:          /// </summary>
 829:          public static Ia.Ngn.Cl.Model.Access ReadAccess(Ia.Ngn.Cl.Model.Ngn db, string id)
 830:          {
 831:              Ia.Ngn.Cl.Model.Access access;
 832:   
 833:              access = (from s in db.Service2
 834:                        where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && s.Id == id
 835:                        select s.Access).SingleOrDefault();
 836:   
 837:              return access;
 838:          }
 839:   
 840:          ////////////////////////////////////////////////////////////////////////////
 841:   
 842:          /// <summary>
 843:          ///
 844:          /// </summary>
 845:          public static bool UpdatePort(Ia.Ngn.Cl.Model.Service2 service, int port, out string result)
 846:          {
 847:              bool b;
 848:   
 849:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 850:              {
 851:                  service = (from s in db.Service2
 852:                             where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && s.Id == service.Id
 853:                             select s).SingleOrDefault();
 854:   
 855:                  if (service.Port != port)
 856:                  {
 857:                      service.Port = port;
 858:   
 859:                      db.Service2.Attach(service);
 860:                      db.Entry(service).Property(u => u.Port).IsModified = true;
 861:   
 862:                      db.SaveChanges();
 863:   
 864:                      result = "Success: Service Port updated. ";
 865:                      b = true;
 866:                  }
 867:                  else
 868:                  {
 869:                      result = "Warning: Service Port value was not updated because its the same. ";
 870:   
 871:                      b = false;
 872:                  }
 873:              }
 874:   
 875:              return b;
 876:          }
 877:   
 878:          ////////////////////////////////////////////////////////////////////////////
 879:   
 880:          /// <summary>
 881:          ///
 882:          /// </summary>
 883:          public static List<Ia.Ngn.Cl.Model.Service2> ServiceWithNullAccessList
 884:          {
 885:              get
 886:              {
 887:                  List<Ia.Ngn.Cl.Model.Service2> serviceList;
 888:   
 889:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 890:                  {
 891:                      serviceList = (from s in db.Service2
 892:                                     where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && s.Access == null
 893:                                     select s).ToList();
 894:                  }
 895:   
 896:                  return serviceList;
 897:              }
 898:          }
 899:   
 900:          ////////////////////////////////////////////////////////////////////////////
 901:   
 902:          /// <summary>
 903:          ///
 904:          /// </summary>
 905:          public static List<string> ServiceIdWithinSipOltList()
 906:          {
 907:              List<int> sipOltIdList;
 908:              List<string> list, list2;
 909:   
 910:              sipOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.SipOltIdList;
 911:   
 912:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 913:              {
 914:                  // services with access
 915:                  list = (from s in db.Service2
 916:                          where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && s.Access != null && sipOltIdList.Contains(s.Access.Olt)
 917:                          select s.Id).ToList();
 918:   
 919:                  // services without access might be newly installed
 920:                  list2 = (from s in db.Service2
 921:                           join srs in db.ServiceRequestServices on s.Service equals srs.Service
 922:                           where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && s.Access == null && srs.Access != null && srs.Provisioned == true && sipOltIdList.Contains(srs.Access.Olt)
 923:                           select s.Id).ToList();
 924:              }
 925:   
 926:              return list.Union(list2).Distinct().ToList();
 927:          }
 928:   
 929:          ////////////////////////////////////////////////////////////////////////////
 930:   
 931:          /// <summary>
 932:          ///
 933:          /// </summary>
 934:          public static List<string> ServiceIdWithinAllowedSipOltToBeProvisionedOrMigratedList()
 935:          {
 936:              List<int> sipOltIdList;
 937:              List<string> list, list2;
 938:   
 939:              sipOltIdList = Ia.Ngn.Cl.Model.Data.Service.AllowedToBeProvisionedSipOltIdList.Union(Ia.Ngn.Cl.Model.Data.Service.AllowedToBeMigratedSipOltIdList).ToList();
 940:   
 941:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 942:              {
 943:                  // services with access
 944:                  list = (from s in db.Service2
 945:                          where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && s.Access != null && sipOltIdList.Contains(s.Access.Olt)
 946:                          select s.Id).ToList();
 947:   
 948:                  // services without access might be newly installed
 949:                  list2 = (from s in db.Service2
 950:                           join srs in db.ServiceRequestServices on s.Service equals srs.Service
 951:                           where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && s.Access == null && srs.Access != null && srs.Provisioned == true && sipOltIdList.Contains(srs.Access.Olt)
 952:                           select s.Id).ToList();
 953:              }
 954:   
 955:              return list.Union(list2).Distinct().ToList();
 956:          }
 957:   
 958:          ////////////////////////////////////////////////////////////////////////////
 959:   
 960:          /// <summary>
 961:          ///
 962:          /// </summary>
 963:          public static List<Ia.Ngn.Cl.Model.Business.ServiceAccessIpOntCreated> ServiceOntWithinAllowedSipOltToBeProvisionedOrMigratedList
 964:          {
 965:              get
 966:              {
 967:                  List<int> oltIdList;
 968:                  List<Ia.Ngn.Cl.Model.Business.ServiceAccessIpOntCreated> list1, list2, list;
 969:   
 970:                  oltIdList = Ia.Ngn.Cl.Model.Data.Service.AllowedToBeProvisionedSipOltIdList.Union(Ia.Ngn.Cl.Model.Data.Service.AllowedToBeMigratedSipOltIdList).ToList();
 971:   
 972:                  var ontAccessIdToOntForOltIdListDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntForOltIdListDictionary(oltIdList);
 973:   
 974:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 975:                  {
 976:                      // services with access
 977:                      list1 = (from s in db.Service2
 978:                               where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && s.Access != null && oltIdList.Contains(s.Access.Olt)
 979:                               select new Ia.Ngn.Cl.Model.Business.ServiceAccessIpOntCreated { ServiceId = s.Id, Service = s.Service, AccessId = s.Access.Id, CreatedDateTime = s.Created }).AsNoTracking().ToList();
 980:   
 981:                      // services without access might be newly installed
 982:                      list2 = (from s in db.Service2
 983:                               join srs in db.ServiceRequestServices on s.Service equals srs.Service
 984:                               where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && s.Access == null && srs.Access != null && srs.Provisioned == true && oltIdList.Contains(srs.Access.Olt)
 985:                               select new Ia.Ngn.Cl.Model.Business.ServiceAccessIpOntCreated { ServiceId = s.Id, Service = s.Service, AccessId = srs.Access.Id, CreatedDateTime = s.Created }).AsNoTracking().ToList();
 986:                  }
 987:   
 988:                  list = list1.Concat(list2).ToList();
 989:   
 990:                  foreach (var l in list)
 991:                  {
 992:                      l.Ont = ontAccessIdToOntForOltIdListDictionary.ContainsKey(l.AccessId) ? ontAccessIdToOntForOltIdListDictionary[l.AccessId] : null;
 993:                  }
 994:   
 995:                  return list;
 996:              }
 997:          }
 998:   
 999:          ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static Dictionary<string, int> ServiceToOltIdWithinNokiaSwitchHuaweiAccessOltListDictionary
        {
            get
            {
                List<int> oltIdList;
                Dictionary<string, int> dictionary, dictionary1, dictionary2;
 
                oltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.NokiaRouterHuaweiAccessOltIdList;
 
                using (var db = new Ia.Ngn.Cl.Model.Ngn())
                {
                    // services with access
                    dictionary1 = (from s in db.Service2
                                   where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && s.Access != null && oltIdList.Contains(s.Access.Olt)
                                   select new { s.Service, s.Access.Olt }).AsNoTracking().ToDictionary(u => u.Service, u => u.Olt);
 
                    /*
                    // services without access might be newly installed
                    dictionary2 = (from s in db.Service2
                                   join srs in db.ServiceRequestServices on s.Service equals srs.Service
                                   where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && s.Access == null && srs.Access != null && srs.Provisioned == true && oltIdList.Contains(srs.Access.Olt)
                                   select new { s.Service, s.Access.Olt }).AsNoTracking().ToDictionary(u => u.Service, u => u.Olt);
                    */
                }
 
                dictionary = dictionary1;//.Union(dictionary2).ToDictionary(u => u.Key, u => u.Value);
 
                return dictionary;
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static List<Ia.Ngn.Cl.Model.Business.ServiceAccessIpOntCreated> ServiceOntWithinAllowedToBeProvisionedOrMigratedHuaweiSwitchNokiaAccessOltList()
        {
            List<int> oltIdList;
            List<Ia.Ngn.Cl.Model.Business.ServiceAccessIpOntCreated> list1, list2, list;
 
            oltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.HuaweiSwitchNokiaAccessOltIdList;
 
            var ontAccessIdToOntForOltIdListDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntForOltIdListDictionary(oltIdList);
 
            using (var db = new Ia.Ngn.Cl.Model.Ngn())
            {
                // services with access
                list1 = (from s in db.Service2
                         where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && s.Access != null && oltIdList.Contains(s.Access.Olt)
                         select new Ia.Ngn.Cl.Model.Business.ServiceAccessIpOntCreated { ServiceId = s.Id, Service = s.Service, AccessId = s.Access.Id, CreatedDateTime = s.Created }).AsNoTracking().ToList();
 
                // services without access might be newly installed
                list2 = (from s in db.Service2
                         join srs in db.ServiceRequestServices on s.Service equals srs.Service
                         where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && s.Access == null && srs.Access != null && srs.Provisioned == true && oltIdList.Contains(srs.Access.Olt)
                         select new Ia.Ngn.Cl.Model.Business.ServiceAccessIpOntCreated { ServiceId = s.Id, Service = s.Service, AccessId = srs.Access.Id, CreatedDateTime = s.Created }).AsNoTracking().ToList();
            }
 
            list = list1.Concat(list2).ToList();
 
            foreach (var l in list)
            {
                l.Ont = ontAccessIdToOntForOltIdListDictionary.ContainsKey(l.AccessId) ? ontAccessIdToOntForOltIdListDictionary[l.AccessId] : null;
            }
 
            return list;
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static List<string> ServiceIdWithinHuaweiSwitchDomainList()
        {
            List<int> huaweiSwitchDomainList;
            List<string> list;
 
            huaweiSwitchDomainList = Ia.Ngn.Cl.Model.Data.Service.HuaweiSwitchDomainList;
 
            using (var db = new Ia.Ngn.Cl.Model.Ngn())
            {
                list = (from s in db.Service2
                        where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && huaweiSwitchDomainList.Any(u => s.Service.StartsWith(u.ToString()))
                        select s.Id).ToList();
            }
 
            return list.ToList();
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static List<string> ServiceIdWithinNokiaSwitchDomainList()
        {
            List<int> nokiaSwitchDomainList;
            List<string> list;
 
            nokiaSwitchDomainList = Ia.Ngn.Cl.Model.Data.Service.NokiaSwitchDomainList;
 
            using (var db = new Ia.Ngn.Cl.Model.Ngn())
            {
                list = (from s in db.Service2
                        where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && nokiaSwitchDomainList.Any(u => s.Service.StartsWith(u.ToString()))
                        select s.Id).ToList();
            }
 
            return list.ToList();
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static List<string> ServiceIdWithNullAccessList()
        {
            List<string> list;
 
            using (var db = new Ia.Ngn.Cl.Model.Ngn())
            {
                list = (from s in db.Service2
                        where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && s.Access == null
                        select s.Id).ToList();
            }
 
            return list;
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static List<Ia.Ngn.Cl.Model.Service2> ServiceSuspensionIsTrueList
        {
            get
            {
                List<Ia.Ngn.Cl.Model.Service2> serviceList;
 
                using (var db = new Ia.Ngn.Cl.Model.Ngn())
                {
                    serviceList = (from s in db.Service2
                                   where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && s.ServiceSuspension == true
                                   select s).ToList();
                }
 
                return serviceList;
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static int ServiceSuspensionIsTrueListCount
        {
            get
            {
                int c;
 
                using (var db = new Ia.Ngn.Cl.Model.Ngn())
                {
                    c = (from s in db.Service2
                         where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && s.ServiceSuspension == true
                         select s).Count();
                }
 
                return c;
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static List<Ia.Ngn.Cl.Model.Service2> ServiceSuspensionIsFalseList
        {
            get
            {
                List<Ia.Ngn.Cl.Model.Service2> serviceList;
 
                using (var db = new Ia.Ngn.Cl.Model.Ngn())
                {
                    serviceList = (from s in db.Service2
                                   where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && s.ServiceSuspension == false
                                   select s).ToList();
                }
 
                return serviceList;
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static List<string> ServiceSuspensionIsTrueStringNumberList
        {
            get
            {
                List<string> serviceNumberStringList;
                List<Ia.Ngn.Cl.Model.Service2> serviceList;
 
                using (var db = new Ia.Ngn.Cl.Model.Ngn())
                {
                    // below:                
                    serviceList = ServiceSuspensionIsTrueList;
 
                    if (serviceList.Count > 0)
                    {
                        serviceNumberStringList = new List<string>(serviceList.Count);
 
                        foreach (Ia.Ngn.Cl.Model.Service2 srs in serviceList)
                        {
                            serviceNumberStringList.Add(srs.Service);
                        }
                    }
                    else
                    {
                        // below: not null
                        serviceNumberStringList = new List<string>(1);
                    }
                }
 
                return serviceNumberStringList;
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static List<string> ServiceSuspensionIsFalseStringNumberList
        {
            get
            {
                List<string> serviceNumberStringList;
                List<Ia.Ngn.Cl.Model.Service2> serviceList;
 
                using (var db = new Ia.Ngn.Cl.Model.Ngn())
                {
                    // below:                
                    serviceList = ServiceSuspensionIsFalseList;
 
                    if (serviceList.Count > 0)
                    {
                        serviceNumberStringList = new List<string>(serviceList.Count);
 
                        foreach (Ia.Ngn.Cl.Model.Service2 srs in serviceList)
                        {
                            serviceNumberStringList.Add(srs.Service);
                        }
                    }
                    else
                    {
                        // below: not null
                        serviceNumberStringList = new List<string>(1);
                    }
                }
 
                return serviceNumberStringList;
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static bool IsSuspended(string service)
        {
            bool isSuspended;
 
            using (var db = new Ia.Ngn.Cl.Model.Ngn())
            {
                isSuspended = (from s in db.Service2
                               where s.Service == service && s.ServiceSuspension == true
                               select s.Service).Any();
            }
 
            return isSuspended;
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static bool HasInternationalCalling(string service)
        {
            return InternationalCallingIsAssigned(service);
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static bool InternationalCallingIsAssigned(string service)
        {
            bool isAssigned;
 
            using (var db = new Ia.Ngn.Cl.Model.Ngn())
            {
                isAssigned = (from s in db.Service2
                              where s.Service == service && s.InternationalCalling == true
                              select s.Service).Any();
            }
 
            return isAssigned;
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static Dictionary<string, string> ServiceIdToAccessIdDictionary
        {
            get
            {
                Dictionary<string, string> dictionary, nullAccessDictionary;
 
                using (var db = new Ia.Ngn.Cl.Model.Ngn())
                {
                    dictionary = (from s in db.Service2
                                  where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && s.Access != null
                                  select new { s.Id, s.Access }).AsNoTracking().ToDictionary(u => u.Id, u => u.Access.Id);
 
                    nullAccessDictionary = (from s in db.Service2
                                            where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && s.Access == null
                                            select new { s.Id, s.Access }).AsNoTracking().ToDictionary(u => u.Id, u => string.Empty);
                }
 
                return dictionary.Union(nullAccessDictionary).ToDictionary(u => u.Key, u => u.Value);
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static Dictionary<string, string> PstnServiceIdToAccessIdDictionary
        {
            get
            {
                Dictionary<string, string> dictionary, nullAccessDictionary;
 
                using (var db = new Ia.Ngn.Cl.Model.Ngn())
                {
                    dictionary = (from s in db.Service2
                                  where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.PstnService && s.Access != null
                                  select new { s.Id, s.Access }).ToDictionary(u => u.Id, u => u.Access.Id);
 
                    nullAccessDictionary = (from s in db.Service2
                                            where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.PstnService && s.Access == null
                                            select new { s.Id, s.Access }).ToDictionary(u => u.Id, u => string.Empty);
                }
 
                return dictionary.Union(nullAccessDictionary).ToDictionary(u => u.Key, u => u.Value);
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static bool NullifyAccessIdByAccessId(string accessId, out string result)
        {
            bool b;
            int numberOfRecordsWhereAccessIsNullified;
            Ia.Ngn.Cl.Model.Service2 service2;
 
            b = false;
            numberOfRecordsWhereAccessIsNullified = 0;
 
            using (var db = new Ia.Ngn.Cl.Model.Ngn())
            {
                service2 = (from s in db.Service2 where s.Access.Id == accessId select s).Include(u => u.Access).FirstOrDefault(); //.SingleOrDefault();
 
                if (service2 != null)
                {
                    service2.Access = null;
                    service2.Updated = DateTime.UtcNow.AddHours(3);
 
                    db.Service2.Attach(service2);
                    db.Entry(service2).Property(u => u.Updated).IsModified = true;
 
                    db.SaveChanges();
 
                    numberOfRecordsWhereAccessIsNullified++;
                }
 
                b = true;
            }
 
            result = "Number of records where access is nullified: " + numberOfRecordsWhereAccessIsNullified;
 
            return b;
        }
 
        ////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static Dictionary<string, string> MigratedServiceIdToAccessIdDictionary
        {
            get
            {
                Dictionary<string, string> dictionary, nullAccessDictionary;
 
                var migrationDomainList = Ia.Ngn.Cl.Model.Data.Service.MigrationDomainList;
                var migrationDomainStringList = migrationDomainList.ConvertAll<string>(delegate (int i) { return i.ToString(); });
 
                using (var db = new Ia.Ngn.Cl.Model.Ngn())
                {
                    dictionary = (from s in db.Service2
                                  where s.Access != null && migrationDomainStringList.Any(u => s.Service.StartsWith(u))
                                  select new { s.Id, s.Access }).AsNoTracking().ToDictionary(u => u.Id, u => u.Access.Id);
 
                    nullAccessDictionary = (from s in db.Service2
                                            where s.Access == null && migrationDomainStringList.Any(u => s.Service.StartsWith(u))
                                            select new { s.Id, s.Access }).AsNoTracking().ToDictionary(u => u.Id, u => string.Empty);
                }
 
                return dictionary.Union(nullAccessDictionary).ToDictionary(u => u.Key, u => u.Value);
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static Dictionary<string, string> MigratedServiceIdToAccessIdInAllowedToBeMigratedOltDictionary
        {
            get
            {
                Dictionary<string, string> dictionary;
 
                var allowedToBeMigratedOltIdList = Ia.Ngn.Cl.Model.Data.Service.AllowedToBeMigratedOltIdList;
 
                var migrationDomainList = Ia.Ngn.Cl.Model.Data.Service.MigrationDomainList;
                var migrationDomainStringList = migrationDomainList.ConvertAll<string>(delegate (int i) { return i.ToString(); });
 
                using (var db = new Ia.Ngn.Cl.Model.Ngn())
                {
                    dictionary = (from s in db.Service2
                                  where s.Access != null && migrationDomainStringList.Any(u => s.Service.StartsWith(u)) && allowedToBeMigratedOltIdList.Contains(s.Access.Olt) && s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService
                                  select new { s.Id, s.Access }).ToDictionary(u => u.Id, u => u.Access.Id);
                }
 
                return dictionary.ToDictionary(u => u.Key, u => u.Value);
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static List<string> ImsServiceInAllowedToBeMigratedOltList
        {
            get
            {
                List<string> list;
 
                var allowedToBeMigratedOltIdList = Ia.Ngn.Cl.Model.Data.Service.AllowedToBeMigratedOltIdList;
 
                var migrationDomainList = Ia.Ngn.Cl.Model.Data.Service.MigrationDomainList;
                var migrationDomainStringList = migrationDomainList.ConvertAll<string>(delegate (int i) { return i.ToString(); });
 
                using (var db = new Ia.Ngn.Cl.Model.Ngn())
                {
                    var list0 = (from s in db.Service2
                                 where s.Access != null && s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService
                                 select new { s.Service, AccessOlt = s.Access.Olt }).AsNoTracking().ToList();
 
                    list = (from l in list0
                            where migrationDomainStringList.Any(u => l.Service.StartsWith(u)) && allowedToBeMigratedOltIdList.Contains(l.AccessOlt)
                            select l.Service).ToList();
                }
 
                return list;
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static Dictionary<string, string> ImsServiceToAccessIdInAllowedToBeMigratedOltDictionary
        {
            get
            {
                Dictionary<string, string> dictionary;
 
                var allowedToBeMigratedOltIdList = Ia.Ngn.Cl.Model.Data.Service.AllowedToBeMigratedOltIdList;
 
                var migrationDomainList = Ia.Ngn.Cl.Model.Data.Service.MigrationDomainList;
                var migrationDomainStringList = migrationDomainList.ConvertAll<string>(delegate (int i) { return i.ToString(); });
 
                using (var db = new Ia.Ngn.Cl.Model.Ngn())
                {
                    var list = (from s in db.Service2
                                where s.Access != null && s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService
                                select new { s.Service, AccessId = s.Access.Id, AccessOlt = s.Access.Olt }).AsNoTracking().ToList();
 
                    dictionary = (from l in list
                                  where migrationDomainStringList.Any(u => l.Service.StartsWith(u)) && allowedToBeMigratedOltIdList.Contains(l.AccessOlt)
                                  select l).ToDictionary(u => u.Service, u => u.AccessId);
                }
 
                return dictionary.ToDictionary(u => u.Key, u => u.Value);
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static List<string> MsanServiceInAllowedToBeMigratedDomainList
        {
            get
            {
                List<string> list;
 
                var migrationDomainList = Ia.Ngn.Cl.Model.Data.Service.MigrationDomainList;
                var migrationDomainStringList = migrationDomainList.ConvertAll<string>(delegate (int i) { return i.ToString(); });
 
                var msanServiceList = Ia.Ngn.Cl.Model.Data.Service2.MsanServiceList;
 
                list = (from l in msanServiceList
                        where migrationDomainStringList.Any(u => l.StartsWith(u))
                        select l).ToList();
 
                return list;
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static Dictionary<string, string> ServiceToAccessIdDictionary
        {
            get
            {
                string key;
                Dictionary<string, string> serviceToAccessIdDictionary, serviceIdToAccessIdDictionary;
 
                serviceIdToAccessIdDictionary = ServiceIdToAccessIdDictionary;
 
                serviceToAccessIdDictionary = new Dictionary<string, string>(serviceIdToAccessIdDictionary.Count);
 
                foreach (KeyValuePair<string, string> kvp in serviceIdToAccessIdDictionary)
                {
                    key = Ia.Ngn.Cl.Model.Business.Service.ServiceIdToService(kvp.Key);
 
                    serviceToAccessIdDictionary[key] = kvp.Value;
                }
 
                return serviceToAccessIdDictionary;
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static Dictionary<string, string> ServiceIdToAccessNameDictionary
        {
            get
            {
                Dictionary<string, string> dictionary, nullAccessDictionary;
 
                using (var db = new Ia.Ngn.Cl.Model.Ngn())
                {
                    dictionary = (from s in db.Service2
                                  where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && s.Access != null
                                  select new { s.Id, s.Access }).ToDictionary(u => u.Id, u => u.Access.Name);
 
                    nullAccessDictionary = (from s in db.Service2
                                            where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && s.Access == null
                                            select s.Id).ToDictionary(u => u, null);
                }
 
                return dictionary.Union(nullAccessDictionary).ToDictionary(u => u.Key, u => u.Value);
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static Dictionary<string, int> AccessNameToSeviceCountDictionary()
        {
            string accessName;
            Dictionary<string, int> dictionary;
 
            using (var db = new Ia.Ngn.Cl.Model.Ngn())
            {
                var accessIdToAccessNameDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntAccessNameDictionary;
 
                var serviceToAccessIdDictionary = (from s in db.Service2
                                                   where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && s.Access != null
                                                   select new { s.Service, AccessId = s.Access.Id }).ToDictionary(u => u.Service, u => u.AccessId);
 
                dictionary = new Dictionary<string, int>(serviceToAccessIdDictionary.Count);
 
                foreach (var accessName0 in accessIdToAccessNameDictionary.Values)
                {
                    dictionary[accessName0] = 0;
                }
 
                foreach (KeyValuePair<string, string> kvp in serviceToAccessIdDictionary)
                {
                    accessName = accessIdToAccessNameDictionary[kvp.Value];
 
                    if (!string.IsNullOrEmpty(accessName))
                    {
                        if (dictionary.ContainsKey(accessName))
                        {
                            dictionary[accessName] = dictionary[accessName] + 1;
                        }
                        else dictionary[accessName] = 1;
                    }
                }
            }
 
            return dictionary.ToDictionary(u => u.Key, u => u.Value);
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static Dictionary<string, List<string>> OntAccessIdToSeviceListDictionary()
        {
            string service, accessId;
            Dictionary<string, List<string>> dictionary;
 
            using (var db = new Ia.Ngn.Cl.Model.Ngn())
            {
                var ontAccessIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdList;
 
                var serviceToAccessIdDictionary = (from s in db.Service2
                                                   where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && s.Access != null
                                                   select new { s.Service, AccessId = s.Access.Id }).ToDictionary(u => u.Service, u => u.AccessId);
 
                dictionary = new Dictionary<string, List<string>>(serviceToAccessIdDictionary.Count);
 
                foreach (var ontAccessId in ontAccessIdList) dictionary[ontAccessId] = new List<string>();
 
                foreach (var kvp in serviceToAccessIdDictionary)
                {
                    service = kvp.Key;
                    accessId = kvp.Value;
 
                    dictionary[accessId].Add(service);
                }
            }
 
            return dictionary;
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont> ServiceToNddOntDictionary
        {
            get
            {
                string key;
                Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont> dictionary;
 
                var serviceIdToAccessIdDictionary = Ia.Ngn.Cl.Model.Data.Service2.ServiceIdToAccessIdDictionary;
                var ontAccessIdToOntDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntDictionary;
 
                dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont>(serviceIdToAccessIdDictionary.Count);
 
                foreach (KeyValuePair<string, string> kvp in serviceIdToAccessIdDictionary)
                {
                    key = Ia.Ngn.Cl.Model.Business.Service.ServiceIdToService(kvp.Key);
 
                    if (!string.IsNullOrEmpty(kvp.Value)) dictionary[key] = ontAccessIdToOntDictionary[kvp.Value];
                    else dictionary[key] = null;
                }
 
                return dictionary;
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont> PstnServiceToNddOntDictionary
        {
            get
            {
                string key;
                Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont> dictionary;
 
                var pstnServiceIdToAccessIdDictionary = Ia.Ngn.Cl.Model.Data.Service2.PstnServiceIdToAccessIdDictionary;
                var ontAccessIdToOntDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntDictionary;
 
                dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont>(pstnServiceIdToAccessIdDictionary.Count);
 
                foreach (KeyValuePair<string, string> kvp in pstnServiceIdToAccessIdDictionary)
                {
                    key = Ia.Ngn.Cl.Model.Business.Service.ServiceIdToService(kvp.Key);
 
                    if (!string.IsNullOrEmpty(kvp.Value)) dictionary[key] = ontAccessIdToOntDictionary[kvp.Value];
                    //else dictionary[key] = null;
                }
 
                return dictionary;
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor> MigratedServiceToNddOntRouterVendorDictionary
        {
            get
            {
                string key;
                Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor> dictionary;
 
                var migratedServiceIdToAccessIdDictionary = Ia.Ngn.Cl.Model.Data.Service2.MigratedServiceIdToAccessIdDictionary;
                var ontAccessIdToOntDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntDictionary;
 
                dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor>(migratedServiceIdToAccessIdDictionary.Count);
 
                foreach (KeyValuePair<string, string> kvp in migratedServiceIdToAccessIdDictionary)
                {
                    key = Ia.Ngn.Cl.Model.Business.Service.ServiceIdToService(kvp.Key);
 
                    //if (!string.IsNullOrEmpty(kvp.Value)) dictionary[key] = ontAccessIdToOntDictionary[kvp.Value];
                    //else dictionary[key] = null;
                }
 
                return dictionary;
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site> ServiceToSiteDictionary
        {
            get
            {
                int fourLetterServiceDomain, fiveLetterServiceDomain;
                string service;
                Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site> dictionary;
 
                var serviceIdList = Ia.Ngn.Cl.Model.Data.Service2.ServiceIdList;
                var routerDomainToSiteDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.RouterDomainToSiteDictionary;
 
                dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site>(serviceIdList.Count);
 
                foreach (string s in serviceIdList)
                {
                    service = Ia.Ngn.Cl.Model.Business.Service.ServiceIdToService(s);
 
                    if (service.Length >= 5)
                    {
                        fourLetterServiceDomain = int.Parse(service.Substring(0, 4));
                        fiveLetterServiceDomain = int.Parse(service.Substring(0, 5));
 
                        if (routerDomainToSiteDictionary.ContainsKey(fiveLetterServiceDomain)) dictionary[service] = routerDomainToSiteDictionary[fiveLetterServiceDomain];
                        else if (routerDomainToSiteDictionary.ContainsKey(fourLetterServiceDomain)) dictionary[service] = routerDomainToSiteDictionary[fourLetterServiceDomain];
                        //else throw new System.ArgumentOutOfRangeException("Service number " + service + " is out of range");
                    }
                    //else throw new System.ArgumentOutOfRangeException("Service number " + service + " is out of range");
                }
 
                return dictionary;
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site> ImsServiceToSiteDictionary
        {
            get
            {
                int fourLetterServiceDomain, fiveLetterServiceDomain;
                string service;
                Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site> dictionary;
 
                var serviceIdList = Ia.Ngn.Cl.Model.Data.Service2.ImsServiceIdList;
                var routerDomainToSiteDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.RouterDomainToSiteDictionary;
 
                dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site>(serviceIdList.Count);
 
                foreach (string s in serviceIdList)
                {
                    service = Ia.Ngn.Cl.Model.Business.Service.ServiceIdToService(s);
 
                    if (service.Length >= 5)
                    {
                        fourLetterServiceDomain = int.Parse(service.Substring(0, 4));
                        fiveLetterServiceDomain = int.Parse(service.Substring(0, 5));
 
                        if (routerDomainToSiteDictionary.ContainsKey(fiveLetterServiceDomain)) dictionary[service] = routerDomainToSiteDictionary[fiveLetterServiceDomain];
                        else if (routerDomainToSiteDictionary.ContainsKey(fourLetterServiceDomain)) dictionary[service] = routerDomainToSiteDictionary[fourLetterServiceDomain];
                        //else throw new System.ArgumentOutOfRangeException("Service number " + service + " is out of range");
                    }
                    //else throw new System.ArgumentOutOfRangeException("Service number " + service + " is out of range");
                }
 
                return dictionary;
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site> MsanServiceToSiteDictionary
        {
            get
            {
                Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site> dictionary;
 
                var imsServiceToSiteDictionary = Ia.Ngn.Cl.Model.Data.Service2.ImsServiceToSiteDictionary;
 
                var msanServiceList = Ia.Ngn.Cl.Model.Data.Service2.MsanServiceList;
 
                dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site>(msanServiceList.Count);
 
                foreach (string service in msanServiceList)
                {
                    if (imsServiceToSiteDictionary.ContainsKey(service)) // I had to add this because the systems sees 2489 numbers in MSAN
                    {
                        dictionary[service] = imsServiceToSiteDictionary[service];
                    }
                }
 
                return dictionary;
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site> MsanServiceToSiteInAllowedToBeMigratedDomainListDictionary
        {
            get
            {
                Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site> dictionary;
 
                var msanServiceInAllowedToBeMigratedDomainList = Ia.Ngn.Cl.Model.Data.Service2.MsanServiceInAllowedToBeMigratedDomainList;
                var msanServiceToSiteDictionary = Ia.Ngn.Cl.Model.Data.Service2.MsanServiceToSiteDictionary;
 
                dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site>(msanServiceInAllowedToBeMigratedDomainList.Count);
 
                foreach (string service in msanServiceInAllowedToBeMigratedDomainList)
                {
                    if (msanServiceToSiteDictionary.ContainsKey(service)) // I had to add this because the systems sees 2489 numbers in MSAN
                    {
                        dictionary[service] = msanServiceToSiteDictionary[service];
                    }
                }
 
                return dictionary;
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site> PstnServiceToSiteDictionary
        {
            get
            {
                int fourLetterServiceDomain, fiveLetterServiceDomain;
                string service;
                Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site> dictionary;
 
                var serviceIdList = Ia.Ngn.Cl.Model.Data.Service2.PstnServiceIdList;
                var routerDomainToSiteDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.RouterDomainToSiteDictionary;
 
                dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site>(serviceIdList.Count);
 
                foreach (string s in serviceIdList)
                {
                    service = Ia.Ngn.Cl.Model.Business.Service.ServiceIdToService(s);
 
                    if (service.Length >= 5)
                    {
                        fourLetterServiceDomain = int.Parse(service.Substring(0, 4));
                        fiveLetterServiceDomain = int.Parse(service.Substring(0, 5));
 
                        if (routerDomainToSiteDictionary.ContainsKey(fiveLetterServiceDomain)) dictionary[service] = routerDomainToSiteDictionary[fiveLetterServiceDomain];
                        else if (routerDomainToSiteDictionary.ContainsKey(fourLetterServiceDomain)) dictionary[service] = routerDomainToSiteDictionary[fourLetterServiceDomain];
                        //else throw new System.ArgumentOutOfRangeException("Service number " + service + " is out of range");
                    }
                    //else throw new System.ArgumentOutOfRangeException("Service number " + service + " is out of range");
                }
 
                return dictionary;
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static Dictionary<string, string> ServiceNotInServiceRequestServiceToSiteDictionary
        {
            get
            {
                string service, siteName;
                Dictionary<string, string> dictionary;
 
                var serviceToSiteNameDictionary = Ia.Ngn.Cl.Model.Data.Service2.ServiceToSiteDictionary;
                var serviceRequestServiceServiceToSiteNameDictionary = Ia.Ngn.Cl.Model.Data.ServiceRequestService.ServiceToSiteDictionary;
 
                dictionary = new Dictionary<string, string>();
 
                foreach (var kvp in serviceToSiteNameDictionary)
                {
                    service = kvp.Key;
                    siteName = kvp.Value.Name;
 
                    if (!serviceRequestServiceServiceToSiteNameDictionary.ContainsKey(service)) dictionary.Add(service, siteName);
                }
 
                return dictionary;
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static Dictionary<string, string> ServiceNotInProvisionedServiceRequestServiceToSiteDictionary
        {
            get
            {
                string service, siteName;
                Dictionary<string, string> dictionary;
 
                var serviceToSiteNameDictionary = Ia.Ngn.Cl.Model.Data.Service2.ServiceToSiteDictionary;
                var serviceRequestServiceProvisionedServiceToSiteNameDictionary = Ia.Ngn.Cl.Model.Data.ServiceRequestService.ProvisionedServiceToSiteDictionary;
 
                dictionary = new Dictionary<string, string>();
 
                foreach (var kvp in serviceToSiteNameDictionary)
                {
                    service = kvp.Key;
                    siteName = kvp.Value.Name;
 
                    if (!serviceRequestServiceProvisionedServiceToSiteNameDictionary.ContainsKey(service)) dictionary.Add(service, siteName);
                }
 
                return dictionary;
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static Dictionary<string, string> ImsServiceNotInProvisionedServiceRequestServiceToSiteDictionary
        {
            get
            {
                string service, siteName;
                Dictionary<string, string> dictionary;
 
                var serviceToSiteNameDictionary = Ia.Ngn.Cl.Model.Data.Service2.ImsServiceToSiteDictionary;
                var serviceRequestServiceProvisionedServiceToSiteNameDictionary = Ia.Ngn.Cl.Model.Data.ServiceRequestService.ProvisionedServiceToSiteDictionary;
 
                var doesNotExistInSrsList = Ia.Ngn.Cl.Model.Data.Service2.ServiceImsServicesThatDoNotExistInServiceRequestServicesList();
 
                dictionary = new Dictionary<string, string>();
 
                foreach (var kvp in serviceToSiteNameDictionary)
                {
                    service = kvp.Key;
                    siteName = kvp.Value.Name;
 
                    if (!serviceRequestServiceProvisionedServiceToSiteNameDictionary.ContainsKey(service))
                    {
                        if (!doesNotExistInSrsList.Contains(service))
                        {
                            dictionary.Add(service, siteName);
                        }
                    }
                }
 
                return dictionary;
            }
        }
 
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static List<string> ServiceImsServicesThatDoNotExistInServiceRequestServicesList()
        {
            List<string> list;
 
            using (var db = new Ia.Ngn.Cl.Model.Ngn())
            {
                /*
select s.Service from Service2 s
left outer join ServiceRequestServices srs on srs.Service = s.Service
where s.ServiceType = 1 and srs.Id is null
                 */
 
                list = (from s in db.Service2
                        join srs in db.ServiceRequestServices on s.Service equals srs.Service into srs2
                        from srs3 in srs2.DefaultIfEmpty()
                        where srs3 == null && s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService
                        select s.Service).ToList();
            }
 
            return list;
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static Dictionary<string, string> PstnServiceNotInProvisionedServiceRequestServiceToSiteDictionary
        {
            get
            {
                string service, siteName;
                Dictionary<string, string> dictionary;
 
                var serviceToSiteNameDictionary = Ia.Ngn.Cl.Model.Data.Service2.PstnServiceToSiteDictionary;
                var serviceRequestServiceProvisionedServiceToSiteNameDictionary = Ia.Ngn.Cl.Model.Data.ServiceRequestService.ProvisionedServiceToSiteDictionary;
 
                var doesNotExistInSrsList = Ia.Ngn.Cl.Model.Data.Service2.ServiceImsServicesThatDoNotExistInServiceRequestServicesList();
 
                dictionary = new Dictionary<string, string>();
 
                foreach (var kvp in serviceToSiteNameDictionary)
                {
                    service = kvp.Key;
                    siteName = kvp.Value.Name;
 
                    if (!serviceRequestServiceProvisionedServiceToSiteNameDictionary.ContainsKey(service))
                    {
                        if (!doesNotExistInSrsList.Contains(service))
                        {
                            dictionary.Add(service, siteName);
                        }
                    }
                }
 
                return dictionary;
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static Dictionary<string, int> PstnFiveDigitDomainToCountOfServicesDictionary()
        {
            var dictionary = new Dictionary<string, int>();
 
            using (var db = new Ia.Ngn.Cl.Model.Ngn())
            {
                /*
select substring(s.Service,1,5), count(s.Service)
from Service2 s
where ServiceType = 2 -- PSTN
group by substring(s.Service,1,5)
                 */
 
                dictionary = (from s in db.Service2
                              where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.PstnService
                              group s.Service.Substring(0, 5) by s.Service.Substring(0, 5) into g
                              select new { PstnFiveDigitDomain = g.Key, ServiceCount = g.Count() }).AsNoTracking().ToDictionary(t => t.PstnFiveDigitDomain, t => t.ServiceCount);
            }
 
            return dictionary;
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static void UpdatePstnServiceAccess(string service, string newAccessId, Guid userId, out Ia.Cl.Model.Result result)
        {
            int serviceType;
            string service2Id;
            Ia.Ngn.Cl.Model.Service2 service2;
 
            result = new Ia.Cl.Model.Result();
 
            serviceType = Ia.Ngn.Cl.Model.Business.Service.ServiceType.PstnService; // PSTN
            service2Id = Ia.Ngn.Cl.Model.Business.Service2.ServiceId(service, serviceType);
 
            using (var db = new Ia.Ngn.Cl.Model.Ngn())
            {
                service2 = (from s in db.Service2 where s.Id == service2Id select s).SingleOrDefault();
 
                if (service2 != null)
                {
                    if (!string.IsNullOrEmpty(newAccessId))
                    {
                        if (service2.Access == null || service2.Access != null && service2.Access.Id != newAccessId)
                        {
                            service2.Access = (from a in db.Accesses where a.Id == newAccessId select a).SingleOrDefault();
                            service2.UserId = userId;
 
                            db.Service2.Attach(service2);
                            db.Entry(service2).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
 
                            db.SaveChanges();
 
                            result.AddSuccess("Service " + service + " was updated with access " + service2.Access.Name + " (تم تحديث ربط الجهاز بالرقم). ");
                        }
                        else
                        {
                            result.AddWarning("Service access value was not updated because submitted data is the same as current data and because access is not null (لم يتم تغيير الجهاز المربوط بالرقم لأن المعلومات المعطاة هي ذاتها لم تتغير ولأن الجهاز معرف). ");
                        }
                    }
                    else //if(string.IsNullOrEmpty(updatedAccessId))
                    {
                        if (service2.Access != null)
                        {
                            service2.Access = (from a in db.Accesses where a.Id == string.Empty select a).SingleOrDefault();
                            service2.Port = Ia.Ngn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown;
                            service2.UserId = userId;
 
                            db.Service2.Attach(service2);
                            db.Entry(service2).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
 
                            db.SaveChanges();
 
                            result.AddSuccess("Service " + service + " was updated with null access and " + Ia.Ngn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown + " port (تم مسح ربط الجهاز بالرقم ومسح المنفذ). ");
                        }
                        else
                        {
                            result.AddWarning("Service access and port values were not reset because submitted data (access null and port " + Ia.Ngn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown + ") is the same as current data (لم يتم تغيير الجهاز المربوط بالرقم أو المنفذ لأن المعلومات المعطاة هي ذاتها لم تتغير). ");
                        }
                    }
                }
                else
                {
                    result.AddWarning("Service " + service + " does not exist (رقم الخدمة غير موجود). ");
                }
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static void UpdateImsServiceAccessAndPort(string service, string accessId, int port, Guid userId, out Ia.Cl.Model.Result result)
        {
            int serviceType;
            string service2Id;
            Ia.Ngn.Cl.Model.Service2 service2;
 
            result = new Ia.Cl.Model.Result();
 
            serviceType = Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService;
            service2Id = Ia.Ngn.Cl.Model.Business.Service2.ServiceId(service, serviceType);
 
            using (var db = new Ia.Ngn.Cl.Model.Ngn())
            {
                service2 = (from s in db.Service2 where s.Id == service2Id select s).Include(s => s.Access).SingleOrDefault();
 
                if (service2 != null)
                {
                    if (!string.IsNullOrEmpty(accessId))
                    {
                        if (service2.Access == null || service2.Access != null && (service2.Access.Id != accessId || service2.Port != port))
                        {
                            service2.Access = (from a in db.Accesses where a.Id == accessId select a).SingleOrDefault();
                            service2.Port = port;
                            service2.UserId = userId;
 
                            db.Service2.Attach(service2);
                            db.Entry(service2).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
 
                            db.SaveChanges();
 
                            result.AddSuccess("Service " + service + " was updated with access " + service2.Access.Name + " and port " + port);
                        }
                        else
                        {
                            result.AddWarning("Service access not updated");
                        }
                    }
                    else
                    {
                        if (service2.Access != null)
                        {
                            service2.Access = (from a in db.Accesses where a.Id == string.Empty select a).SingleOrDefault();
                            service2.Port = Ia.Ngn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown;
                            service2.UserId = userId;
 
                            db.Service2.Attach(service2);
                            db.Entry(service2).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
 
                            db.SaveChanges();
 
                            result.AddSuccess("Service " + service + " was updated with null access and " + Ia.Ngn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown + " port.");
                        }
                        else
                        {
                            result.AddWarning("Service access not reset.");
                        }
                    }
                }
                else
                {
                    result.AddWarning("Service " + service + " does not exist.");
                }
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static void ProvisioningStateOfServicesWithinPstnSite(int siteId, out List<string> provisionedServiceList, out List<string> unprovisionedServiceList)
        {
            var site = (from s in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.PstnList
                        where s.Id == siteId
                        select s).SingleOrDefault();
 
            if (site != null)
            {
                provisionedServiceList = new List<string>();
                unprovisionedServiceList = new List<string>();
 
                using (var db = new Ia.Ngn.Cl.Model.Ngn())
                {
                    var provisionedService0List = (from s in db.Service2
                                                   join srs in db.ServiceRequestServices on s.Service equals srs.Service
                                                   where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.PstnService && srs.Provisioned == true
                                                   select s.Service).AsNoTracking().ToList();
 
                    foreach (var s in provisionedService0List)
                    {
                        if (site.DomainList.Any(u => s.StartsWith(u.ToString()))) provisionedServiceList.Add(s);
                    }
 
                    var unprovisionedService0List = (from s in db.Service2
                                                     join srs in db.ServiceRequestServices on s.Service equals srs.Service
                                                     where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.PstnService && srs.Provisioned == false
                                                     select s.Service).AsNoTracking().ToList();
 
                    foreach (var s in unprovisionedService0List)
                    {
                        if (site.DomainList.Any(u => s.StartsWith(u.ToString()))) unprovisionedServiceList.Add(s);
                    }
                }
            }
            else
            {
                provisionedServiceList = new List<string>();
                unprovisionedServiceList = new List<string>();
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////
    }
 
    ////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////
}