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

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

Service support class for Fixed Telecommunications Network (FTN) 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.Ftn.Cl.Models.Data
   10: {
   11:     ////////////////////////////////////////////////////////////////////////////
   12:  
   13:     /// <summary publish="true">
   14:     /// Service support class for Fixed Telecommunications Network (FTN) 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:     /// </remarks> 
   20:     public class Service2
   21:     {
   22:         public Service2() { }
   23:  
   24:         ////////////////////////////////////////////////////////////////////////////
   25:  
   26:         /// <summary>
   27:         ///
   28:         /// </summary>
   29:         public static Ia.Ftn.Cl.Models.Service2 Read(string service)
   30:         {
   31:             Ia.Ftn.Cl.Models.Service2 service2;
   32:  
   33:             using (var db = new Ia.Ftn.Cl.Db())
   34:             {
   35:                 service2 = (from s in db.Service2
   36:                             where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && s.Service == service
   37:                             select s).SingleOrDefault();
   38:             }
   39:  
   40:             return service2;
   41:         }
   42:  
   43:         ////////////////////////////////////////////////////////////////////////////
   44:  
   45:         /// <summary>
   46:         ///
   47:         /// </summary>
   48:         public static List<Ia.Ftn.Cl.Models.Service2> ReadList(List<string> serviceList)
   49:         {
   50:             List<Ia.Ftn.Cl.Models.Service2> list;
   51:  
   52:             using (var db = new Ia.Ftn.Cl.Db())
   53:             {
   54:                 if (serviceList.Count > 0)
   55:                 {
   56:                     list = (from s in db.Service2
   57:                             where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && serviceList.Contains(s.Service)
   58:                             select s).ToList();
   59:                 }
   60:                 else list = new List<Ia.Ftn.Cl.Models.Service2>();
   61:             }
   62:  
   63:             return list;
   64:         }
   65:  
   66:         ////////////////////////////////////////////////////////////////////////////
   67:  
   68:         /// <summary>
   69:         ///
   70:         /// </summary>
   71:         public static Ia.Ftn.Cl.Models.Service2 ReadMsan(string service)
   72:         {
   73:             Ia.Ftn.Cl.Models.Service2 service2;
   74:  
   75: #if DEBUG
   76:             var dummyVarToDrawRefractorToBelow = Ia.Ftn.Cl.Models.Business.NumberFormatConverter.Dn("0000000");
   77: #endif
   78:  
   79:             using (var db = new Ia.Ftn.Cl.Db())
   80:             {
   81:                 service2 = (from s in db.Service2
   82:                             join evpu in db.EmsVoipPstnUsers on "+965" + s.Service equals evpu.DN // see: Ia.Ftn.Cl.Model.Business.NumberFormatConverter.Dn()
   83:                             where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && s.Service == service
   84:                             select s).SingleOrDefault();
   85:             }
   86:  
   87:             return service2;
   88:         }
   89:  
   90:         ////////////////////////////////////////////////////////////////////////////
   91:  
   92:         /// <summary>
   93:         ///
   94:         /// </summary>
   95:         public static List<Ia.Ftn.Cl.Models.Service2> ReadMsanList(List<string> serviceList)
   96:         {
   97:             List<Ia.Ftn.Cl.Models.Service2> list;
   98:  
   99: #if DEBUG
  100:             var dummyVarToDrawRefractorToBelow = Ia.Ftn.Cl.Models.Business.NumberFormatConverter.Dn("0000000");
  101: #endif
  102:  
  103:             using (var db = new Ia.Ftn.Cl.Db())
  104:             {
  105:                 if (serviceList.Count > 0)
  106:                 {
  107:                     list = (from s in db.Service2
  108:                             join evpu in db.EmsVoipPstnUsers on "+965" + s.Service equals evpu.DN // see: Ia.Ftn.Cl.Model.Business.NumberFormatConverter.Dn()
  109:                             where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && serviceList.Contains(s.Service)
  110:                             select s).ToList();
  111:  
  112:                 }
  113:                 else list = new List<Ia.Ftn.Cl.Models.Service2>();
  114:             }
  115:  
  116:             return list;
  117:         }
  118:  
  119:         ////////////////////////////////////////////////////////////////////////////
  120:  
  121:         /// <summary>
  122:         ///
  123:         /// </summary>
  124:         public static Ia.Ftn.Cl.Models.Service2 ReadPstn(string service)
  125:         {
  126:             Ia.Ftn.Cl.Models.Service2 service2;
  127:  
  128:             using (var db = new Ia.Ftn.Cl.Db())
  129:             {
  130:                 service2 = (from s in db.Service2
  131:                             where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.PstnService && s.Service == service
  132:                             select s).SingleOrDefault();
  133:             }
  134:  
  135:             return service2;
  136:         }
  137:  
  138:         ////////////////////////////////////////////////////////////////////////////
  139:  
  140:         /// <summary>
  141:         ///
  142:         /// </summary>
  143:         public static List<Ia.Ftn.Cl.Models.Service2> ReadPstnList(List<string> serviceList)
  144:         {
  145:             List<Ia.Ftn.Cl.Models.Service2> list;
  146:  
  147:             using (var db = new Ia.Ftn.Cl.Db())
  148:             {
  149:                 if (serviceList.Count > 0)
  150:                 {
  151:                     list = (from s in db.Service2
  152:                             where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.PstnService && serviceList.Contains(s.Service)
  153:                             select s).ToList();
  154:                 }
  155:                 else list = new List<Ia.Ftn.Cl.Models.Service2>();
  156:             }
  157:  
  158:             return list;
  159:         }
  160:  
  161:         ////////////////////////////////////////////////////////////////////////////
  162:  
  163:         /// <summary>
  164:         ///
  165:         /// </summary>
  166:         public static Ia.Ftn.Cl.Models.Service2 Read(long number)
  167:         {
  168:             Ia.Ftn.Cl.Models.Service2 service;
  169:  
  170:             using (var db = new Ia.Ftn.Cl.Db())
  171:             {
  172:                 service = (from s in db.Service2
  173:                            where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && s.Service == number.ToString()
  174:                            select s).SingleOrDefault();
  175:             }
  176:  
  177:             return service;
  178:         }
  179:  
  180:         ////////////////////////////////////////////////////////////////////////////
  181:  
  182:         /// <summary>
  183:         ///
  184:         /// </summary>
  185:         public static Ia.Ftn.Cl.Models.Service2 ReadByIdIncludeAccess(string serviceId)
  186:         {
  187:             Ia.Ftn.Cl.Models.Service2 service2;
  188:  
  189:             using (var db = new Ia.Ftn.Cl.Db())
  190:             {
  191:                 service2 = (from s in db.Service2.Include(a => a.Access)
  192:                             where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && s.Id == serviceId
  193:                             select s).AsNoTracking().SingleOrDefault();
  194:             }
  195:  
  196:             return service2;
  197:         }
  198:  
  199:         ////////////////////////////////////////////////////////////////////////////
  200:  
  201:         /// <summary>
  202:         ///
  203:         /// </summary>
  204:         public static Ia.Ftn.Cl.Models.Service2 ReadWithAccess(string service)
  205:         {
  206:             Ia.Ftn.Cl.Models.Service2 service2;
  207:  
  208:             using (var db = new Ia.Ftn.Cl.Db())
  209:             {
  210:                 service2 = (from s in db.Service2.Include(a => a.Access)
  211:                             where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && s.Service == service
  212:                             select s).SingleOrDefault();
  213:             }
  214:  
  215:             return service2;
  216:         }
  217:  
  218:         ////////////////////////////////////////////////////////////////////////////
  219:  
  220:         /// <summary>
  221:         ///
  222:         /// </summary>
  223:         public static List<Ia.Ftn.Cl.Models.Service2> List()
  224:         {
  225:             List<Ia.Ftn.Cl.Models.Service2> serviceList;
  226:  
  227:             using (var db = new Ia.Ftn.Cl.Db())
  228:             {
  229:                 serviceList = (from s in db.Service2
  230:                                where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService
  231:                                select s).ToList();
  232:             }
  233:  
  234:             return serviceList;
  235:         }
  236:  
  237:         ////////////////////////////////////////////////////////////////////////////
  238:  
  239:         /// <summary>
  240:         ///
  241:         /// </summary>
  242:         public static List<string> List(List<int> domainList)
  243:         {
  244:             List<string> stringDomainList;
  245:             List<string> serviceList;
  246:  
  247:             using (var db = new Ia.Ftn.Cl.Db())
  248:             {
  249:                 if (domainList.Count > 0)
  250:                 {
  251:                     stringDomainList = new List<string>();
  252:  
  253:                     foreach (int i in domainList) stringDomainList.Add(i.ToString());
  254:  
  255:                     serviceList = (from s in db.Service2
  256:                                    where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && stringDomainList.Any(u => s.Service.StartsWith(u.ToString()))
  257:                                    select s.Service).ToList();
  258:                 }
  259:                 else serviceList = new List<string>();
  260:             }
  261:  
  262:             return serviceList;
  263:         }
  264:  
  265:         ////////////////////////////////////////////////////////////////////////////
  266:  
  267:         /// <summary>
  268:         ///
  269:         /// </summary>
  270:         public static List<string> ServiceList
  271:         {
  272:             get
  273:             {
  274:                 List<string> list;
  275:  
  276:                 using (var db = new Ia.Ftn.Cl.Db())
  277:                 {
  278:                     list = (from s in db.Service2
  279:                             where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService
  280:                             select s.Service).ToList();
  281:                 }
  282:  
  283:                 return list;
  284:             }
  285:         }
  286:  
  287:         ////////////////////////////////////////////////////////////////////////////
  288:  
  289:         /// <summary>
  290:         ///
  291:         /// </summary>
  292:         public static List<string> ImsServiceList
  293:         {
  294:             get
  295:             {
  296:                 List<string> list;
  297:  
  298:                 using (var db = new Ia.Ftn.Cl.Db())
  299:                 {
  300:                     list = (from s in db.Service2
  301:                             where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService
  302:                             select s.Service).ToList();
  303:                 }
  304:  
  305:                 return list;
  306:             }
  307:         }
  308:  
  309:         ////////////////////////////////////////////////////////////////////////////
  310:  
  311:         /// <summary>
  312:         ///
  313:         /// </summary>
  314:         public static bool IsImsService(string service)
  315:         {
  316:             bool isImsService;
  317:  
  318:             using (var db = new Ia.Ftn.Cl.Db())
  319:             {
  320:                 isImsService = (from s in db.Service2
  321:                                 where s.Service == service && s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService
  322:                                 select s.Service).Any();
  323:             }
  324:  
  325:             return isImsService;
  326:         }
  327:  
  328:         ////////////////////////////////////////////////////////////////////////////
  329:  
  330:         /// <summary>
  331:         ///
  332:         /// </summary>
  333:         public static List<string> ImsServiceWithAccessNullList
  334:         {
  335:             get
  336:             {
  337:                 List<string> list;
  338:  
  339:                 using (var db = new Ia.Ftn.Cl.Db())
  340:                 {
  341:                     list = (from s in db.Service2
  342:                             where s.Access == null && s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService
  343:                             select s.Service).ToList();
  344:                 }
  345:  
  346:                 return list;
  347:             }
  348:         }
  349:  
  350:         ////////////////////////////////////////////////////////////////////////////
  351:  
  352:         /// <summary>
  353:         ///
  354:         /// </summary>
  355:         public static List<string> MsanServiceList
  356:         {
  357:             get
  358:             {
  359:                 List<string> list;
  360:  
  361: #if DEBUG
  362:                 var dummyVarToDrawRefractorToBelow = Ia.Ftn.Cl.Models.Business.NumberFormatConverter.Dn("0000000");
  363: #endif
  364:  
  365:                 using (var db = new Ia.Ftn.Cl.Db())
  366:                 {
  367:                     list = (from s in db.Service2
  368:                             join evpu in db.EmsVoipPstnUsers on "+965" + s.Service equals evpu.DN // see: Ia.Ftn.Cl.Model.Business.NumberFormatConverter.Dn()
  369:                             where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService
  370:                             select s.Service).ToList();
  371:                 }
  372:  
  373:                 return list;
  374:             }
  375:         }
  376:  
  377:         ////////////////////////////////////////////////////////////////////////////
  378:  
  379:         /// <summary>
  380:         /// 
  381:         /// </summary>
  382:         public static List<string> PstnServiceList
  383:         {
  384:             get
  385:             {
  386:                 List<string> list;
  387:  
  388:                 using (var db = new Ia.Ftn.Cl.Db())
  389:                 {
  390:                     list = (from s in db.Service2
  391:                             where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.PstnService
  392:                             select s.Service).ToList();
  393:                 }
  394:  
  395:                 return list.ToList();
  396:             }
  397:         }
  398:  
  399:         ////////////////////////////////////////////////////////////////////////////
  400:  
  401:         /// <summary>
  402:         ///
  403:         /// </summary>
  404:         public static bool IsPstnService(string service)
  405:         {
  406:             bool isPstnService;
  407:  
  408:  
  409:             using (var db = new Ia.Ftn.Cl.Db())
  410:             {
  411:                 isPstnService = (from s in db.Service2
  412:                                  where s.Service == service && s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.PstnService
  413:                                  select s.Service).Any();
  414:             }
  415:  
  416:             return isPstnService;
  417:         }
  418:  
  419:         ////////////////////////////////////////////////////////////////////////////
  420:  
  421:         /// <summary>
  422:         /// 
  423:         /// </summary>
  424:         public static List<string> ServiceIdList
  425:         {
  426:             get
  427:             {
  428:                 List<string> list;
  429:  
  430:                 using (var db = new Ia.Ftn.Cl.Db())
  431:                 {
  432:                     list = (from s in db.Service2 /*where s.ServiceType == Ia.Ftn.Cl.Model.Business.Service.ServiceType.ImsService*/ select s.Id).ToList();
  433:                 }
  434:  
  435:                 return list.ToList();
  436:             }
  437:         }
  438:  
  439:         ////////////////////////////////////////////////////////////////////////////
  440:  
  441:         /// <summary>
  442:         /// 
  443:         /// </summary>
  444:         public static List<string> ImsServiceIdList
  445:         {
  446:             get
  447:             {
  448:                 List<string> list;
  449:  
  450:                 using (var db = new Ia.Ftn.Cl.Db())
  451:                 {
  452:                     list = (from s in db.Service2
  453:                             where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService
  454:                             select s.Id).ToList();
  455:                 }
  456:  
  457:                 return list.ToList();
  458:             }
  459:         }
  460:  
  461:         ////////////////////////////////////////////////////////////////////////////
  462:  
  463:         /// <summary>
  464:         /// 
  465:         /// </summary>
  466:         public static List<string> PstnServiceIdList
  467:         {
  468:             get
  469:             {
  470:                 List<string> list;
  471:  
  472:                 using (var db = new Ia.Ftn.Cl.Db())
  473:                 {
  474:                     list = (from s in db.Service2
  475:                             where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.PstnService
  476:                             select s.Id).ToList();
  477:                 }
  478:  
  479:                 return list.ToList();
  480:             }
  481:         }
  482:  
  483:         ////////////////////////////////////////////////////////////////////////////
  484:  
  485:         /// <summary>
  486:         ///
  487:         /// </summary>
  488:         public static List<Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated> ServiceOntList
  489:         {
  490:             get
  491:             {
  492:                 List<Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated> list;
  493:  
  494:                 var ontAccessIdToOntForOltIdListDictionary = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntAccessIdToOntDictionary;
  495:  
  496:                 using (var db = new Ia.Ftn.Cl.Db())
  497:                 {
  498:                     list = (from s in db.Service2
  499:                             where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService
  500:                             select new Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated { ServiceId = s.Id, Service = s.Service, AccessId = s.Access != null ? s.Access.Id : string.Empty, CreatedDateTime = s.Created }).AsNoTracking().ToList();
  501:                 }
  502:  
  503:                 foreach (var l in list)
  504:                 {
  505:                     l.Ont = ontAccessIdToOntForOltIdListDictionary.ContainsKey(l.AccessId) ? ontAccessIdToOntForOltIdListDictionary[l.AccessId] : null;
  506:                 }
  507:  
  508:                 return list;
  509:             }
  510:         }
  511:  
  512:         ////////////////////////////////////////////////////////////////////////////
  513:  
  514:         /// <summary>
  515:         ///
  516:         /// </summary>
  517:         public static List<Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated> ServiceOntBySiteIdList(int siteId)
  518:         {
  519:             List<Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated> list;
  520:  
  521:             var ontAccessIdToOntForOltIdListDictionary = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntAccessIdToOntDictionary;
  522:  
  523:             var site = (from s in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.SiteList
  524:                         where s.Id == siteId
  525:                         select s).SingleOrDefault();
  526:  
  527:             if (site != null)
  528:             {
  529:                 var siteRouterDomainList = (from r in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.RouterList
  530:                                             where r.Site.Id == site.Id
  531:                                             select r).SelectMany(d => d.DomainList).ToList();
  532:  
  533:                 using (var db = new Ia.Ftn.Cl.Db())
  534:                 {
  535:                     var list0 = (from s in db.Service2
  536:                                  where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService
  537:                                  select new Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated { ServiceId = s.Id, Service = s.Service, AccessId = s.Access != null ? s.Access.Id : string.Empty, CreatedDateTime = s.Created }).AsNoTracking().ToList();
  538:  
  539:                     list = new List<Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated>();
  540:  
  541:                     foreach (var l in list0)
  542:                     {
  543:                         if (!string.IsNullOrEmpty(l.AccessId))
  544:                         {
  545:                             if (ontAccessIdToOntForOltIdListDictionary.ContainsKey(l.AccessId))
  546:                             {
  547:                                 l.Ont = ontAccessIdToOntForOltIdListDictionary[l.AccessId];
  548:  
  549:                                 if (l.Ont.Pon.PonGroup.Olt.Odf.Router.Site.Id == siteId)
  550:                                 {
  551:                                     list.Add(l);
  552:                                 }
  553:                                 else
  554:                                 {
  555:  
  556:                                 }
  557:                             }
  558:                             else
  559:                             {
  560:  
  561:                             }
  562:                         }
  563:                         else
  564:                         {
  565:                             if (siteRouterDomainList.Any(u => l.Service.StartsWith(u.ToString())))
  566:                             {
  567:                                 list.Add(l);
  568:                             }
  569:                         }
  570:                     }
  571:                 }
  572:  
  573:                 var msanServiceList = Ia.Ftn.Cl.Models.Data.Huawei.Default.MsanServiceListBySiteId(siteId);
  574:  
  575:                 foreach (var msanService in msanServiceList)
  576:                 {
  577:                     list.Add(new Business.ServiceAccessIpOntCreated { Service = msanService, AccessId = string.Empty });
  578:                 }
  579:             }
  580:             else
  581:             {
  582:                 list = new List<Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated>();
  583:             }
  584:  
  585:             return list;
  586:         }
  587:  
  588:         ////////////////////////////////////////////////////////////////////////////
  589:  
  590:         /// <summary>
  591:         ///
  592:         /// </summary>
  593:         public static List<Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated> ServiceOntByAreaIdList(int areaId)
  594:         {
  595:             List<Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated> list;
  596:  
  597:             var ontAccessIdToOntForOltIdListDictionary = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntAccessIdToOntDictionary;
  598:  
  599:             var area = (from a in Ia.Ftn.Cl.Models.Data.Service.KuwaitFtnAreaList
  600:                         where a.Id == areaId
  601:                         select a).SingleOrDefault();
  602:  
  603:             if (area != null)
  604:             {
  605:                 using (var db = new Ia.Ftn.Cl.Db())
  606:                 {
  607:                     var list0 = (from s in db.Service2
  608:                                  where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService
  609:                                  select new Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated { ServiceId = s.Id, Service = s.Service, AccessId = s.Access != null ? s.Access.Id : string.Empty }).AsNoTracking().ToList();
  610:  
  611:                     list = new List<Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated>();
  612:  
  613:                     foreach (var l in list0)
  614:                     {
  615:                         if (!string.IsNullOrEmpty(l.AccessId))
  616:                         {
  617:                             if (ontAccessIdToOntForOltIdListDictionary.ContainsKey(l.AccessId))
  618:                             {
  619:                                 l.Ont = ontAccessIdToOntForOltIdListDictionary[l.AccessId];
  620:  
  621:                                 if (l.Ont.Pon.PonGroup.Symbol == area.Symbol)
  622:                                 {
  623:                                     list.Add(l);
  624:                                 }
  625:                                 else
  626:                                 {
  627:  
  628:                                 }
  629:                             }
  630:                             else
  631:                             {
  632:  
  633:                             }
  634:                         }
  635:                         else
  636:                         {
  637:                         }
  638:                     }
  639:                 }
  640:             }
  641:             else
  642:             {
  643:                 list = new List<Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated>();
  644:             }
  645:  
  646:             return list;
  647:         }
  648:  
  649:         ////////////////////////////////////////////////////////////////////////////
  650:  
  651:         /// <summary>
  652:         ///
  653:         /// </summary>
  654:         public static List<Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated> ServiceOntByDomainList(string domain)
  655:         {
  656:             List<Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated> list;
  657:  
  658:             var ontAccessIdToOntForOltIdListDictionary = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntAccessIdToOntDictionary;
  659:  
  660:             using (var db = new Ia.Ftn.Cl.Db())
  661:             {
  662:                 var list0 = (from s in db.Service2
  663:                              where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && s.Service.StartsWith(domain)
  664:                              select new Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated { ServiceId = s.Id, Service = s.Service, AccessId = s.Access != null ? s.Access.Id : string.Empty }).AsNoTracking().ToList();
  665:  
  666:                 list = new List<Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated>();
  667:  
  668:                 foreach (var l in list0)
  669:                 {
  670:                     if (!string.IsNullOrEmpty(l.AccessId))
  671:                     {
  672:                         if (ontAccessIdToOntForOltIdListDictionary.ContainsKey(l.AccessId))
  673:                         {
  674:                             l.Ont = ontAccessIdToOntForOltIdListDictionary[l.AccessId];
  675:  
  676:                             list.Add(l);
  677:                         }
  678:                         else
  679:                         {
  680:  
  681:                         }
  682:                     }
  683:                     else
  684:                     {
  685:                     }
  686:                 }
  687:             }
  688:  
  689:             return list;
  690:         }
  691:  
  692:         ////////////////////////////////////////////////////////////////////////////
  693:  
  694:         /// <summary>
  695:         ///
  696:         /// </summary>
  697:         public static List<Ia.Ftn.Cl.Models.Service2> WithinSiteList(int siteId)
  698:         {
  699:             List<Ia.Ftn.Cl.Models.Service2> list;
  700:  
  701:             var site = (from s in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.SiteList
  702:                         where s.Id == siteId
  703:                         select s).SingleOrDefault();
  704:  
  705:             if (site != null)
  706:             {
  707:                 var siteRouterDomainList = (from r in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.RouterList
  708:                                             where r.Site.Id == site.Id
  709:                                             select r).SelectMany(d => d.DomainList).ToList();
  710:  
  711:                 using (var db = new Ia.Ftn.Cl.Db())
  712:                 {
  713:                     var list0 = (from s in db.Service2
  714:                                  select s).Include(u => u.Access).ToList();
  715:  
  716:                     list = (from s in list0
  717:                             where siteRouterDomainList.Any(u => s.Service.StartsWith(u.ToString()))
  718:                             select s).ToList();
  719:                 }
  720:             }
  721:             else
  722:             {
  723:                 list = new List<Ia.Ftn.Cl.Models.Service2>();
  724:             }
  725:  
  726:             return list;
  727:         }
  728:  
  729:         ////////////////////////////////////////////////////////////////////////////
  730:  
  731:         /// <summary>
  732:         /// 
  733:         /// </summary>
  734:         public static List<Ia.Ftn.Cl.Models.Service2> PstnService2List
  735:         {
  736:             get
  737:             {
  738:                 List<Ia.Ftn.Cl.Models.Service2> list;
  739:  
  740:                 using (var db = new Ia.Ftn.Cl.Db())
  741:                 {
  742:                     list = (from s in db.Service2
  743:                             where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.PstnService
  744:                             select s).Include(s => s.Access).ToList();
  745:                 }
  746:  
  747:                 return list.ToList();
  748:             }
  749:         }
  750:  
  751:         ////////////////////////////////////////////////////////////////////////////
  752:  
  753:         /// <summary>
  754:         /// 
  755:         /// </summary>
  756:         public static Dictionary<string, int> ServiceIdToPortDictionary
  757:         {
  758:             get
  759:             {
  760:                 Dictionary<string, int> dictionary;
  761:  
  762:                 using (var db = new Ia.Ftn.Cl.Db())
  763:                 {
  764:                     dictionary = (from s in db.Service2
  765:                                   where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && s.Access != null
  766:                                   select new { s.Id, s.Port }).ToDictionary(m => m.Id, m => m.Port);
  767:                 }
  768:  
  769:                 return dictionary;
  770:             }
  771:         }
  772:  
  773:         ////////////////////////////////////////////////////////////////////////////
  774:  
  775:         /// <summary>
  776:         ///
  777:         /// </summary>
  778:         public static Ia.Ftn.Cl.Models.Access ReadAccess(string id)
  779:         {
  780:             Ia.Ftn.Cl.Models.Access access;
  781:  
  782:             using (var db = new Ia.Ftn.Cl.Db())
  783:             {
  784:                 access = (from s in db.Service2
  785:                           where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && s.Id == id
  786:                           select s.Access).SingleOrDefault();
  787:             }
  788:  
  789:             return access;
  790:         }
  791:  
  792:         ////////////////////////////////////////////////////////////////////////////
  793:  
  794:         /// <summary>
  795:         ///
  796:         /// </summary>
  797:         public static Dictionary<string, int> ServicePortDictionary
  798:         {
  799:             get
  800:             {
  801:                 Dictionary<string, int> dictionary;
  802:  
  803:                 using (var db = new Ia.Ftn.Cl.Db())
  804:                 {
  805:                     dictionary = (from s in db.Service2
  806:                                   where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && s.Port > -1
  807:                                   select new { s.Service, s.Port }).ToDictionary(m => m.Service, m => m.Port);
  808:                 }
  809:  
  810:                 return dictionary;
  811:             }
  812:         }
  813:  
  814:         ////////////////////////////////////////////////////////////////////////////
  815:  
  816:         /// <summary>
  817:         ///
  818:         /// </summary>
  819:         public static Ia.Ftn.Cl.Models.Access ReadAccess(Db db, string id)
  820:         {
  821:             Ia.Ftn.Cl.Models.Access access;
  822:  
  823:             access = (from s in db.Service2
  824:                       where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && s.Id == id
  825:                       select s.Access).SingleOrDefault();
  826:  
  827:             return access;
  828:         }
  829:  
  830:         ////////////////////////////////////////////////////////////////////////////
  831:  
  832:         /// <summary>
  833:         ///
  834:         /// </summary>
  835:         public static bool UpdatePort(Ia.Ftn.Cl.Models.Service2 service, int port, out string result)
  836:         {
  837:             bool b;
  838:  
  839:             using (var db = new Ia.Ftn.Cl.Db())
  840:             {
  841:                 service = (from s in db.Service2
  842:                            where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && s.Id == service.Id
  843:                            select s).SingleOrDefault();
  844:  
  845:                 if (service.Port != port)
  846:                 {
  847:                     service.Port = port;
  848:  
  849:                     db.Service2.Attach(service);
  850:                     db.Entry(service).Property(u => u.Port).IsModified = true;
  851:  
  852:                     db.SaveChanges();
  853:  
  854:                     result = "Success: Service Port updated. ";
  855:                     b = true;
  856:                 }
  857:                 else
  858:                 {
  859:                     result = "Warning: Service Port value was not updated because its the same. ";
  860:  
  861:                     b = false;
  862:                 }
  863:             }
  864:  
  865:             return b;
  866:         }
  867:  
  868:         ////////////////////////////////////////////////////////////////////////////
  869:  
  870:         /// <summary>
  871:         ///
  872:         /// </summary>
  873:         public static List<Ia.Ftn.Cl.Models.Service2> ServiceWithNullAccessList
  874:         {
  875:             get
  876:             {
  877:                 List<Ia.Ftn.Cl.Models.Service2> serviceList;
  878:  
  879:                 using (var db = new Ia.Ftn.Cl.Db())
  880:                 {
  881:                     serviceList = (from s in db.Service2
  882:                                    where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && s.Access == null
  883:                                    select s).ToList();
  884:                 }
  885:  
  886:                 return serviceList;
  887:             }
  888:         }
  889:  
  890:         ////////////////////////////////////////////////////////////////////////////
  891:  
  892:         /// <summary>
  893:         ///
  894:         /// </summary>
  895:         public static List<string> ServiceIdWithinSipOltList()
  896:         {
  897:             List<int> sipOltIdList;
  898:             List<string> list, list2;
  899:  
  900:             sipOltIdList = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.SipOltIdList;
  901:  
  902:             using (var db = new Ia.Ftn.Cl.Db())
  903:             {
  904:                 // services with access
  905:                 list = (from s in db.Service2
  906:                         where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && s.Access != null && sipOltIdList.Contains(s.Access.Olt)
  907:                         select s.Id).ToList();
  908:  
  909:                 // services without access might be newly installed
  910:                 list2 = (from s in db.Service2
  911:                          join srs in db.ServiceRequestServices on s.Service equals srs.Service
  912:                          where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && s.Access == null && srs.Access != null && srs.Provisioned == true && sipOltIdList.Contains(srs.Access.Olt)
  913:                          select s.Id).ToList();
  914:             }
  915:  
  916:             return list.Union(list2).Distinct().ToList();
  917:         }
  918:  
  919:         ////////////////////////////////////////////////////////////////////////////
  920:  
  921:         /// <summary>
  922:         ///
  923:         /// </summary>
  924:         public static List<string> ServiceIdWithinAllowedSipOltToBeProvisionedOrMigratedList()
  925:         {
  926:             List<int> sipOltIdList;
  927:             List<string> list, list2;
  928:  
  929:             sipOltIdList = Ia.Ftn.Cl.Models.Data.Service.AllowedToBeProvisionedSipOltIdList.Union(Ia.Ftn.Cl.Models.Data.Service.AllowedToBeMigratedSipOltIdList).ToList();
  930:  
  931:             using (var db = new Ia.Ftn.Cl.Db())
  932:             {
  933:                 // services with access
  934:                 list = (from s in db.Service2
  935:                         where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && s.Access != null && sipOltIdList.Contains(s.Access.Olt)
  936:                         select s.Id).ToList();
  937:  
  938:                 // services without access might be newly installed
  939:                 list2 = (from s in db.Service2
  940:                          join srs in db.ServiceRequestServices on s.Service equals srs.Service
  941:                          where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && s.Access == null && srs.Access != null && srs.Provisioned == true && sipOltIdList.Contains(srs.Access.Olt)
  942:                          select s.Id).ToList();
  943:             }
  944:  
  945:             return list.Union(list2).Distinct().ToList();
  946:         }
  947:  
  948:         ////////////////////////////////////////////////////////////////////////////
  949:  
  950:         /// <summary>
  951:         ///
  952:         /// </summary>
  953:         public static List<Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated> ServiceOntWithinAllowedSipOltToBeProvisionedOrMigratedList
  954:         {
  955:             get
  956:             {
  957:                 List<int> oltIdList;
  958:                 List<Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated> list1, list2, list;
  959:  
  960:                 oltIdList = Ia.Ftn.Cl.Models.Data.Service.AllowedToBeProvisionedSipOltIdList.Union(Ia.Ftn.Cl.Models.Data.Service.AllowedToBeMigratedSipOltIdList).ToList();
  961:  
  962:                 var ontAccessIdToOntForOltIdListDictionary = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntAccessIdToOntForOltIdListDictionary(oltIdList);
  963:  
  964:                 using (var db = new Ia.Ftn.Cl.Db())
  965:                 {
  966:                     // services with access
  967:                     list1 = (from s in db.Service2
  968:                              where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && s.Access != null && oltIdList.Contains(s.Access.Olt)
  969:                              select new Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated { ServiceId = s.Id, Service = s.Service, AccessId = s.Access.Id, CreatedDateTime = s.Created }).AsNoTracking().ToList();
  970:  
  971:                     // services without access might be newly installed
  972:                     list2 = (from s in db.Service2
  973:                              join srs in db.ServiceRequestServices on s.Service equals srs.Service
  974:                              where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && s.Access == null && srs.Access != null && srs.Provisioned == true && oltIdList.Contains(srs.Access.Olt)
  975:                              select new Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated { ServiceId = s.Id, Service = s.Service, AccessId = srs.Access.Id, CreatedDateTime = s.Created }).AsNoTracking().ToList();
  976:                 }
  977:  
  978:                 list = list1.Concat(list2).ToList();
  979:  
  980:                 foreach (var l in list)
  981:                 {
  982:                     l.Ont = ontAccessIdToOntForOltIdListDictionary.ContainsKey(l.AccessId) ? ontAccessIdToOntForOltIdListDictionary[l.AccessId] : null;
  983:                 }
  984:  
  985:                 return list;
  986:             }
  987:         }
  988:  
  989:         ////////////////////////////////////////////////////////////////////////////
  990:  
  991:         /// <summary>
  992:         ///
  993:         /// </summary>
  994:         public static Dictionary<string, int> ServiceToOltIdWithinNokiaSwitchHuaweiAccessOltListDictionary
  995:         {
  996:             get
  997:             {
  998:                 List<int> oltIdList;
  999:                 Dictionary<string, int> dictionary, dictionary1, dictionary2;
 1000:  
 1001:                 oltIdList = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.NokiaRouterHuaweiAccessOltIdList;
 1002:  
 1003:                 using (var db = new Ia.Ftn.Cl.Db())
 1004:                 {
 1005:                     // services with access
 1006:                     dictionary1 = (from s in db.Service2
 1007:                                    where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && s.Access != null && oltIdList.Contains(s.Access.Olt)
 1008:                                    select new { s.Service, s.Access.Olt }).AsNoTracking().ToDictionary(u => u.Service, u => u.Olt);
 1009:  
 1010:                     /*
 1011:                     // services without access might be newly installed
 1012:                     dictionary2 = (from s in db.Service2
 1013:                                    join srs in db.ServiceRequestServices on s.Service equals srs.Service
 1014:                                    where s.ServiceType == Ia.Ftn.Cl.Model.Business.Service.ServiceType.ImsService && s.Access == null && srs.Access != null && srs.Provisioned == true && oltIdList.Contains(srs.Access.Olt)
 1015:                                    select new { s.Service, s.Access.Olt }).AsNoTracking().ToDictionary(u => u.Service, u => u.Olt);
 1016:                     */
 1017:                 }
 1018:  
 1019:                 dictionary = dictionary1;//.Union(dictionary2).ToDictionary(u => u.Key, u => u.Value);
 1020:  
 1021:                 return dictionary;
 1022:             }
 1023:         }
 1024:  
 1025:         ////////////////////////////////////////////////////////////////////////////
 1026:  
 1027:         /// <summary>
 1028:         ///
 1029:         /// </summary>
 1030:         public static List<Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated> ServiceOntWithinAllowedToBeProvisionedOrMigratedHuaweiSwitchNokiaAccessOltList()
 1031:         {
 1032:             List<int> oltIdList;
 1033:             List<Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated> list1, list2, list;
 1034:  
 1035:             oltIdList = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.HuaweiRouterNokiaAccessOltIdList;
 1036:  
 1037:             var ontAccessIdToOntForOltIdListDictionary = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntAccessIdToOntForOltIdListDictionary(oltIdList);
 1038:  
 1039:             using (var db = new Ia.Ftn.Cl.Db())
 1040:             {
 1041:                 // services with access
 1042:                 list1 = (from s in db.Service2
 1043:                          where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && s.Access != null && oltIdList.Contains(s.Access.Olt)
 1044:                          select new Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated { ServiceId = s.Id, Service = s.Service, AccessId = s.Access.Id, CreatedDateTime = s.Created }).AsNoTracking().ToList();
 1045:  
 1046:                 // services without access might be newly installed
 1047:                 list2 = (from s in db.Service2
 1048:                          join srs in db.ServiceRequestServices on s.Service equals srs.Service
 1049:                          where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && s.Access == null && srs.Access != null && srs.Provisioned == true && oltIdList.Contains(srs.Access.Olt)
 1050:                          select new Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated { ServiceId = s.Id, Service = s.Service, AccessId = srs.Access.Id, CreatedDateTime = s.Created }).AsNoTracking().ToList();
 1051:             }
 1052:  
 1053:             list = list1.Concat(list2).ToList();
 1054:  
 1055:             foreach (var l in list)
 1056:             {
 1057:                 l.Ont = ontAccessIdToOntForOltIdListDictionary.ContainsKey(l.AccessId) ? ontAccessIdToOntForOltIdListDictionary[l.AccessId] : null;
 1058:             }
 1059:  
 1060:             return list;
 1061:         }
 1062:  
 1063:         ////////////////////////////////////////////////////////////////////////////
 1064:  
 1065:         /// <summary>
 1066:         ///
 1067:         /// </summary>
 1068:         public static List<string> ServiceIdWithinHuaweiSwitchDomainList()
 1069:         {
 1070:             List<int> huaweiSwitchDomainList;
 1071:             List<string> list;
 1072:  
 1073:             huaweiSwitchDomainList = Ia.Ftn.Cl.Models.Data.Service.HuaweiSwitchDomainList;
 1074:  
 1075:             using (var db = new Ia.Ftn.Cl.Db())
 1076:             {
 1077:                 list = (from s in db.Service2
 1078:                         where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && huaweiSwitchDomainList.Any(u => s.Service.StartsWith(u.ToString()))
 1079:                         select s.Id).ToList();
 1080:             }
 1081:  
 1082:             return list.ToList();
 1083:         }
 1084:  
 1085:         ////////////////////////////////////////////////////////////////////////////
 1086:  
 1087:         /// <summary>
 1088:         ///
 1089:         /// </summary>
 1090:         public static List<string> ServiceIdWithinNokiaSwitchDomainList()
 1091:         {
 1092:             List<int> nokiaSwitchDomainList;
 1093:             List<string> list;
 1094:  
 1095:             nokiaSwitchDomainList = Ia.Ftn.Cl.Models.Data.Service.NokiaSwitchDomainList;
 1096:  
 1097:             using (var db = new Ia.Ftn.Cl.Db())
 1098:             {
 1099:                 list = (from s in db.Service2
 1100:                         where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && nokiaSwitchDomainList.Any(u => s.Service.StartsWith(u.ToString()))
 1101:                         select s.Id).ToList();
 1102:             }
 1103:  
 1104:             return list.ToList();
 1105:         }
 1106:  
 1107:         ////////////////////////////////////////////////////////////////////////////
 1108:  
 1109:         /// <summary>
 1110:         ///
 1111:         /// </summary>
 1112:         public static List<string> ServiceIdWithNullAccessList()
 1113:         {
 1114:             List<string> list;
 1115:  
 1116:             using (var db = new Ia.Ftn.Cl.Db())
 1117:             {
 1118:                 list = (from s in db.Service2
 1119:                         where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && s.Access == null
 1120:                         select s.Id).ToList();
 1121:             }
 1122:  
 1123:             return list;
 1124:         }
 1125:  
 1126:         ////////////////////////////////////////////////////////////////////////////
 1127:  
 1128:         /// <summary>
 1129:         ///
 1130:         /// </summary>
 1131:         public static List<Ia.Ftn.Cl.Models.Service2> ServiceSuspensionIsTrueList
 1132:         {
 1133:             get
 1134:             {
 1135:                 List<Ia.Ftn.Cl.Models.Service2> serviceList;
 1136:  
 1137:                 using (var db = new Ia.Ftn.Cl.Db())
 1138:                 {
 1139:                     serviceList = (from s in db.Service2
 1140:                                    where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && s.ServiceSuspension == true
 1141:                                    select s).ToList();
 1142:                 }
 1143:  
 1144:                 return serviceList;
 1145:             }
 1146:         }
 1147:  
 1148:         ////////////////////////////////////////////////////////////////////////////
 1149:  
 1150:         /// <summary>
 1151:         ///
 1152:         /// </summary>
 1153:         public static int ServiceSuspensionIsTrueListCount
 1154:         {
 1155:             get
 1156:             {
 1157:                 int c;
 1158:  
 1159:                 using (var db = new Ia.Ftn.Cl.Db())
 1160:                 {
 1161:                     c = (from s in db.Service2
 1162:                          where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && s.ServiceSuspension == true
 1163:                          select s).Count();
 1164:                 }
 1165:  
 1166:                 return c;
 1167:             }
 1168:         }
 1169:  
 1170:         ////////////////////////////////////////////////////////////////////////////
 1171:  
 1172:         /// <summary>
 1173:         ///
 1174:         /// </summary>
 1175:         public static List<Ia.Ftn.Cl.Models.Service2> ServiceSuspensionIsFalseList
 1176:         {
 1177:             get
 1178:             {
 1179:                 List<Ia.Ftn.Cl.Models.Service2> serviceList;
 1180:  
 1181:                 using (var db = new Ia.Ftn.Cl.Db())
 1182:                 {
 1183:                     serviceList = (from s in db.Service2
 1184:                                    where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && s.ServiceSuspension == false
 1185:                                    select s).ToList();
 1186:                 }
 1187:  
 1188:                 return serviceList;
 1189:             }
 1190:         }
 1191:  
 1192:         ////////////////////////////////////////////////////////////////////////////
 1193:  
 1194:         /// <summary>
 1195:         ///
 1196:         /// </summary>
 1197:         public static List<string> ServiceSuspensionIsTrueStringNumberList
 1198:         {
 1199:             get
 1200:             {
 1201:                 List<string> serviceNumberStringList;
 1202:                 List<Ia.Ftn.Cl.Models.Service2> serviceList;
 1203:  
 1204:                 using (var db = new Ia.Ftn.Cl.Db())
 1205:                 {
 1206:                     // below:                
 1207:                     serviceList = ServiceSuspensionIsTrueList;
 1208:  
 1209:                     if (serviceList.Count > 0)
 1210:                     {
 1211:                         serviceNumberStringList = new List<string>(serviceList.Count);
 1212:  
 1213:                         foreach (Ia.Ftn.Cl.Models.Service2 srs in serviceList)
 1214:                         {
 1215:                             serviceNumberStringList.Add(srs.Service);
 1216:                         }
 1217:                     }
 1218:                     else
 1219:                     {
 1220:                         // below: not null
 1221:                         serviceNumberStringList = new List<string>(1);
 1222:                     }
 1223:                 }
 1224:  
 1225:                 return serviceNumberStringList;
 1226:             }
 1227:         }
 1228:  
 1229:         ////////////////////////////////////////////////////////////////////////////
 1230:  
 1231:         /// <summary>
 1232:         ///
 1233:         /// </summary>
 1234:         public static List<string> ServiceSuspensionIsFalseStringNumberList
 1235:         {
 1236:             get
 1237:             {
 1238:                 List<string> serviceNumberStringList;
 1239:                 List<Ia.Ftn.Cl.Models.Service2> serviceList;
 1240:  
 1241:                 using (var db = new Ia.Ftn.Cl.Db())
 1242:                 {
 1243:                     // below:                
 1244:                     serviceList = ServiceSuspensionIsFalseList;
 1245:  
 1246:                     if (serviceList.Count > 0)
 1247:                     {
 1248:                         serviceNumberStringList = new List<string>(serviceList.Count);
 1249:  
 1250:                         foreach (Ia.Ftn.Cl.Models.Service2 srs in serviceList)
 1251:                         {
 1252:                             serviceNumberStringList.Add(srs.Service);
 1253:                         }
 1254:                     }
 1255:                     else
 1256:                     {
 1257:                         // below: not null
 1258:                         serviceNumberStringList = new List<string>(1);
 1259:                     }
 1260:                 }
 1261:  
 1262:                 return serviceNumberStringList;
 1263:             }
 1264:         }
 1265:  
 1266:         ////////////////////////////////////////////////////////////////////////////
 1267:  
 1268:         /// <summary>
 1269:         ///
 1270:         /// </summary>
 1271:         public static bool IsSuspended(string service)
 1272:         {
 1273:             bool isSuspended;
 1274:  
 1275:             using (var db = new Ia.Ftn.Cl.Db())
 1276:             {
 1277:                 isSuspended = (from s in db.Service2
 1278:                                where s.Service == service && s.ServiceSuspension == true
 1279:                                select s.Service).Any();
 1280:             }
 1281:  
 1282:             return isSuspended;
 1283:         }
 1284:  
 1285:         ////////////////////////////////////////////////////////////////////////////
 1286:  
 1287:         /// <summary>
 1288:         ///
 1289:         /// </summary>
 1290:         public static bool HasInternationalCalling(string service)
 1291:         {
 1292:             return InternationalCallingIsAssigned(service);
 1293:         }
 1294:  
 1295:         ////////////////////////////////////////////////////////////////////////////
 1296:  
 1297:         /// <summary>
 1298:         ///
 1299:         /// </summary>
 1300:         public static bool InternationalCallingIsAssigned(string service)
 1301:         {
 1302:             bool isAssigned;
 1303:  
 1304:             using (var db = new Ia.Ftn.Cl.Db())
 1305:             {
 1306:                 isAssigned = (from s in db.Service2
 1307:                               where s.Service == service && s.InternationalCalling == true
 1308:                               select s.Service).Any();
 1309:             }
 1310:  
 1311:             return isAssigned;
 1312:         }
 1313:  
 1314:         ////////////////////////////////////////////////////////////////////////////
 1315:  
 1316:         /// <summary>
 1317:         ///
 1318:         /// </summary>
 1319:         public static Dictionary<string, string> ServiceIdToAccessIdDictionary
 1320:         {
 1321:             get
 1322:             {
 1323:                 Dictionary<string, string> dictionary, nullAccessDictionary;
 1324:  
 1325:                 using (var db = new Ia.Ftn.Cl.Db())
 1326:                 {
 1327:                     dictionary = (from s in db.Service2
 1328:                                   where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && s.Access != null
 1329:                                   select new { s.Id, s.Access }).AsNoTracking().ToDictionary(u => u.Id, u => u.Access.Id);
 1330:  
 1331:                     nullAccessDictionary = (from s in db.Service2
 1332:                                             where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && s.Access == null
 1333:                                             select new { s.Id, s.Access }).AsNoTracking().ToDictionary(u => u.Id, u => string.Empty);
 1334:                 }
 1335:  
 1336:                 return dictionary.Union(nullAccessDictionary).ToDictionary(u => u.Key, u => u.Value);
 1337:             }
 1338:         }
 1339:  
 1340:         ////////////////////////////////////////////////////////////////////////////
 1341:  
 1342:         /// <summary>
 1343:         ///
 1344:         /// </summary>
 1345:         public static Dictionary<string, string> PstnServiceIdToAccessIdDictionary
 1346:         {
 1347:             get
 1348:             {
 1349:                 Dictionary<string, string> dictionary, nullAccessDictionary;
 1350:  
 1351:                 using (var db = new Ia.Ftn.Cl.Db())
 1352:                 {
 1353:                     dictionary = (from s in db.Service2
 1354:                                   where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.PstnService && s.Access != null
 1355:                                   select new { s.Id, s.Access }).ToDictionary(u => u.Id, u => u.Access.Id);
 1356:  
 1357:                     nullAccessDictionary = (from s in db.Service2
 1358:                                             where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.PstnService && s.Access == null
 1359:                                             select new { s.Id, s.Access }).ToDictionary(u => u.Id, u => string.Empty);
 1360:                 }
 1361:  
 1362:                 return dictionary.Union(nullAccessDictionary).ToDictionary(u => u.Key, u => u.Value);
 1363:             }
 1364:         }
 1365:  
 1366:         ////////////////////////////////////////////////////////////////////////////
 1367:         ////////////////////////////////////////////////////////////////////////////
 1368:  
 1369:         /// <summary>
 1370:         ///
 1371:         /// </summary>
 1372:         public static bool NullifyAccessIdByAccessId(string accessId, out string result)
 1373:         {
 1374:             bool b;
 1375:             int numberOfRecordsWhereAccessIsNullified;
 1376:             Ia.Ftn.Cl.Models.Service2 service2;
 1377:  
 1378:             b = false;
 1379:             numberOfRecordsWhereAccessIsNullified = 0;
 1380:  
 1381:             using (var db = new Ia.Ftn.Cl.Db())
 1382:             {
 1383:                 service2 = (from s in db.Service2 where s.Access.Id == accessId select s).Include(u => u.Access).FirstOrDefault(); //.SingleOrDefault();
 1384:  
 1385:                 if (service2 != null)
 1386:                 {
 1387:                     service2.Access = null;
 1388:                     service2.Updated = DateTime.UtcNow.AddHours(3);
 1389:  
 1390:                     db.Service2.Attach(service2);
 1391:                     db.Entry(service2).Property(u => u.Updated).IsModified = true;
 1392:  
 1393:                     db.SaveChanges();
 1394:  
 1395:                     numberOfRecordsWhereAccessIsNullified++;
 1396:                 }
 1397:  
 1398:                 b = true;
 1399:             }
 1400:  
 1401:             result = "Number of records where access is nullified: " + numberOfRecordsWhereAccessIsNullified;
 1402:  
 1403:             return b;
 1404:         }
 1405:  
 1406:         ////////////////////////////////////////////////////////////////////////////
 1407:         ////////////////////////////////////////////////////////////////////////////
 1408:  
 1409:         /// <summary>
 1410:         ///
 1411:         /// </summary>
 1412:         public static Dictionary<string, string> MigratedServiceIdToAccessIdDictionary
 1413:         {
 1414:             get
 1415:             {
 1416:                 Dictionary<string, string> dictionary, nullAccessDictionary;
 1417:  
 1418:                 var migrationDomainList = Ia.Ftn.Cl.Models.Data.Service.MigrationDomainList;
 1419:                 var migrationDomainStringList = migrationDomainList.ConvertAll<string>(delegate (int i) { return i.ToString(); });
 1420:  
 1421:                 using (var db = new Ia.Ftn.Cl.Db())
 1422:                 {
 1423:                     dictionary = (from s in db.Service2
 1424:                                   where s.Access != null && migrationDomainStringList.Any(u => s.Service.StartsWith(u))
 1425:                                   select new { s.Id, s.Access }).AsNoTracking().ToDictionary(u => u.Id, u => u.Access.Id);
 1426:  
 1427:                     nullAccessDictionary = (from s in db.Service2
 1428:                                             where s.Access == null && migrationDomainStringList.Any(u => s.Service.StartsWith(u))
 1429:                                             select new { s.Id, s.Access }).AsNoTracking().ToDictionary(u => u.Id, u => string.Empty);
 1430:                 }
 1431:  
 1432:                 return dictionary.Union(nullAccessDictionary).ToDictionary(u => u.Key, u => u.Value);
 1433:             }
 1434:         }
 1435:  
 1436:         ////////////////////////////////////////////////////////////////////////////
 1437:  
 1438:         /// <summary>
 1439:         ///
 1440:         /// </summary>
 1441:         public static Dictionary<string, string> MigratedServiceIdToAccessIdInAllowedToBeMigratedOltDictionary
 1442:         {
 1443:             get
 1444:             {
 1445:                 Dictionary<string, string> dictionary;
 1446:  
 1447:                 var allowedToBeMigratedOltIdList = Ia.Ftn.Cl.Models.Data.Service.AllowedToBeMigratedOltIdList;
 1448:  
 1449:                 var migrationDomainList = Ia.Ftn.Cl.Models.Data.Service.MigrationDomainList;
 1450:                 var migrationDomainStringList = migrationDomainList.ConvertAll<string>(delegate (int i) { return i.ToString(); });
 1451:  
 1452:                 using (var db = new Ia.Ftn.Cl.Db())
 1453:                 {
 1454:                     dictionary = (from s in db.Service2
 1455:                                   where s.Access != null && migrationDomainStringList.Any(u => s.Service.StartsWith(u)) && allowedToBeMigratedOltIdList.Contains(s.Access.Olt) && s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService
 1456:                                   select new { s.Id, s.Access }).ToDictionary(u => u.Id, u => u.Access.Id);
 1457:                 }
 1458:  
 1459:                 return dictionary.ToDictionary(u => u.Key, u => u.Value);
 1460:             }
 1461:         }
 1462:  
 1463:         ////////////////////////////////////////////////////////////////////////////
 1464:  
 1465:         /// <summary>
 1466:         ///
 1467:         /// </summary>
 1468:         public static List<string> ImsServiceInAllowedToBeMigratedOltList
 1469:         {
 1470:             get
 1471:             {
 1472:                 List<string> list;
 1473:  
 1474:                 var allowedToBeMigratedOltIdList = Ia.Ftn.Cl.Models.Data.Service.AllowedToBeMigratedOltIdList;
 1475:  
 1476:                 var migrationDomainList = Ia.Ftn.Cl.Models.Data.Service.MigrationDomainList;
 1477:                 var migrationDomainStringList = migrationDomainList.ConvertAll<string>(delegate (int i) { return i.ToString(); });
 1478:  
 1479:                 using (var db = new Ia.Ftn.Cl.Db())
 1480:                 {
 1481:                     var list0 = (from s in db.Service2
 1482:                                  where s.Access != null && s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService
 1483:                                  select new { s.Service, AccessOlt = s.Access.Olt }).AsNoTracking().ToList();
 1484:  
 1485:                     list = (from l in list0
 1486:                             where migrationDomainStringList.Any(u => l.Service.StartsWith(u)) && allowedToBeMigratedOltIdList.Contains(l.AccessOlt)
 1487:                             select l.Service).ToList();
 1488:                 }
 1489:  
 1490:                 return list;
 1491:             }
 1492:         }
 1493:  
 1494:         ////////////////////////////////////////////////////////////////////////////
 1495:  
 1496:         /// <summary>
 1497:         ///
 1498:         /// </summary>
 1499:         public static Dictionary<string, string> ImsServiceToAccessIdInAllowedToBeMigratedOltDictionary
 1500:         {
 1501:             get
 1502:             {
 1503:                 Dictionary<string, string> dictionary;
 1504:  
 1505:                 var allowedToBeMigratedOltIdList = Ia.Ftn.Cl.Models.Data.Service.AllowedToBeMigratedOltIdList;
 1506:  
 1507:                 var migrationDomainList = Ia.Ftn.Cl.Models.Data.Service.MigrationDomainList;
 1508:                 var migrationDomainStringList = migrationDomainList.ConvertAll<string>(delegate (int i) { return i.ToString(); });
 1509:  
 1510:                 using (var db = new Ia.Ftn.Cl.Db())
 1511:                 {
 1512:                     var list = (from s in db.Service2
 1513:                                 where s.Access != null && s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService
 1514:                                 select new { s.Service, AccessId = s.Access.Id, AccessOlt = s.Access.Olt }).AsNoTracking().ToList();
 1515:  
 1516:                     dictionary = (from l in list
 1517:                                   where migrationDomainStringList.Any(u => l.Service.StartsWith(u)) && allowedToBeMigratedOltIdList.Contains(l.AccessOlt)
 1518:                                   select l).ToDictionary(u => u.Service, u => u.AccessId);
 1519:                 }
 1520:  
 1521:                 return dictionary.ToDictionary(u => u.Key, u => u.Value);
 1522:             }
 1523:         }
 1524:  
 1525:         ////////////////////////////////////////////////////////////////////////////
 1526:  
 1527:         /// <summary>
 1528:         ///
 1529:         /// </summary>
 1530:         public static List<string> MsanServiceInAllowedToBeMigratedDomainList
 1531:         {
 1532:             get
 1533:             {
 1534:                 List<string> list;
 1535:  
 1536:                 var migrationDomainList = Ia.Ftn.Cl.Models.Data.Service.MigrationDomainList;
 1537:                 var migrationDomainStringList = migrationDomainList.ConvertAll<string>(delegate (int i) { return i.ToString(); });
 1538:  
 1539:                 var msanServiceList = Ia.Ftn.Cl.Models.Data.Service2.MsanServiceList;
 1540:  
 1541:                 list = (from l in msanServiceList
 1542:                         where migrationDomainStringList.Any(u => l.StartsWith(u))
 1543:                         select l).ToList();
 1544:  
 1545:                 return list;
 1546:             }
 1547:         }
 1548:  
 1549:         ////////////////////////////////////////////////////////////////////////////
 1550:  
 1551:         /// <summary>
 1552:         ///
 1553:         /// </summary>
 1554:         public static Dictionary<string, string> ServiceToAccessIdDictionary
 1555:         {
 1556:             get
 1557:             {
 1558:                 string key;
 1559:                 Dictionary<string, string> serviceToAccessIdDictionary, serviceIdToAccessIdDictionary;
 1560:  
 1561:                 serviceIdToAccessIdDictionary = ServiceIdToAccessIdDictionary;
 1562:  
 1563:                 serviceToAccessIdDictionary = new Dictionary<string, string>(serviceIdToAccessIdDictionary.Count);
 1564:  
 1565:                 foreach (KeyValuePair<string, string> kvp in serviceIdToAccessIdDictionary)
 1566:                 {
 1567:                     key = Ia.Ftn.Cl.Models.Business.Service.ServiceIdToService(kvp.Key);
 1568:  
 1569:                     serviceToAccessIdDictionary[key] = kvp.Value;
 1570:                 }
 1571:  
 1572:                 return serviceToAccessIdDictionary;
 1573:             }
 1574:         }
 1575:  
 1576:         ////////////////////////////////////////////////////////////////////////////
 1577:  
 1578:         /// <summary>
 1579:         ///
 1580:         /// </summary>
 1581:         public static Dictionary<string, string> ServiceIdToAccessNameDictionary
 1582:         {
 1583:             get
 1584:             {
 1585:                 Dictionary<string, string> dictionary, nullAccessDictionary;
 1586:  
 1587:                 using (var db = new Ia.Ftn.Cl.Db())
 1588:                 {
 1589:                     dictionary = (from s in db.Service2
 1590:                                   where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && s.Access != null
 1591:                                   select new { s.Id, s.Access }).ToDictionary(u => u.Id, u => u.Access.Name);
 1592:  
 1593:                     nullAccessDictionary = (from s in db.Service2
 1594:                                             where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && s.Access == null
 1595:                                             select s.Id).ToDictionary(u => u, null);
 1596:                 }
 1597:  
 1598:                 return dictionary.Union(nullAccessDictionary).ToDictionary(u => u.Key, u => u.Value);
 1599:             }
 1600:         }
 1601:  
 1602:         ////////////////////////////////////////////////////////////////////////////
 1603:  
 1604:         /// <summary>
 1605:         ///
 1606:         /// </summary>
 1607:         public static Dictionary<string, int> AccessNameToSeviceCountDictionary()
 1608:         {
 1609:             string accessName;
 1610:             Dictionary<string, int> dictionary;
 1611:  
 1612:             using (var db = new Ia.Ftn.Cl.Db())
 1613:             {
 1614:                 var accessIdToAccessNameDictionary = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntAccessIdToOntAccessNameDictionary;
 1615:  
 1616:                 var serviceToAccessIdDictionary = (from s in db.Service2
 1617:                                                    where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && s.Access != null
 1618:                                                    select new { s.Service, AccessId = s.Access.Id }).ToDictionary(u => u.Service, u => u.AccessId);
 1619:  
 1620:                 dictionary = new Dictionary<string, int>(serviceToAccessIdDictionary.Count);
 1621:  
 1622:                 foreach (var accessName0 in accessIdToAccessNameDictionary.Values)
 1623:                 {
 1624:                     dictionary[accessName0] = 0;
 1625:                 }
 1626:  
 1627:                 foreach (KeyValuePair<string, string> kvp in serviceToAccessIdDictionary)
 1628:                 {
 1629:                     accessName = accessIdToAccessNameDictionary[kvp.Value];
 1630:  
 1631:                     if (!string.IsNullOrEmpty(accessName))
 1632:                     {
 1633:                         if (dictionary.ContainsKey(accessName))
 1634:                         {
 1635:                             dictionary[accessName] = dictionary[accessName] + 1;
 1636:                         }
 1637:                         else dictionary[accessName] = 1;
 1638:                     }
 1639:                 }
 1640:             }
 1641:  
 1642:             return dictionary.ToDictionary(u => u.Key, u => u.Value);
 1643:         }
 1644:  
 1645:         ////////////////////////////////////////////////////////////////////////////
 1646:  
 1647:         /// <summary>
 1648:         ///
 1649:         /// </summary>
 1650:         public static Dictionary<string, List<string>> OntAccessIdToSeviceListDictionary()
 1651:         {
 1652:             string service, accessId;
 1653:             Dictionary<string, List<string>> dictionary;
 1654:  
 1655:             using (var db = new Ia.Ftn.Cl.Db())
 1656:             {
 1657:                 var ontAccessIdList = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntAccessIdList;
 1658:  
 1659:                 var serviceToAccessIdDictionary = (from s in db.Service2
 1660:                                                    where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && s.Access != null
 1661:                                                    select new { s.Service, AccessId = s.Access.Id }).ToDictionary(u => u.Service, u => u.AccessId);
 1662:  
 1663:                 dictionary = new Dictionary<string, List<string>>(serviceToAccessIdDictionary.Count);
 1664:  
 1665:                 foreach (var ontAccessId in ontAccessIdList) dictionary[ontAccessId] = new List<string>();
 1666:  
 1667:                 foreach (var kvp in serviceToAccessIdDictionary)
 1668:                 {
 1669:                     service = kvp.Key;
 1670:                     accessId = kvp.Value;
 1671:  
 1672:                     dictionary[accessId].Add(service);
 1673:                 }
 1674:             }
 1675:  
 1676:             return dictionary;
 1677:         }
 1678:  
 1679:         ////////////////////////////////////////////////////////////////////////////
 1680:  
 1681:         /// <summary>
 1682:         ///
 1683:         /// </summary>
 1684:         public static Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont> ServiceToNddOntDictionary
 1685:         {
 1686:             get
 1687:             {
 1688:                 string key;
 1689:                 Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont> dictionary;
 1690:  
 1691:                 var serviceIdToAccessIdDictionary = Ia.Ftn.Cl.Models.Data.Service2.ServiceIdToAccessIdDictionary;
 1692:                 var ontAccessIdToOntDictionary = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntAccessIdToOntDictionary;
 1693:  
 1694:                 dictionary = new Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont>(serviceIdToAccessIdDictionary.Count);
 1695:  
 1696:                 foreach (KeyValuePair<string, string> kvp in serviceIdToAccessIdDictionary)
 1697:                 {
 1698:                     key = Ia.Ftn.Cl.Models.Business.Service.ServiceIdToService(kvp.Key);
 1699:  
 1700:                     if (!string.IsNullOrEmpty(kvp.Value)) dictionary[key] = ontAccessIdToOntDictionary[kvp.Value];
 1701:                     else dictionary[key] = null;
 1702:                 }
 1703:  
 1704:                 return dictionary;
 1705:             }
 1706:         }
 1707:  
 1708:         ////////////////////////////////////////////////////////////////////////////
 1709:  
 1710:         /// <summary>
 1711:         ///
 1712:         /// </summary>
 1713:         public static Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont> PstnServiceToNddOntDictionary
 1714:         {
 1715:             get
 1716:             {
 1717:                 string key;
 1718:                 Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont> dictionary;
 1719:  
 1720:                 var pstnServiceIdToAccessIdDictionary = Ia.Ftn.Cl.Models.Data.Service2.PstnServiceIdToAccessIdDictionary;
 1721:                 var ontAccessIdToOntDictionary = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntAccessIdToOntDictionary;
 1722:  
 1723:                 dictionary = new Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont>(pstnServiceIdToAccessIdDictionary.Count);
 1724:  
 1725:                 foreach (KeyValuePair<string, string> kvp in pstnServiceIdToAccessIdDictionary)
 1726:                 {
 1727:                     key = Ia.Ftn.Cl.Models.Business.Service.ServiceIdToService(kvp.Key);
 1728:  
 1729:                     if (!string.IsNullOrEmpty(kvp.Value)) dictionary[key] = ontAccessIdToOntDictionary[kvp.Value];
 1730:                     //else dictionary[key] = null;
 1731:                 }
 1732:  
 1733:                 return dictionary;
 1734:             }
 1735:         }
 1736:  
 1737:         ////////////////////////////////////////////////////////////////////////////
 1738:  
 1739:         /// <summary>
 1740:         ///
 1741:         /// </summary>
 1742:         public static Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor> MigratedServiceToNddOntRouterVendorDictionary
 1743:         {
 1744:             get
 1745:             {
 1746:                 string key;
 1747:                 Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor> dictionary;
 1748:  
 1749:                 var migratedServiceIdToAccessIdDictionary = Ia.Ftn.Cl.Models.Data.Service2.MigratedServiceIdToAccessIdDictionary;
 1750:                 var ontAccessIdToOntDictionary = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntAccessIdToOntDictionary;
 1751:  
 1752:                 dictionary = new Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor>(migratedServiceIdToAccessIdDictionary.Count);
 1753:  
 1754:                 foreach (KeyValuePair<string, string> kvp in migratedServiceIdToAccessIdDictionary)
 1755:                 {
 1756:                     key = Ia.Ftn.Cl.Models.Business.Service.ServiceIdToService(kvp.Key);
 1757:  
 1758:                     //if (!string.IsNullOrEmpty(kvp.Value)) dictionary[key] = ontAccessIdToOntDictionary[kvp.Value];
 1759:                     //else dictionary[key] = null;
 1760:                 }
 1761:  
 1762:                 return dictionary;
 1763:             }
 1764:         }
 1765:  
 1766:         ////////////////////////////////////////////////////////////////////////////
 1767:  
 1768:         /// <summary>
 1769:         ///
 1770:         /// </summary>
 1771:         public static Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site> ServiceToSiteDictionary
 1772:         {
 1773:             get
 1774:             {
 1775:                 int fourLetterServiceDomain, fiveLetterServiceDomain;
 1776:                 string service;
 1777:                 Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site> dictionary;
 1778:  
 1779:                 var serviceIdList = Ia.Ftn.Cl.Models.Data.Service2.ServiceIdList;
 1780:                 var routerDomainToSiteDictionary = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.RouterDomainToSiteDictionary;
 1781:  
 1782:                 dictionary = new Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site>(serviceIdList.Count);
 1783:  
 1784:                 foreach (string s in serviceIdList)
 1785:                 {
 1786:                     service = Ia.Ftn.Cl.Models.Business.Service.ServiceIdToService(s);
 1787:  
 1788:                     if (service.Length >= 5)
 1789:                     {
 1790:                         fourLetterServiceDomain = int.Parse(service.Substring(0, 4));
 1791:                         fiveLetterServiceDomain = int.Parse(service.Substring(0, 5));
 1792:  
 1793:                         if (routerDomainToSiteDictionary.ContainsKey(fiveLetterServiceDomain)) dictionary[service] = routerDomainToSiteDictionary[fiveLetterServiceDomain];
 1794:                         else if (routerDomainToSiteDictionary.ContainsKey(fourLetterServiceDomain)) dictionary[service] = routerDomainToSiteDictionary[fourLetterServiceDomain];
 1795:                         //else throw new System.ArgumentOutOfRangeException("Service number " + service + " is out of range");
 1796:                     }
 1797:                     //else throw new System.ArgumentOutOfRangeException("Service number " + service + " is out of range");
 1798:                 }
 1799:  
 1800:                 return dictionary;
 1801:             }
 1802:         }
 1803:  
 1804:         ////////////////////////////////////////////////////////////////////////////
 1805:  
 1806:         /// <summary>
 1807:         ///
 1808:         /// </summary>
 1809:         public static Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site> ImsServiceToSiteDictionary
 1810:         {
 1811:             get
 1812:             {
 1813:                 int fourLetterServiceDomain, fiveLetterServiceDomain;
 1814:                 string service;
 1815:                 Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site> dictionary;
 1816:  
 1817:                 var serviceIdList = Ia.Ftn.Cl.Models.Data.Service2.ImsServiceIdList;
 1818:                 var routerDomainToSiteDictionary = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.RouterDomainToSiteDictionary;
 1819:  
 1820:                 dictionary = new Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site>(serviceIdList.Count);
 1821:  
 1822:                 foreach (string s in serviceIdList)
 1823:                 {
 1824:                     service = Ia.Ftn.Cl.Models.Business.Service.ServiceIdToService(s);
 1825:  
 1826:                     if (service.Length >= 5)
 1827:                     {
 1828:                         fourLetterServiceDomain = int.Parse(service.Substring(0, 4));
 1829:                         fiveLetterServiceDomain = int.Parse(service.Substring(0, 5));
 1830:  
 1831:                         if (routerDomainToSiteDictionary.ContainsKey(fiveLetterServiceDomain)) dictionary[service] = routerDomainToSiteDictionary[fiveLetterServiceDomain];
 1832:                         else if (routerDomainToSiteDictionary.ContainsKey(fourLetterServiceDomain)) dictionary[service] = routerDomainToSiteDictionary[fourLetterServiceDomain];
 1833:                         //else throw new System.ArgumentOutOfRangeException("Service number " + service + " is out of range");
 1834:                     }
 1835:                     //else throw new System.ArgumentOutOfRangeException("Service number " + service + " is out of range");
 1836:                 }
 1837:  
 1838:                 return dictionary;
 1839:             }
 1840:         }
 1841:  
 1842:         ////////////////////////////////////////////////////////////////////////////
 1843:  
 1844:         /// <summary>
 1845:         ///
 1846:         /// </summary>
 1847:         public static Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site> MsanServiceToSiteDictionary
 1848:         {
 1849:             get
 1850:             {
 1851:                 Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site> dictionary;
 1852:  
 1853:                 var imsServiceToSiteDictionary = Ia.Ftn.Cl.Models.Data.Service2.ImsServiceToSiteDictionary;
 1854:  
 1855:                 var msanServiceList = Ia.Ftn.Cl.Models.Data.Service2.MsanServiceList;
 1856:  
 1857:                 dictionary = new Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site>(msanServiceList.Count);
 1858:  
 1859:                 foreach (string service in msanServiceList)
 1860:                 {
 1861:                     if (imsServiceToSiteDictionary.ContainsKey(service)) // I had to add this because the systems sees 2489 numbers in MSAN
 1862:                     {
 1863:                         dictionary[service] = imsServiceToSiteDictionary[service];
 1864:                     }
 1865:                 }
 1866:  
 1867:                 return dictionary;
 1868:             }
 1869:         }
 1870:  
 1871:         ////////////////////////////////////////////////////////////////////////////
 1872:  
 1873:         /// <summary>
 1874:         ///
 1875:         /// </summary>
 1876:         public static Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site> MsanServiceToSiteInAllowedToBeMigratedDomainListDictionary
 1877:         {
 1878:             get
 1879:             {
 1880:                 Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site> dictionary;
 1881:  
 1882:                 var msanServiceInAllowedToBeMigratedDomainList = Ia.Ftn.Cl.Models.Data.Service2.MsanServiceInAllowedToBeMigratedDomainList;
 1883:                 var msanServiceToSiteDictionary = Ia.Ftn.Cl.Models.Data.Service2.MsanServiceToSiteDictionary;
 1884:  
 1885:                 dictionary = new Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site>(msanServiceInAllowedToBeMigratedDomainList.Count);
 1886:  
 1887:                 foreach (string service in msanServiceInAllowedToBeMigratedDomainList)
 1888:                 {
 1889:                     if (msanServiceToSiteDictionary.ContainsKey(service)) // I had to add this because the systems sees 2489 numbers in MSAN
 1890:                     {
 1891:                         dictionary[service] = msanServiceToSiteDictionary[service];
 1892:                     }
 1893:                 }
 1894:  
 1895:                 return dictionary;
 1896:             }
 1897:         }
 1898:  
 1899:         ////////////////////////////////////////////////////////////////////////////
 1900:  
 1901:         /// <summary>
 1902:         ///
 1903:         /// </summary>
 1904:         public static Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site> PstnServiceToSiteDictionary
 1905:         {
 1906:             get
 1907:             {
 1908:                 int fourLetterServiceDomain, fiveLetterServiceDomain;
 1909:                 string service;
 1910:                 Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site> dictionary;
 1911:  
 1912:                 var serviceIdList = Ia.Ftn.Cl.Models.Data.Service2.PstnServiceIdList;
 1913:                 var routerDomainToSiteDictionary = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.RouterDomainToSiteDictionary;
 1914:  
 1915:                 dictionary = new Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site>(serviceIdList.Count);
 1916:  
 1917:                 foreach (string s in serviceIdList)
 1918:                 {
 1919:                     service = Ia.Ftn.Cl.Models.Business.Service.ServiceIdToService(s);
 1920:  
 1921:                     if (service.Length >= 5)
 1922:                     {
 1923:                         fourLetterServiceDomain = int.Parse(service.Substring(0, 4));
 1924:                         fiveLetterServiceDomain = int.Parse(service.Substring(0, 5));
 1925:  
 1926:                         if (routerDomainToSiteDictionary.ContainsKey(fiveLetterServiceDomain)) dictionary[service] = routerDomainToSiteDictionary[fiveLetterServiceDomain];
 1927:                         else if (routerDomainToSiteDictionary.ContainsKey(fourLetterServiceDomain)) dictionary[service] = routerDomainToSiteDictionary[fourLetterServiceDomain];
 1928:                         //else throw new System.ArgumentOutOfRangeException("Service number " + service + " is out of range");
 1929:                     }
 1930:                     //else throw new System.ArgumentOutOfRangeException("Service number " + service + " is out of range");
 1931:                 }
 1932:  
 1933:                 return dictionary;
 1934:             }
 1935:         }
 1936:  
 1937:         ////////////////////////////////////////////////////////////////////////////
 1938:  
 1939:         /// <summary>
 1940:         ///
 1941:         /// </summary>
 1942:         public static Dictionary<string, string> ServiceNotInServiceRequestServiceToSiteDictionary
 1943:         {
 1944:             get
 1945:             {
 1946:                 string service, siteName;
 1947:                 Dictionary<string, string> dictionary;
 1948:  
 1949:                 var serviceToSiteNameDictionary = Ia.Ftn.Cl.Models.Data.Service2.ServiceToSiteDictionary;
 1950:                 var serviceRequestServiceServiceToSiteNameDictionary = Ia.Ftn.Cl.Models.Data.ServiceRequestService.ServiceToSiteDictionary;
 1951:  
 1952:                 dictionary = new Dictionary<string, string>();
 1953:  
 1954:                 foreach (var kvp in serviceToSiteNameDictionary)
 1955:                 {
 1956:                     service = kvp.Key;
 1957:                     siteName = kvp.Value.Name;
 1958:  
 1959:                     if (!serviceRequestServiceServiceToSiteNameDictionary.ContainsKey(service)) dictionary.Add(service, siteName);
 1960:                 }
 1961:  
 1962:                 return dictionary;
 1963:             }
 1964:         }
 1965:  
 1966:         ////////////////////////////////////////////////////////////////////////////
 1967:  
 1968:         /// <summary>
 1969:         ///
 1970:         /// </summary>
 1971:         public static Dictionary<string, string> ServiceNotInProvisionedServiceRequestServiceToSiteDictionary
 1972:         {
 1973:             get
 1974:             {
 1975:                 string service, siteName;
 1976:                 Dictionary<string, string> dictionary;
 1977:  
 1978:                 var serviceToSiteNameDictionary = Ia.Ftn.Cl.Models.Data.Service2.ServiceToSiteDictionary;
 1979:                 var serviceRequestServiceProvisionedServiceToSiteNameDictionary = Ia.Ftn.Cl.Models.Data.ServiceRequestService.ProvisionedServiceToSiteDictionary;
 1980:  
 1981:                 dictionary = new Dictionary<string, string>();
 1982:  
 1983:                 foreach (var kvp in serviceToSiteNameDictionary)
 1984:                 {
 1985:                     service = kvp.Key;
 1986:                     siteName = kvp.Value.Name;
 1987:  
 1988:                     if (!serviceRequestServiceProvisionedServiceToSiteNameDictionary.ContainsKey(service)) dictionary.Add(service, siteName);
 1989:                 }
 1990:  
 1991:                 return dictionary;
 1992:             }
 1993:         }
 1994:  
 1995:         ////////////////////////////////////////////////////////////////////////////
 1996:  
 1997:         /// <summary>
 1998:         ///
 1999:         /// </summary>
 2000:         public static Dictionary<string, string> ImsServiceNotInProvisionedServiceRequestServiceToSiteDictionary
 2001:         {
 2002:             get
 2003:             {
 2004:                 string service, siteName;
 2005:                 Dictionary<string, string> dictionary;
 2006:  
 2007:                 var serviceToSiteNameDictionary = Ia.Ftn.Cl.Models.Data.Service2.ImsServiceToSiteDictionary;
 2008:                 var serviceRequestServiceProvisionedServiceToSiteNameDictionary = Ia.Ftn.Cl.Models.Data.ServiceRequestService.ProvisionedServiceToSiteDictionary;
 2009:  
 2010:                 var doesNotExistInSrsList = Ia.Ftn.Cl.Models.Data.Service2.ServiceImsServicesThatDoNotExistInServiceRequestServicesList();
 2011:  
 2012:                 dictionary = new Dictionary<string, string>();
 2013:  
 2014:                 foreach (var kvp in serviceToSiteNameDictionary)
 2015:                 {
 2016:                     service = kvp.Key;
 2017:                     siteName = kvp.Value.Name;
 2018:  
 2019:                     if (!serviceRequestServiceProvisionedServiceToSiteNameDictionary.ContainsKey(service))
 2020:                     {
 2021:                         if (!doesNotExistInSrsList.Contains(service))
 2022:                         {
 2023:                             dictionary.Add(service, siteName);
 2024:                         }
 2025:                     }
 2026:                 }
 2027:  
 2028:                 return dictionary;
 2029:             }
 2030:         }
 2031:  
 2032:  
 2033:         ////////////////////////////////////////////////////////////////////////////
 2034:  
 2035:         /// <summary>
 2036:         ///
 2037:         /// </summary>
 2038:         public static List<string> ServiceImsServicesThatDoNotExistInServiceRequestServicesList()
 2039:         {
 2040:             List<string> list;
 2041:  
 2042:             using (var db = new Ia.Ftn.Cl.Db())
 2043:             {
 2044:                 /*
 2045: select s.Service from Service2 s
 2046: left outer join ServiceRequestServices srs on srs.Service = s.Service
 2047: where s.ServiceType = 1 and srs.Id is null
 2048:                  */
 2049:  
 2050:                 list = (from s in db.Service2
 2051:                         join srs in db.ServiceRequestServices on s.Service equals srs.Service into srs2
 2052:                         from srs3 in srs2.DefaultIfEmpty()
 2053:                         where srs3 == null && s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService
 2054:                         select s.Service).ToList();
 2055:             }
 2056:  
 2057:             return list;
 2058:         }
 2059:  
 2060:         ////////////////////////////////////////////////////////////////////////////
 2061:  
 2062:         /// <summary>
 2063:         ///
 2064:         /// </summary>
 2065:         public static Dictionary<string, string> PstnServiceNotInProvisionedServiceRequestServiceToSiteDictionary
 2066:         {
 2067:             get
 2068:             {
 2069:                 string service, siteName;
 2070:                 Dictionary<string, string> dictionary;
 2071:  
 2072:                 var serviceToSiteNameDictionary = Ia.Ftn.Cl.Models.Data.Service2.PstnServiceToSiteDictionary;
 2073:                 var serviceRequestServiceProvisionedServiceToSiteNameDictionary = Ia.Ftn.Cl.Models.Data.ServiceRequestService.ProvisionedServiceToSiteDictionary;
 2074:  
 2075:                 var doesNotExistInSrsList = Ia.Ftn.Cl.Models.Data.Service2.ServiceImsServicesThatDoNotExistInServiceRequestServicesList();
 2076:  
 2077:                 dictionary = new Dictionary<string, string>();
 2078:  
 2079:                 foreach (var kvp in serviceToSiteNameDictionary)
 2080:                 {
 2081:                     service = kvp.Key;
 2082:                     siteName = kvp.Value.Name;
 2083:  
 2084:                     if (!serviceRequestServiceProvisionedServiceToSiteNameDictionary.ContainsKey(service))
 2085:                     {
 2086:                         if (!doesNotExistInSrsList.Contains(service))
 2087:                         {
 2088:                             dictionary.Add(service, siteName);
 2089:                         }
 2090:                     }
 2091:                 }
 2092:  
 2093:                 return dictionary;
 2094:             }
 2095:         }
 2096:  
 2097:         ////////////////////////////////////////////////////////////////////////////
 2098:  
 2099:         /// <summary>
 2100:         ///
 2101:         /// </summary>
 2102:         public static Dictionary<string, int> PstnFiveDigitDomainToCountOfServicesDictionary()
 2103:         {
 2104:             var dictionary = new Dictionary<string, int>();
 2105:  
 2106:             using (var db = new Ia.Ftn.Cl.Db())
 2107:             {
 2108:                 /*
 2109: select substring(s.Service,1,5), count(s.Service)
 2110: from Service2 s
 2111: where ServiceType = 2 -- PSTN
 2112: group by substring(s.Service,1,5)
 2113:                  */
 2114:  
 2115:                 dictionary = (from s in db.Service2
 2116:                               where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.PstnService
 2117:                               group s.Service.Substring(0, 5) by s.Service.Substring(0, 5) into g
 2118:                               select new { PstnFiveDigitDomain = g.Key, ServiceCount = g.Count() }).AsNoTracking().ToDictionary(t => t.PstnFiveDigitDomain, t => t.ServiceCount);
 2119:             }
 2120:  
 2121:             return dictionary;
 2122:         }
 2123:  
 2124:         ////////////////////////////////////////////////////////////////////////////
 2125:  
 2126:         /// <summary>
 2127:         ///
 2128:         /// </summary>
 2129:         public static void UpdatePstnServiceAccess(string service, string newAccessId, string userId, out Ia.Cl.Models.Result result)
 2130:         {
 2131:             int serviceType;
 2132:             string service2Id;
 2133:             Ia.Ftn.Cl.Models.Service2 service2;
 2134:  
 2135:             result = new Ia.Cl.Models.Result();
 2136:  
 2137:             serviceType = Ia.Ftn.Cl.Models.Business.Service.ServiceType.PstnService; // PSTN
 2138:             service2Id = Ia.Ftn.Cl.Models.Business.Service2.ServiceId(service, serviceType);
 2139:  
 2140:             using (var db = new Ia.Ftn.Cl.Db())
 2141:             {
 2142:                 service2 = (from s in db.Service2 where s.Id == service2Id select s).SingleOrDefault();
 2143:  
 2144:                 if (service2 != null)
 2145:                 {
 2146:                     if (!string.IsNullOrEmpty(newAccessId))
 2147:                     {
 2148:                         if (service2.Access == null || service2.Access != null && service2.Access.Id != newAccessId)
 2149:                         {
 2150:                             service2.Access = (from a in db.Accesses where a.Id == newAccessId select a).SingleOrDefault();
 2151:  
 2152:                             db.Service2.Attach(service2);
 2153:                             db.Entry(service2).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
 2154:  
 2155:                             db.SaveChanges();
 2156:  
 2157:                             result.AddSuccess("Service " + service + " was updated with access " + service2.Access.Name + " (تم تحديث ربط الجهاز بالرقم). ");
 2158:                         }
 2159:                         else
 2160:                         {
 2161:                             result.AddWarning("Service access value was not updated because submitted data is the same as current data and because access is not null (لم يتم تغيير الجهاز المربوط بالرقم لأن المعلومات المعطاة هي ذاتها لم تتغير ولأن الجهاز معرف). ");
 2162:                         }
 2163:                     }
 2164:                     else //if(string.IsNullOrEmpty(updatedAccessId))
 2165:                     {
 2166:                         if (service2.Access != null)
 2167:                         {
 2168:                             service2.Access = (from a in db.Accesses where a.Id == string.Empty select a).SingleOrDefault();
 2169:                             service2.Port = Ia.Ftn.Cl.Models.Business.Default.PortUndefinedOrInvalidOrUnknown;
 2170:  
 2171:                             db.Service2.Attach(service2);
 2172:                             db.Entry(service2).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
 2173:  
 2174:                             db.SaveChanges();
 2175:  
 2176:                             result.AddSuccess("Service " + service + " was updated with null access and " + Ia.Ftn.Cl.Models.Business.Default.PortUndefinedOrInvalidOrUnknown + " port (تم مسح ربط الجهاز بالرقم ومسح المنفذ). ");
 2177:                         }
 2178:                         else
 2179:                         {
 2180:                             result.AddWarning("Service access and port values were not reset because submitted data (access null and port " + Ia.Ftn.Cl.Models.Business.Default.PortUndefinedOrInvalidOrUnknown + ") is the same as current data (لم يتم تغيير الجهاز المربوط بالرقم أو المنفذ لأن المعلومات المعطاة هي ذاتها لم تتغير). ");
 2181:                         }
 2182:                     }
 2183:                 }
 2184:                 else
 2185:                 {
 2186:                     result.AddWarning("Service " + service + " does not exist (رقم الخدمة غير موجود). ");
 2187:                 }
 2188:             }
 2189:         }
 2190:  
 2191:         ////////////////////////////////////////////////////////////////////////////
 2192:  
 2193:         /// <summary>
 2194:         ///
 2195:         /// </summary>
 2196:         public static void UpdateImsServiceAccessAndPort(string service, string accessId, int port, string userId, out Ia.Cl.Models.Result result)
 2197:         {
 2198:             int serviceType;
 2199:             string service2Id;
 2200:             Ia.Ftn.Cl.Models.Service2 service2;
 2201:  
 2202:             result = new Ia.Cl.Models.Result();
 2203:  
 2204:             serviceType = Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService;
 2205:             service2Id = Ia.Ftn.Cl.Models.Business.Service2.ServiceId(service, serviceType);
 2206:  
 2207:             using (var db = new Ia.Ftn.Cl.Db())
 2208:             {
 2209:                 service2 = (from s in db.Service2 where s.Id == service2Id select s).Include(s => s.Access).SingleOrDefault();
 2210:  
 2211:                 if (service2 != null)
 2212:                 {
 2213:                     if (!string.IsNullOrEmpty(accessId))
 2214:                     {
 2215:                         if (service2.Access == null || service2.Access != null && (service2.Access.Id != accessId || service2.Port != port))
 2216:                         {
 2217:                             service2.Access = (from a in db.Accesses where a.Id == accessId select a).SingleOrDefault();
 2218:                             service2.Port = port;
 2219:  
 2220:                             db.Service2.Attach(service2);
 2221:                             db.Entry(service2).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
 2222:  
 2223:                             db.SaveChanges();
 2224:  
 2225:                             result.AddSuccess("Service " + service + " was updated with access " + service2.Access.Name + " and port " + port);
 2226:                         }
 2227:                         else
 2228:                         {
 2229:                             result.AddWarning("Service access not updated");
 2230:                         }
 2231:                     }
 2232:                     else
 2233:                     {
 2234:                         if (service2.Access != null)
 2235:                         {
 2236:                             service2.Access = (from a in db.Accesses where a.Id == string.Empty select a).SingleOrDefault();
 2237:                             service2.Port = Ia.Ftn.Cl.Models.Business.Default.PortUndefinedOrInvalidOrUnknown;
 2238:  
 2239:                             db.Service2.Attach(service2);
 2240:                             db.Entry(service2).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
 2241:  
 2242:                             db.SaveChanges();
 2243:  
 2244:                             result.AddSuccess("Service " + service + " was updated with null access and " + Ia.Ftn.Cl.Models.Business.Default.PortUndefinedOrInvalidOrUnknown + " port.");
 2245:                         }
 2246:                         else
 2247:                         {
 2248:                             result.AddWarning("Service access not reset.");
 2249:                         }
 2250:                     }
 2251:                 }
 2252:                 else
 2253:                 {
 2254:                     result.AddWarning("Service " + service + " does not exist.");
 2255:                 }
 2256:             }
 2257:         }
 2258:  
 2259:         ////////////////////////////////////////////////////////////////////////////
 2260:  
 2261:         /// <summary>
 2262:         ///
 2263:         /// </summary>
 2264:         public static void ProvisioningStateOfServicesWithinPstnSite(int siteId, out List<string> provisionedServiceList, out List<string> unprovisionedServiceList)
 2265:         {
 2266:             var site = (from s in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.PstnList
 2267:                         where s.Id == siteId
 2268:                         select s).SingleOrDefault();
 2269:  
 2270:             if (site != null)
 2271:             {
 2272:                 provisionedServiceList = new List<string>();
 2273:                 unprovisionedServiceList = new List<string>();
 2274:  
 2275:                 using (var db = new Ia.Ftn.Cl.Db())
 2276:                 {
 2277:                     var provisionedService0List = (from s in db.Service2
 2278:                                                    join srs in db.ServiceRequestServices on s.Service equals srs.Service
 2279:                                                    where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.PstnService && srs.Provisioned == true
 2280:                                                    select s.Service).AsNoTracking().ToList();
 2281:  
 2282:                     foreach (var s in provisionedService0List)
 2283:                     {
 2284:                         if (site.DomainList.Any(u => s.StartsWith(u.ToString()))) provisionedServiceList.Add(s);
 2285:                     }
 2286:  
 2287:                     var unprovisionedService0List = (from s in db.Service2
 2288:                                                      join srs in db.ServiceRequestServices on s.Service equals srs.Service
 2289:                                                      where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.PstnService && srs.Provisioned == false
 2290:                                                      select s.Service).AsNoTracking().ToList();
 2291:  
 2292:                     foreach (var s in unprovisionedService0List)
 2293:                     {
 2294:                         if (site.DomainList.Any(u => s.StartsWith(u.ToString()))) unprovisionedServiceList.Add(s);
 2295:                     }
 2296:                 }
 2297:             }
 2298:             else
 2299:             {
 2300:                 provisionedServiceList = new List<string>();
 2301:                 unprovisionedServiceList = new List<string>();
 2302:             }
 2303:         }
 2304:  
 2305:         ////////////////////////////////////////////////////////////////////////////
 2306:         ////////////////////////////////////////////////////////////////////////////
 2307:     }
 2308:  
 2309:     ////////////////////////////////////////////////////////////////////////////
 2310:     ////////////////////////////////////////////////////////////////////////////
 2311: }