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

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

Find subscriber and network information support class for the Fixed Telecommunications Network data model

    1: using System.Data;
    2: using System.Linq;
    3: using System.Collections.Generic;
    4: using Microsoft.EntityFrameworkCore;
    5: using System.Diagnostics;
    6:  
    7: namespace Ia.Ftn.Cl.Models.Data.Maintenance
    8: {
    9:     ////////////////////////////////////////////////////////////////////////////
   10:  
   11:     /// <summary publish="true">
   12:     /// Find subscriber and network information support class for the Fixed Telecommunications Network data model
   13:     /// </summary>
   14:     /// 
   15:     /// <remarks> 
   16:     /// Copyright © 2006-2021 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   17:     ///
   18:     /// This library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
   19:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   20:     ///
   21:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   22:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   23:     /// 
   24:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   25:     /// 
   26:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   27:     /// </remarks> 
   28:     public class Find
   29:     {
   30:         ////////////////////////////////////////////////////////////////////////////
   31:  
   32:         /// <summary>
   33:         ///
   34:         /// </summary>
   35:         public Find() { }
   36:  
   37:         ////////////////////////////////////////////////////////////////////////////
   38:  
   39:         /// <summary>
   40:         /// 
   41:         /// </summary>
   42:         public static List<Ia.Ftn.Cl.Models.Ui.ServiceRequestService> ServiceRequestServiceList(List<string> serviceRequestServiceIdList)
   43:         {
   44:             List<Ia.Ftn.Cl.Models.ServiceRequestService> inList;
   45:             List<Ia.Ftn.Cl.Models.Ui.ServiceRequestService> list;
   46:  
   47:             using (var db = new Ia.Ftn.Cl.Db())
   48:             {
   49:                 if (serviceRequestServiceIdList.Count > 0)
   50:                 {
   51:                     inList = (from srs in db.ServiceRequestServices where serviceRequestServiceIdList.Contains(srs.Id) select srs).Include(u => u.Access).AsNoTracking().ToList();
   52:  
   53:                     list = (from srs in inList
   54:                             select new Ia.Ftn.Cl.Models.Ui.ServiceRequestService()
   55:                             {
   56:                                 Id = srs.Id,
   57:                                 AbbriviatedCalling = srs.AbbriviatedCalling,
   58:                                 Access = srs.Access,
   59:                                 AlarmCall = srs.AlarmCall,
   60:                                 CallBarring = srs.CallBarring,
   61:                                 CallerId = srs.CallerId,
   62:                                 CallForwarding = srs.CallForwarding,
   63:                                 CallWaiting = srs.CallWaiting,
   64:                                 ConferenceCall = srs.ConferenceCall,
   65:                                 Created = srs.Created,
   66:                                 InternationalCalling = srs.InternationalCalling,
   67:                                 InternationalCallingUserControlled = srs.InternationalCallingUserControlled,
   68:                                 LastRequestDateTime = srs.LastRequestDateTime,
   69:                                 Provisioned = srs.Provisioned,
   70:                                 Service = srs.Service,
   71:                                 Serial = srs.Serial,
   72:                                 ServiceType = srs.ServiceType,
   73:                                 //ServiceSuspension = srs.ServiceSuspension,
   74:                                 Type = srs.Type,
   75:                                 Updated = srs.Updated
   76:                             }).ToList();
   77:                 }
   78:                 else list = new List<Ia.Ftn.Cl.Models.Ui.ServiceRequestService>();
   79:  
   80:                 return list.Distinct().ToList();
   81:             }
   82:         }
   83:  
   84:         ////////////////////////////////////////////////////////////////////////////
   85:  
   86:         /// <summary>
   87:         /// 
   88:         /// </summary>
   89:         public static List<Ia.Ftn.Cl.Models.ServiceRequest> ServiceRequestList(List<int> serviceRequestIdList)
   90:         {
   91:             List<Ia.Ftn.Cl.Models.ServiceRequest> list;
   92:  
   93:             using (var db = new Ia.Ftn.Cl.Db())
   94:             {
   95:                 if (serviceRequestIdList.Count > 0)
   96:                 {
   97:                     list = (from sr in db.ServiceRequests
   98:                             where serviceRequestIdList.Contains(sr.Id)
   99:                             select sr).AsNoTracking().ToList();
  100:                 }
  101:                 else list = new List<Ia.Ftn.Cl.Models.ServiceRequest>();
  102:             }
  103:  
  104:             return list.Distinct().ToList();
  105:         }
  106:  
  107:         ////////////////////////////////////////////////////////////////////////////
  108:  
  109:         /// <summary>
  110:         /// 
  111:         /// </summary>
  112:         public static List<Ia.Ftn.Cl.Models.ServiceRequestAdministrativeIssue> ServiceRequestAdministrativeIssueList(List<string> serviceRequestAdministrativeIssueIdList)
  113:         {
  114:             List<Ia.Ftn.Cl.Models.ServiceRequestAdministrativeIssue> list;
  115:  
  116:             using (var db = new Ia.Ftn.Cl.Db())
  117:             {
  118:                 if (serviceRequestAdministrativeIssueIdList.Count > 0)
  119:                 {
  120:                     list = (from srai in db.ServiceRequestAdministrativeIssues
  121:                             where serviceRequestAdministrativeIssueIdList.Contains(srai.Id)
  122:                             select srai).AsNoTracking().ToList();
  123:                 }
  124:                 else list = new List<Ia.Ftn.Cl.Models.ServiceRequestAdministrativeIssue>();
  125:             }
  126:  
  127:             return list.Distinct().ToList();
  128:         }
  129:  
  130:         ////////////////////////////////////////////////////////////////////////////
  131:  
  132:         /// <summary>
  133:         /// 
  134:         /// </summary>
  135:         public static List<Ia.Ftn.Cl.Models.ServiceRequestHistory> ServiceRequestHistoryList(List<string> serviceRequestHistoryIdList)
  136:         {
  137:             List<Ia.Ftn.Cl.Models.ServiceRequestHistory> list;
  138:  
  139:             using (var db = new Ia.Ftn.Cl.Db())
  140:             {
  141:                 if (serviceRequestHistoryIdList.Count > 0)
  142:                 {
  143:                     list = (from srh in db.ServiceRequestHistories
  144:                             where serviceRequestHistoryIdList.Contains(srh.Id)
  145:                             select srh).AsNoTracking().ToList();
  146:                 }
  147:                 else list = new List<Ia.Ftn.Cl.Models.ServiceRequestHistory>();
  148:             }
  149:  
  150:             return list.Distinct().ToList();
  151:         }
  152:  
  153:         ////////////////////////////////////////////////////////////////////////////
  154:  
  155:         /// <summary>
  156:         /// 
  157:         /// </summary>
  158:         public static List<Ia.Ftn.Cl.Models.ServiceRequest> ServiceRequestListForCustomerId(int customerId, int maxNumberOfResults)
  159:         {
  160:             List<Ia.Ftn.Cl.Models.ServiceRequest> list;
  161:  
  162:             using (var db = new Ia.Ftn.Cl.Db())
  163:             {
  164:                 list = (from sr in db.ServiceRequests
  165:                         where sr.CustomerId == customerId
  166:                         select sr).AsNoTracking().Take(maxNumberOfResults).ToList();
  167:             }
  168:  
  169:             return list.Distinct().ToList();
  170:         }
  171:  
  172:         ////////////////////////////////////////////////////////////////////////////
  173:  
  174:         /// <summary>
  175:         /// 
  176:         /// </summary>
  177:         public static List<Ia.Ftn.Cl.Models.ServiceRequest> ServiceRequestListForCustomerName(string customerName, int maxNumberOfResults)
  178:         {
  179:             List<Ia.Ftn.Cl.Models.ServiceRequest> list;
  180:  
  181:             using (var db = new Ia.Ftn.Cl.Db())
  182:             {
  183:                 if (!string.IsNullOrEmpty(customerName))
  184:                 {
  185:                     list = (from sr in db.ServiceRequests
  186:                             where sr.CustomerName == customerName || sr.CustomerName.Contains(customerName)
  187:                             select sr).Take(maxNumberOfResults).AsNoTracking().ToList();
  188:                 }
  189:                 else list = new List<Ia.Ftn.Cl.Models.ServiceRequest>();
  190:             }
  191:  
  192:             return list.Distinct().ToList();
  193:         }
  194:  
  195:         ////////////////////////////////////////////////////////////////////////////
  196:  
  197:         /// <summary>
  198:         /// 
  199:         /// </summary>
  200:         public static List<Ia.Ftn.Cl.Models.ServiceRequestType> ServiceRequestTypeList(List<int> serviceRequestTypeIdList)
  201:         {
  202:             List<Ia.Ftn.Cl.Models.ServiceRequestType> list;
  203:  
  204:             using (var db = new Ia.Ftn.Cl.Db())
  205:             {
  206:                 if (serviceRequestTypeIdList.Count > 0)
  207:                 {
  208:                     list = (from srt in db.ServiceRequestTypes
  209:                             where serviceRequestTypeIdList.Contains(srt.Id)
  210:                             select srt).AsNoTracking().ToList();
  211:                 }
  212:                 else list = new List<Ia.Ftn.Cl.Models.ServiceRequestType>();
  213:             }
  214:  
  215:             return list.Distinct().ToList();
  216:         }
  217:  
  218:         ////////////////////////////////////////////////////////////////////////////
  219:  
  220:         /// <summary>
  221:         /// 
  222:         /// </summary>
  223:         public static List<Ia.Ftn.Cl.Models.Ui.Nokia.AgcfGatewayRecord> AgcfGatewayRecordList(List<int> agcfGatewayRecordIdList)
  224:         {
  225:             List<Ia.Ftn.Cl.Models.Ui.Nokia.AgcfGatewayRecord> list;
  226:  
  227:             using (var db = new Ia.Ftn.Cl.Db())
  228:             {
  229:                 if (agcfGatewayRecordIdList.Count > 0)
  230:                 {
  231:                     list = (from gr in db.AgcfGatewayRecords
  232:                             where agcfGatewayRecordIdList.Contains(gr.Id)
  233:                             select new Ia.Ftn.Cl.Models.Ui.Nokia.AgcfGatewayRecord()
  234:                             {
  235:                                 Id = gr.Id,
  236:                                 GwId = gr.GwId,
  237:                                 GwUserId = gr.GwUserId,
  238:                                 GwDomain = gr.GwDomain,
  239:                                 GwName = gr.GwName,
  240:                                 IP1 = gr.IP1,
  241:                                 IP2 = gr.IP2,
  242:                                 MateExternalIPAddr = gr.MateExternalIPAddr,
  243:                                 IsPrimary = gr.IsPrimary,
  244:                                 Created = gr.Created,
  245:                                 Updated = gr.Updated
  246:                             }).AsNoTracking().ToList();
  247:                 }
  248:                 else list = new List<Ia.Ftn.Cl.Models.Ui.Nokia.AgcfGatewayRecord>();
  249:             }
  250:  
  251:             return list.Distinct().ToList();
  252:         }
  253:  
  254:         ////////////////////////////////////////////////////////////////////////////
  255:  
  256:         /// <summary>
  257:         /// 
  258:         /// </summary>
  259:         public static List<Ia.Ftn.Cl.Models.Ui.Nokia.AgcfEndpoint> AgcfEndpointList(List<string> agcfEndpointIdList)
  260:         {
  261:             List<Ia.Ftn.Cl.Models.Ui.Nokia.AgcfEndpoint> list;
  262:  
  263:             using (var db = new Ia.Ftn.Cl.Db())
  264:             {
  265:                 if (agcfEndpointIdList.Count > 0)
  266:                 {
  267:                     list = (from e in db.AgcfEndpoints
  268:                             where agcfEndpointIdList.Contains(e.Id)
  269:                             select new Ia.Ftn.Cl.Models.Ui.Nokia.AgcfEndpoint()
  270:                             {
  271:                                 Id = e.Id,
  272:                                 PrividUser = e.PrividUser,
  273:                                 GwId = e.GwId,
  274:                                 Dn = e.Dn,
  275:                                 FlatTermID = e.FlatTermID,
  276:                                 CallHoldLc = e.CallHoldLc,
  277:                                 CallWaitingLc = e.CallWaitingLc,
  278:                                 CallToggleLc = e.CallToggleLc,
  279:                                 ThreeWayCallLc = e.ThreeWayCallLc,
  280:                                 McidLc = e.McidLc,
  281:                                 Password = e.Password,
  282:                                 CallTransferLc = e.CallTransferLc,
  283:                                 Created = e.Created,
  284:                                 Updated = e.Updated
  285:                             }).AsNoTracking().ToList();
  286:                 }
  287:                 else list = new List<Ia.Ftn.Cl.Models.Ui.Nokia.AgcfEndpoint>();
  288:             }
  289:  
  290:             return list.Distinct().ToList();
  291:         }
  292:  
  293:         ////////////////////////////////////////////////////////////////////////////
  294:  
  295:         /// <summary>
  296:         /// 
  297:         /// </summary>
  298:         public static List<Ia.Ftn.Cl.Models.Huawei.Mgw> MgwList(List<string> mgwIdList)
  299:         {
  300:             List<Ia.Ftn.Cl.Models.Huawei.Mgw> list;
  301:  
  302:             using (var db = new Ia.Ftn.Cl.Db())
  303:             {
  304:                 if (mgwIdList.Count > 0)
  305:                 {
  306:                     list = (from m in db.Mgws
  307:                             where mgwIdList.Contains(m.Id)
  308:                             select m).AsNoTracking().ToList();
  309:                 }
  310:                 else list = new List<Ia.Ftn.Cl.Models.Huawei.Mgw>();
  311:             }
  312:  
  313:             return list.Distinct().ToList();
  314:         }
  315:  
  316:         ////////////////////////////////////////////////////////////////////////////
  317:  
  318:         /// <summary>
  319:         /// 
  320:         /// </summary>
  321:         public static List<Ia.Ftn.Cl.Models.Huawei.Asbr> AsbrList(List<string> asbrIdList)
  322:         {
  323:             List<Ia.Ftn.Cl.Models.Huawei.Asbr> list;
  324:  
  325:             using (var db = new Ia.Ftn.Cl.Db())
  326:             {
  327:                 if (asbrIdList.Count > 0)
  328:                 {
  329:                     list = (from a in db.Asbrs
  330:                             where asbrIdList.Contains(a.Id)
  331:                             select a).AsNoTracking().ToList();
  332:                 }
  333:                 else list = new List<Ia.Ftn.Cl.Models.Huawei.Asbr>();
  334:             }
  335:  
  336:             return list.Distinct().ToList();
  337:         }
  338:  
  339:         ////////////////////////////////////////////////////////////////////////////
  340:  
  341:         /// <summary>
  342:         /// 
  343:         /// </summary>
  344:         public static List<Ia.Ftn.Cl.Models.Huawei.EmsDev> EmsDevList(List<int> emsDevIdList)
  345:         {
  346:             List<Ia.Ftn.Cl.Models.Huawei.EmsDev> list;
  347:  
  348:             using (var db = new Ia.Ftn.Cl.Db())
  349:             {
  350:                 if (emsDevIdList.Count > 0)
  351:                 {
  352:                     list = (from ed in db.EmsDevs
  353:                             where emsDevIdList.Contains(ed.Id)
  354:                             select ed).AsNoTracking().ToList();
  355:                 }
  356:                 else list = new List<Ia.Ftn.Cl.Models.Huawei.EmsDev>();
  357:             }
  358:  
  359:             return list.Distinct().ToList();
  360:         }
  361:  
  362:         ////////////////////////////////////////////////////////////////////////////
  363:  
  364:         /// <summary>
  365:         /// 
  366:         /// </summary>
  367:         public static List<Ia.Ftn.Cl.Models.Huawei.EmsDev> EmsDevListFromEmsOntIdList(List<string> emsOntIdList)
  368:         {
  369:             List<Ia.Ftn.Cl.Models.Huawei.EmsDev> list;
  370:  
  371:             using (var db = new Ia.Ftn.Cl.Db())
  372:             {
  373:                 if (emsOntIdList.Count > 0)
  374:                 {
  375:                     list = (from ed in db.EmsDevs
  376:                             join eb in db.EmsBoards on ed.Id equals eb.EmsDev.Id
  377:                             join ep in db.EmsPorts on eb.Id equals ep.EmsBoard.Id
  378:                             join eo in db.EmsOnts on ep.Id equals eo.EmsPort.Id
  379:                             where emsOntIdList.Contains(eo.Id)
  380:                             select ed).AsNoTracking().ToList();
  381:                 }
  382:                 else list = new List<Ia.Ftn.Cl.Models.Huawei.EmsDev>();
  383:             }
  384:  
  385:             return list.Distinct().ToList();
  386:         }
  387:  
  388:         ////////////////////////////////////////////////////////////////////////////
  389:  
  390:         /// <summary>
  391:         /// 
  392:         /// </summary>
  393:         public static List<Ia.Ftn.Cl.Models.Huawei.EmsBoard> EmsBoardList(List<string> emsBoardIdList)
  394:         {
  395:             List<Ia.Ftn.Cl.Models.Huawei.EmsBoard> list;
  396:  
  397:             using (var db = new Ia.Ftn.Cl.Db())
  398:             {
  399:                 if (emsBoardIdList.Count > 0)
  400:                 {
  401:                     list = (from eb in db.EmsBoards
  402:                             where emsBoardIdList.Contains(eb.Id)
  403:                             select eb).AsNoTracking().ToList();
  404:                 }
  405:                 else list = new List<Ia.Ftn.Cl.Models.Huawei.EmsBoard>();
  406:             }
  407:  
  408:             return list.Distinct().ToList();
  409:         }
  410:  
  411:         ////////////////////////////////////////////////////////////////////////////
  412:  
  413:         /// <summary>
  414:         /// 
  415:         /// </summary>
  416:         public static List<Ia.Ftn.Cl.Models.Huawei.EmsBoard> EmsBoardListFromEmsOntIdList(List<string> emsOntIdList)
  417:         {
  418:             List<Ia.Ftn.Cl.Models.Huawei.EmsBoard> list;
  419:  
  420:             using (var db = new Ia.Ftn.Cl.Db())
  421:             {
  422:                 if (emsOntIdList.Count > 0)
  423:                 {
  424:                     list = (from eb in db.EmsBoards
  425:                             join ep in db.EmsPorts on eb.Id equals ep.EmsBoard.Id
  426:                             join eo in db.EmsOnts on ep.Id equals eo.EmsPort.Id
  427:                             where emsOntIdList.Contains(eo.Id)
  428:                             select eb).AsNoTracking().ToList();
  429:                 }
  430:                 else list = new List<Ia.Ftn.Cl.Models.Huawei.EmsBoard>();
  431:             }
  432:  
  433:             return list.Distinct().ToList();
  434:         }
  435:  
  436:         ////////////////////////////////////////////////////////////////////////////
  437:  
  438:         /// <summary>
  439:         /// 
  440:         /// </summary>
  441:         public static List<Ia.Ftn.Cl.Models.Huawei.EmsPort> EmsPortList(List<string> emsPortIdList)
  442:         {
  443:             List<Ia.Ftn.Cl.Models.Huawei.EmsPort> list;
  444:  
  445:             using (var db = new Ia.Ftn.Cl.Db())
  446:             {
  447:                 if (emsPortIdList.Count > 0)
  448:                 {
  449:                     list = (from ep in db.EmsPorts
  450:                             where emsPortIdList.Contains(ep.Id)
  451:                             select ep).AsNoTracking().ToList();
  452:                 }
  453:                 else list = new List<Ia.Ftn.Cl.Models.Huawei.EmsPort>();
  454:             }
  455:  
  456:             return list.Distinct().ToList();
  457:         }
  458:  
  459:         ////////////////////////////////////////////////////////////////////////////
  460:  
  461:         /// <summary>
  462:         /// 
  463:         /// </summary>
  464:         public static List<Ia.Ftn.Cl.Models.Huawei.EmsPort> EmsPortListFromEmsOntIdList(List<string> emsOntIdList)
  465:         {
  466:             List<Ia.Ftn.Cl.Models.Huawei.EmsPort> list;
  467:  
  468:             using (var db = new Ia.Ftn.Cl.Db())
  469:             {
  470:                 if (emsOntIdList.Count > 0)
  471:                 {
  472:                     list = (from ep in db.EmsPorts
  473:                             join eo in db.EmsOnts on ep.Id equals eo.EmsPort.Id
  474:                             where emsOntIdList.Contains(eo.Id)
  475:                             select ep).AsNoTracking().ToList();
  476:                 }
  477:                 else list = new List<Ia.Ftn.Cl.Models.Huawei.EmsPort>();
  478:             }
  479:  
  480:             return list.Distinct().ToList();
  481:         }
  482:  
  483:         ////////////////////////////////////////////////////////////////////////////
  484:  
  485:         /// <summary>
  486:         /// 
  487:         /// </summary>
  488:         public static List<Ia.Ftn.Cl.Models.Ui.Huawei.EmsOnt> EmsOntList(List<string> emsOntIdList)
  489:         {
  490:             List<Ia.Ftn.Cl.Models.Ui.Huawei.EmsOnt> list;
  491:  
  492:             using (var db = new Ia.Ftn.Cl.Db())
  493:             {
  494:                 if (emsOntIdList.Count > 0)
  495:                 {
  496:                     list = (from eo in db.EmsOnts
  497:                             where emsOntIdList.Contains(eo.Id)
  498:                             select new Ia.Ftn.Cl.Models.Ui.Huawei.EmsOnt()
  499:                             {
  500:                                 Id = eo.Id,
  501:                                 ResultCode = eo.ResultCode,
  502:                                 StateId = eo.StateId,
  503:                                 Access = eo.Access,
  504:                                 ALIAS = eo.ALIAS,
  505:                                 AUTH = eo.AUTH,
  506:                                 CAPABPROF = eo.CAPABPROF,
  507:                                 Created = eo.Created,
  508:                                 DEV = eo.DEV,
  509:                                 DID = eo.DID,
  510:                                 EQUIPMENTID = eo.EQUIPMENTID,
  511:                                 FN = eo.FN,
  512:                                 GATE = eo.GATE,
  513:                                 IP = eo.IP,
  514:                                 MAINSOFTVERSION = eo.MAINSOFTVERSION,
  515:                                 NAME = eo.NAME,
  516:                                 ONTID = eo.ONTID,
  517:                                 PN = eo.PN,
  518:                                 ROUTEIP = eo.ROUTEIP,
  519:                                 SERIALNUM = eo.SERIALNUM,
  520:                                 SN = eo.SN,
  521:                                 VAPROF = eo.VAPROF,
  522:                                 Updated = eo.Updated,
  523:                                 VENDORID = eo.VENDORID,
  524:                                 VLAN = eo.VLAN
  525:                             }).AsNoTracking().ToList();
  526:                 }
  527:                 else list = new List<Ia.Ftn.Cl.Models.Ui.Huawei.EmsOnt>();
  528:             }
  529:  
  530:             return list.Distinct().ToList();
  531:         }
  532:  
  533:         ////////////////////////////////////////////////////////////////////////////
  534:  
  535:         /// <summary>
  536:         /// 
  537:         /// </summary>
  538:         public static List<Ia.Ftn.Cl.Models.Huawei.EmsOntSipInfo> EmsOntSipInfoListFromEmsOntIdList(List<string> emsOntIdList)
  539:         {
  540:             List<Ia.Ftn.Cl.Models.Huawei.EmsOntSipInfo> list;
  541:  
  542:             using (var db = new Ia.Ftn.Cl.Db())
  543:             {
  544:                 if (emsOntIdList.Count > 0)
  545:                 {
  546:                     list = (from eosi in db.EmsOntSipInfoes
  547:                             where emsOntIdList.Contains(eosi.EmsOnt.Id)
  548:                             select eosi).Include(o => o.EmsOnt).AsNoTracking().ToList();
  549:                 }
  550:                 else list = new List<Ia.Ftn.Cl.Models.Huawei.EmsOntSipInfo>();
  551:             }
  552:  
  553:             return list.Distinct().ToList();
  554:         }
  555:  
  556:         ////////////////////////////////////////////////////////////////////////////
  557:  
  558:         /// <summary>
  559:         /// 
  560:         /// </summary>
  561:         public static List<Ia.Ftn.Cl.Models.Huawei.EmsVoipPstnUser> EmsVoipPstnUserList(List<string> emsVoipPstnUserIdList)
  562:         {
  563:             List<Ia.Ftn.Cl.Models.Huawei.EmsVoipPstnUser> list;
  564:  
  565:             using (var db = new Ia.Ftn.Cl.Db())
  566:             {
  567:                 if (emsVoipPstnUserIdList.Count > 0)
  568:                 {
  569:                     list = (from evpu in db.EmsVoipPstnUsers
  570:                             where emsVoipPstnUserIdList.Contains(evpu.Id)
  571:                             select evpu).Include(o => o.EmsOnt).Include(o => o.EmsOnt.Access).AsNoTracking().ToList();
  572:                 }
  573:                 else list = new List<Ia.Ftn.Cl.Models.Huawei.EmsVoipPstnUser>();
  574:             }
  575:  
  576:             return list.Distinct().ToList();
  577:         }
  578:  
  579:         ////////////////////////////////////////////////////////////////////////////
  580:  
  581:         /// <summary>
  582:         /// 
  583:         /// </summary>
  584:         public static List<string> EmsVoipPstnUserIdListFromEmsOntIdList(List<string> emsOntIdList)
  585:         {
  586:             List<string> list;
  587:  
  588:             using (var db = new Ia.Ftn.Cl.Db())
  589:             {
  590:                 if (emsOntIdList.Count > 0)
  591:                 {
  592:                     list = (from evpu in db.EmsVoipPstnUsers
  593:                             where evpu.EmsOnt != null && emsOntIdList.Contains(evpu.EmsOnt.Id)
  594:                             select evpu.Id).AsNoTracking().ToList();
  595:                 }
  596:                 else list = new List<string>();
  597:             }
  598:  
  599:             return list.Distinct().ToList();
  600:         }
  601:  
  602:         ////////////////////////////////////////////////////////////////////////////
  603:  
  604:         /// <summary>
  605:         /// 
  606:         /// </summary>
  607:         public static List<string> EmsVoipPstnUserIdListFromServiceList(List<string> serviceList)
  608:         {
  609:             List<string> serviceWithCountryCodeList, impuAidList;
  610:             List<string> list;
  611:  
  612:             // for MDUs numbers will look like 96524805054
  613:             // for MSAN numbers will look like +96524805054
  614:  
  615:             if (serviceList.Count > 0)
  616:             {
  617:                 serviceWithCountryCodeList = new List<string>();
  618:                 impuAidList = new List<string>();
  619:  
  620:                 foreach (string service in serviceList)
  621:                 {
  622:                     serviceWithCountryCodeList.Add(Ia.Ftn.Cl.Models.Business.NumberFormatConverter.ServiceWithCountryCode(service));
  623:                     impuAidList.Add(Ia.Ftn.Cl.Models.Business.NumberFormatConverter.ImpuAid(service));
  624:                 }
  625:  
  626:                 using (var db = new Ia.Ftn.Cl.Db())
  627:                 {
  628:                     list = (from evpu in db.EmsVoipPstnUsers
  629:                             where serviceWithCountryCodeList.Contains(evpu.DN) || impuAidList.Contains(evpu.DN)
  630:                             select evpu.Id).AsNoTracking().ToList();
  631:                 }
  632:             }
  633:             else list = new List<string>();
  634:  
  635:             return list.Distinct().ToList();
  636:         }
  637:  
  638:         ////////////////////////////////////////////////////////////////////////////
  639:  
  640:         /// <summary>
  641:         /// 
  642:         /// </summary>
  643:         public static List<Ia.Ftn.Cl.Models.Huawei.EmsVoipPstnUser> EmsVoipPstnUserListFromEmsOntIdList(List<string> emsOntIdList)
  644:         {
  645:             List<Ia.Ftn.Cl.Models.Huawei.EmsVoipPstnUser> list;
  646:  
  647:             using (var db = new Ia.Ftn.Cl.Db())
  648:             {
  649:                 if (emsOntIdList.Count > 0)
  650:                 {
  651:                     list = (from evpu in db.EmsVoipPstnUsers
  652:                             where evpu.EmsOnt != null && emsOntIdList.Contains(evpu.EmsOnt.Id)
  653:                             select evpu).Include(o => o.EmsOnt).AsNoTracking().ToList();
  654:                 }
  655:                 else list = new List<Ia.Ftn.Cl.Models.Huawei.EmsVoipPstnUser>();
  656:             }
  657:  
  658:             return list.Distinct().ToList();
  659:         }
  660:  
  661:         ////////////////////////////////////////////////////////////////////////////
  662:  
  663:         /// <summary>
  664:         /// 
  665:         /// </summary>
  666:         public static List<Ia.Ftn.Cl.Models.Huawei.EmsVag> VagListFromEmsOntIdList(List<string> emsOntIdList)
  667:         {
  668:             List<Ia.Ftn.Cl.Models.Huawei.EmsVag> list;
  669:  
  670:             using (var db = new Ia.Ftn.Cl.Db())
  671:             {
  672:                 if (emsOntIdList.Count > 0)
  673:                 {
  674:                     list = (from v in db.EmsVags
  675:                             where emsOntIdList.Contains(v.EmsOnt.Id)
  676:                             select v).Include(o => o.EmsOnt).AsNoTracking().ToList();
  677:                 }
  678:                 else list = new List<Ia.Ftn.Cl.Models.Huawei.EmsVag>();
  679:             }
  680:  
  681:             return list.Distinct().ToList();
  682:         }
  683:  
  684:         ////////////////////////////////////////////////////////////////////////////
  685:  
  686:         /// <summary>
  687:         /// 
  688:         /// </summary>
  689:         public static List<Ia.Ftn.Cl.Models.Huawei.EmsVoipPstnUser> EmsVoipPstnUserListFromEmsOntIdListAndServiceList(List<string> emsOntIdList, List<string> serviceList)
  690:         {
  691:             string serviceWithCountryCode;
  692:             List<string> emsVoipPstnUserDnList;
  693:             List<Ia.Ftn.Cl.Models.Huawei.EmsVoipPstnUser> list;
  694:  
  695:             if (emsOntIdList.Count > 0 && serviceList.Count > 0)
  696:             {
  697:                 emsVoipPstnUserDnList = new List<string>();
  698:  
  699:                 foreach (var service in serviceList)
  700:                 {
  701:                     serviceWithCountryCode = Ia.Ftn.Cl.Models.Business.NumberFormatConverter.ServiceWithCountryCode(service);
  702:                     emsVoipPstnUserDnList.Add(serviceWithCountryCode);
  703:                 }
  704:  
  705:                 using (var db = new Ia.Ftn.Cl.Db())
  706:                 {
  707:                     list = (from evpu in db.EmsVoipPstnUsers
  708:                             where evpu.EmsOnt != null && emsOntIdList.Contains(evpu.EmsOnt.Id) && emsVoipPstnUserDnList.Contains(evpu.DN)
  709:                             select evpu).Include(o => o.EmsOnt).AsNoTracking().ToList();
  710:                 }
  711:             }
  712:             else list = new List<Ia.Ftn.Cl.Models.Huawei.EmsVoipPstnUser>();
  713:  
  714:             return list.Distinct().ToList();
  715:         }
  716:  
  717:         ////////////////////////////////////////////////////////////////////////////
  718:  
  719:         /// <summary>
  720:         /// 
  721:         /// </summary>
  722:         public static List<Ia.Ftn.Cl.Models.Huawei.EmsOntSipInfo> EmsOntSipInfoListFromEmsOntIdListAndService(List<string> emsOntIdList, List<string> sipUserNameList)
  723:         {
  724:             List<Ia.Ftn.Cl.Models.Huawei.EmsOntSipInfo> list;
  725:  
  726:             using (var db = new Ia.Ftn.Cl.Db())
  727:             {
  728:                 if (emsOntIdList.Count > 0 && sipUserNameList.Count > 0)
  729:                 {
  730:                     list = (from eosi in db.EmsOntSipInfoes
  731:                             where emsOntIdList.Contains(eosi.EmsOnt.Id) && sipUserNameList.Contains(eosi.SIPUSERNAME)
  732:                             select eosi).Include(o => o.EmsOnt).Include(o => o.EmsOnt.Access).AsNoTracking().ToList();
  733:                 }
  734:                 else list = new List<Ia.Ftn.Cl.Models.Huawei.EmsOntSipInfo>();
  735:             }
  736:  
  737:             return list.Distinct().ToList();
  738:         }
  739:  
  740:         ////////////////////////////////////////////////////////////////////////////
  741:  
  742:         /// <summary>
  743:         /// 
  744:         /// </summary>
  745:         public static List<Ia.Ftn.Cl.Models.ServiceRequestOnt> ServiceRequestOntList(List<string> serviceRequestOntIdList)
  746:         {
  747:             List<Ia.Ftn.Cl.Models.ServiceRequestOnt> list;
  748:  
  749:             using (var db = new Ia.Ftn.Cl.Db())
  750:             {
  751:                 if (serviceRequestOntIdList.Count > 0)
  752:                 {
  753:                     list = (from sro in db.ServiceRequestOnts
  754:                             where serviceRequestOntIdList.Contains(sro.Id)
  755:                             select sro).AsNoTracking().ToList();
  756:                 }
  757:                 else list = new List<Ia.Ftn.Cl.Models.ServiceRequestOnt>();
  758:             }
  759:  
  760:             return list.Distinct().ToList();
  761:         }
  762:  
  763:         ////////////////////////////////////////////////////////////////////////////
  764:  
  765:         /// <summary>
  766:         /// 
  767:         /// </summary>
  768:         public static List<Ia.Ftn.Cl.Models.ServiceRequestOntDetail> ServiceRequestOntDetailList(List<string> serviceRequestOntIdList)
  769:         {
  770:             List<Ia.Ftn.Cl.Models.ServiceRequestOntDetail> list;
  771:  
  772:             using (var db = new Ia.Ftn.Cl.Db())
  773:             {
  774:                 if (serviceRequestOntIdList.Count > 0)
  775:                 {
  776:                     list = (from srod in db.ServiceRequestOntDetails
  777:                             where serviceRequestOntIdList.Contains(srod.ServiceRequestOnt.Id)
  778:                             select srod).AsNoTracking().ToList();
  779:                 }
  780:                 else list = new List<Ia.Ftn.Cl.Models.ServiceRequestOntDetail>();
  781:             }
  782:  
  783:             return list.Distinct().ToList();
  784:         }
  785:  
  786:         ////////////////////////////////////////////////////////////////////////////
  787:  
  788:         /// <summary>
  789:         /// 
  790:         /// </summary>
  791:         public static List<Ia.Ftn.Cl.Models.ServiceRequestOntDetail> ServiceRequestOntDetailFromServieListList(List<string> serviceList)
  792:         {
  793:             List<Ia.Ftn.Cl.Models.ServiceRequestOntDetail> list;
  794:  
  795:             using (var db = new Ia.Ftn.Cl.Db())
  796:             {
  797:                 if (serviceList.Count > 0)
  798:                 {
  799:                     list = (from srod in db.ServiceRequestOntDetails
  800:                             where serviceList.Contains(srod.Service)
  801:                             select srod).AsNoTracking().ToList();
  802:                 }
  803:                 else list = new List<Ia.Ftn.Cl.Models.ServiceRequestOntDetail>();
  804:             }
  805:  
  806:             return list.Distinct().ToList();
  807:         }
  808:  
  809:         ////////////////////////////////////////////////////////////////////////////
  810:  
  811:         /// <summary>
  812:         /// 
  813:         /// </summary>
  814:         public static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont> NddOntList(List<string> nddOntIdList)
  815:         {
  816:             List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont> list;
  817:  
  818:             if (nddOntIdList.Count > 0)
  819:             {
  820:                 list = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList
  821:                         where nddOntIdList.Contains(o.Id)
  822:                         select o).ToList();
  823:             }
  824:             else list = new List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont>();
  825:  
  826:             return list.Distinct().ToList();
  827:         }
  828:  
  829:         ////////////////////////////////////////////////////////////////////////////
  830:  
  831:         /// <summary>
  832:         /// 
  833:         /// </summary>
  834:         public static List<Ia.Ftn.Cl.Models.Access> AccessList(List<string> accessIdList)
  835:         {
  836:             List<Ia.Ftn.Cl.Models.Access> list;
  837:  
  838:             using (var db = new Ia.Ftn.Cl.Db())
  839:             {
  840:                 if (accessIdList.Count > 0)
  841:                 {
  842:                     list = (from a in db.Accesses
  843:                             where accessIdList.Contains(a.Id)
  844:                             select a).AsNoTracking().ToList();
  845:                 }
  846:                 else list = new List<Ia.Ftn.Cl.Models.Access>();
  847:             }
  848:  
  849:             return list.Distinct().ToList();
  850:         }
  851:  
  852:         ////////////////////////////////////////////////////////////////////////////
  853:  
  854:         /// <summary>
  855:         /// 
  856:         /// </summary>
  857:         public static List<Ia.Ftn.Cl.Models.Access> AccessListFromAddress(int kuwaitFtnAreaId, string block, int street, int premisesOld, int premisesNew)
  858:         {
  859:             string streetString, premisesOldString, premisesNewString;
  860:             List<Ia.Ftn.Cl.Models.Access> list;
  861:  
  862:             using (var db = new Ia.Ftn.Cl.Db())
  863:             {
  864:                 streetString = street.ToString();
  865:                 premisesOldString = premisesOld.ToString();
  866:                 premisesNewString = premisesNew.ToString();
  867:  
  868:                 list = (from a in db.Accesses
  869:                         where
  870:                         a.AreaId == kuwaitFtnAreaId
  871:                         &&
  872:                         (
  873:                         a.Block == block && a.Street == streetString && a.PremisesOld == premisesOldString && a.PremisesNew == premisesNewString
  874:                         || a.Block == block && a.Street == streetString && a.PremisesOld == premisesOldString && premisesNew == 0
  875:                         || a.Block == block && a.Street == streetString && a.PremisesNew == premisesNewString && premisesOld == 0
  876:                         || a.Block == block && a.PremisesOld == premisesOldString && a.PremisesNew == premisesNewString && street == 0
  877:                         || a.Block == block && a.PremisesOld == premisesOldString && street == 0 && premisesNew == 0
  878:                         || a.Block == block && a.PremisesNew == premisesNewString && street == 0 && premisesOld == 0
  879:                         || a.Block == block && a.Street == streetString && premisesOld == 0 && premisesNew == 0
  880:                         || a.Block == block && street == 0 && premisesOld == 0 && premisesNew == 0
  881:                         || block == string.Empty && street == 0 && premisesOld == 0 && premisesNew == 0
  882:                         )
  883:                         select a).AsNoTracking().ToList();
  884:             }
  885:  
  886:             return list.Distinct().ToList();
  887:         }
  888:  
  889:         ////////////////////////////////////////////////////////////////////////////
  890:  
  891:         /// <summary>
  892:         /// 
  893:         /// </summary>
  894:         public static List<Ia.Ftn.Cl.Models.Access> AccessListFromAreaAndBlock(int kuwaitFtnAreaId, string block)
  895:         {
  896:             List<Ia.Ftn.Cl.Models.Access> list;
  897:  
  898:             using (var db = new Ia.Ftn.Cl.Db())
  899:             {
  900:                 list = (from a in db.Accesses
  901:                         where a.AreaId == kuwaitFtnAreaId && a.Block == block
  902:                         select a).AsNoTracking().ToList();
  903:             }
  904:  
  905:             return list.Distinct().ToList();
  906:         }
  907:  
  908:         ////////////////////////////////////////////////////////////////////////////
  909:  
  910:         /// <summary>
  911:         /// 
  912:         /// </summary>
  913:         public static List<string> AccessIdListFromPaci(int paci)
  914:         {
  915:             List<string> list;
  916:  
  917:             using (var db = new Ia.Ftn.Cl.Db())
  918:             {
  919:                 if (paci > 0)
  920:                 {
  921:                     list = (from a in db.Accesses
  922:                             where a.Paci == paci.ToString()
  923:                             select a.Id).AsNoTracking().ToList();
  924:                 }
  925:                 else list = new List<string>();
  926:             }
  927:  
  928:             return list.ToList();
  929:         }
  930:  
  931:         ////////////////////////////////////////////////////////////////////////////
  932:  
  933:         /// <summary>
  934:         /// 
  935:         /// </summary>
  936:         public static List<Ia.Ftn.Cl.Models.Ont> OntList(List<string> ontIdList)
  937:         {
  938:             List<Ia.Ftn.Cl.Models.Ont> list;
  939:  
  940:             using (var db = new Ia.Ftn.Cl.Db())
  941:             {
  942:                 if (ontIdList.Count > 0)
  943:                 {
  944:                     list = (from o in db.Onts
  945:                             where ontIdList.Contains(o.Id)
  946:                             select o).AsNoTracking().ToList();
  947:                 }
  948:                 else list = new List<Ia.Ftn.Cl.Models.Ont>();
  949:             }
  950:  
  951:             return list.Distinct().ToList();
  952:         }
  953:  
  954:         ////////////////////////////////////////////////////////////////////////////
  955:  
  956:         /// <summary>
  957:         /// 
  958:         /// </summary>
  959:         public static List<Ia.Ftn.Cl.Models.OntOntPots> OntOntPotsListFromOntOntPotsIdList(List<string> ontOntPotsIdList)
  960:         {
  961:             List<Ia.Ftn.Cl.Models.OntOntPots> list;
  962:  
  963:             using (var db = new Ia.Ftn.Cl.Db())
  964:             {
  965:                 if (ontOntPotsIdList.Count > 0)
  966:                 {
  967:                     list = (from oop in db.OntOntPots
  968:                             where ontOntPotsIdList.Contains(oop.Id)
  969:                             select oop).AsNoTracking().ToList();
  970:                 }
  971:                 else list = new List<Ia.Ftn.Cl.Models.OntOntPots>();
  972:             }
  973:  
  974:             return list.Distinct().ToList();
  975:         }
  976:  
  977:         ////////////////////////////////////////////////////////////////////////////
  978:  
  979:         /// <summary>
  980:         /// 
  981:         /// </summary>
  982:         public static List<Ia.Ftn.Cl.Models.Event> EventList(List<long> eventIdList)
  983:         {
  984:             List<Ia.Ftn.Cl.Models.Event> list;
  985:  
  986:             using (var db = new Ia.Ftn.Cl.Db())
  987:             {
  988:                 if (eventIdList.Count > 0)
  989:                 {
  990:                     list = (from e in db.Events
  991:                             where eventIdList.Contains(e.Id)
  992:                             select e).AsNoTracking().ToList();
  993:                 }
  994:                 else list = new List<Ia.Ftn.Cl.Models.Event>();
  995:             }
  996:  
  997:             return list.Distinct().ToList();
  998:         }
  999:  
 1000:         ////////////////////////////////////////////////////////////////////////////
 1001:  
 1002:         /// <summary>
 1003:         /// 
 1004:         /// </summary>
 1005:         public static List<Ia.Ftn.Cl.Models.Ui.Nokia.SubParty> SubPartyList(List<string> subPartyIdList)
 1006:         {
 1007:             List<Ia.Ftn.Cl.Models.Ui.Nokia.SubParty> list;
 1008:  
 1009:             using (var db = new Ia.Ftn.Cl.Db())
 1010:             {
 1011:                 if (subPartyIdList.Count > 0)
 1012:                 {
 1013:                     list = (from sp in db.SubParties
 1014:                             where subPartyIdList.Contains(sp.Id)
 1015:                             select new Ia.Ftn.Cl.Models.Ui.Nokia.SubParty()
 1016:                             {
 1017:                                 Id = sp.Id,
 1018:                                 PartyId = sp.PartyId,
 1019:                                 PrimaryPUIDCPEProfileNumber = sp.PrimaryPUIDCPEProfileNumber,
 1020:                                 DisplayName = sp.DisplayName,
 1021:                                 Category = sp.Category,
 1022:                                 AssocOtasRealm = sp.AssocOtasRealm,
 1023:                                 ServiceSuspension = sp.ServiceSuspension,
 1024:                                 Created = sp.Created,
 1025:                                 Updated = sp.Updated
 1026:                             }).AsNoTracking().ToList();
 1027:                 }
 1028:                 else list = new List<Ia.Ftn.Cl.Models.Ui.Nokia.SubParty>();
 1029:             }
 1030:  
 1031:             return list.Distinct().ToList();
 1032:         }
 1033:  
 1034:         ////////////////////////////////////////////////////////////////////////////
 1035:  
 1036:         /// <summary>
 1037:         /// 
 1038:         /// </summary>
 1039:         public static List<Ia.Ftn.Cl.Models.Report> ReportList(List<int> reportIdList)
 1040:         {
 1041:             List<Ia.Ftn.Cl.Models.Report> list;
 1042:  
 1043:             using (var db = new Ia.Ftn.Cl.Db())
 1044:             {
 1045:                 if (reportIdList.Count > 0)
 1046:                 {
 1047:                     list = (from r in db.Reports
 1048:                             where reportIdList.Contains(r.Id)
 1049:                             select r).Include(u => u.StaffIdentityUser).Include(u => u.ReportHistories).ThenInclude(u => u.StaffIdentityUser).AsNoTracking().ToList();
 1050:                 }
 1051:                 else list = new List<Ia.Ftn.Cl.Models.Report>();
 1052:             }
 1053:  
 1054:             return list.Distinct().ToList();
 1055:         }
 1056:  
 1057:         ////////////////////////////////////////////////////////////////////////////
 1058:  
 1059:         /// <summary>
 1060:         /// 
 1061:         /// </summary>
 1062:         public static List<Ia.Ftn.Cl.Models.Ui.Huawei.Sbr> SbrList(List<string> sbrImpuList)
 1063:         {
 1064:             List<Ia.Ftn.Cl.Models.Ui.Huawei.Sbr> list;
 1065:  
 1066:             using (var db = new Ia.Ftn.Cl.Db())
 1067:             {
 1068:                 if (sbrImpuList.Count > 0)
 1069:                 {
 1070:                     list = (from h in db.Sbrs
 1071:                             where sbrImpuList.Contains(h.IMPU)
 1072:                             select new Ia.Ftn.Cl.Models.Ui.Huawei.Sbr()
 1073:                             {
 1074:                                 COP = h.COP,
 1075:                                 CSC = h.CSC,
 1076:                                 Id = h.Id,
 1077:                                 IMPU = h.IMPU,
 1078:                                 ITT = h.ITT,
 1079:                                 LP = h.LP,
 1080:                                 NS3PTY = h.NS3PTY,
 1081:                                 NSABRC = h.NSABRC,
 1082:                                 NSCBA = h.NSCBA,
 1083:                                 NSCFU = h.NSCFU,
 1084:                                 NSCLIP = h.NSCLIP,
 1085:                                 NSCW = h.NSCW,
 1086:                                 NSFAX = h.NSFAX,
 1087:                                 NSHOLD = h.NSHOLD,
 1088:                                 NSNPTY = h.NSNPTY,
 1089:                                 NSWAKE_UP = h.NSWAKE_UP,
 1090:                                 Created = h.Created,
 1091:                                 Updated = h.Updated
 1092:                             }).AsNoTracking().ToList();
 1093:                 }
 1094:                 else list = new List<Ia.Ftn.Cl.Models.Ui.Huawei.Sbr>();
 1095:             }
 1096:  
 1097:             return list.Distinct().ToList();
 1098:         }
 1099:  
 1100:         ////////////////////////////////////////////////////////////////////////////
 1101:  
 1102:         /// <summary>
 1103:         /// 
 1104:         /// </summary>
 1105:         public static List<Ia.Ftn.Cl.Models.Huawei.Owsbr> OwsbrList(List<string> owsbrImpuList)
 1106:         {
 1107:             List<Ia.Ftn.Cl.Models.Huawei.Owsbr> list;
 1108:  
 1109:             using (var db = new Ia.Ftn.Cl.Db())
 1110:             {
 1111:                 if (owsbrImpuList.Count > 0)
 1112:                 {
 1113:                     list = (from o in db.Owsbrs
 1114:                             where owsbrImpuList.Contains(o.IMPU)
 1115:                             select o).AsNoTracking().ToList();
 1116:                 }
 1117:                 else list = new List<Ia.Ftn.Cl.Models.Huawei.Owsbr>();
 1118:             }
 1119:  
 1120:             return list.Distinct().ToList();
 1121:         }
 1122:  
 1123:         ////////////////////////////////////////////////////////////////////////////
 1124:  
 1125:         /// <summary>
 1126:         /// 
 1127:         /// </summary>
 1128:         public static List<Ia.Ftn.Cl.Models.Huawei.Seruattr> SeruattrListFromServiceIdList(List<string> serviceIdList)
 1129:         {
 1130:             List<Ia.Ftn.Cl.Models.Huawei.Seruattr> list;
 1131:  
 1132:             using (var db = new Ia.Ftn.Cl.Db())
 1133:             {
 1134:                 if (serviceIdList.Count > 0)
 1135:                 {
 1136:                     list = (from s in db.Seruattrs
 1137:                             where serviceIdList.Contains(s.Id)
 1138:                             select s).AsNoTracking().ToList();
 1139:                 }
 1140:                 else list = new List<Ia.Ftn.Cl.Models.Huawei.Seruattr>();
 1141:             }
 1142:  
 1143:             return list.Distinct().ToList();
 1144:         }
 1145:  
 1146:         ////////////////////////////////////////////////////////////////////////////
 1147:  
 1148:         /// <summary>
 1149:         /// 
 1150:         /// </summary>
 1151:         public static List<Ia.Ftn.Cl.Models.Huawei.Seruattr> SeruattrList(List<string> serviceList)
 1152:         {
 1153:             List<Ia.Ftn.Cl.Models.Huawei.Seruattr> list;
 1154:  
 1155:             using (var db = new Ia.Ftn.Cl.Db())
 1156:             {
 1157:                 if (serviceList.Count > 0)
 1158:                 {
 1159:                     list = (from s in db.Seruattrs
 1160:                             where serviceList.Contains(s.USRNUM)
 1161:                             select s).AsNoTracking().ToList();
 1162:                 }
 1163:                 else list = new List<Ia.Ftn.Cl.Models.Huawei.Seruattr>();
 1164:             }
 1165:  
 1166:             return list.Distinct().ToList();
 1167:         }
 1168:  
 1169:         ////////////////////////////////////////////////////////////////////////////
 1170:  
 1171:         /// <summary>
 1172:         /// 
 1173:         /// </summary>
 1174:         public static List<Ia.Ftn.Cl.Models.Ericsson.AxeSubscriber> AxeSubscriberListFromServiceIdList(List<string> serviceIdList)
 1175:         {
 1176:             List<Ia.Ftn.Cl.Models.Ericsson.AxeSubscriber> list;
 1177:  
 1178:             using (var db = new Ia.Ftn.Cl.Db())
 1179:             {
 1180:                 if (serviceIdList.Count > 0)
 1181:                 {
 1182:                     list = (from s in db.AxeSubscribers
 1183:                             where serviceIdList.Contains(s.Id)
 1184:                             select s).AsNoTracking().ToList();
 1185:                 }
 1186:                 else list = new List<Ia.Ftn.Cl.Models.Ericsson.AxeSubscriber>();
 1187:             }
 1188:  
 1189:             return list.Distinct().ToList();
 1190:         }
 1191:  
 1192:         ////////////////////////////////////////////////////////////////////////////
 1193:  
 1194:         /// <summary>
 1195:         /// 
 1196:         /// </summary>
 1197:         public static List<Ia.Ftn.Cl.Models.Ericsson.AxeSubscriber> AxeSubscriberList(List<int> numberList)
 1198:         {
 1199:             List<Ia.Ftn.Cl.Models.Ericsson.AxeSubscriber> list;
 1200:  
 1201:             using (var db = new Ia.Ftn.Cl.Db())
 1202:             {
 1203:                 if (numberList.Count > 0)
 1204:                 {
 1205:                     list = (from s in db.AxeSubscribers
 1206:                             where numberList.Contains(s.SNB)
 1207:                             select s).AsNoTracking().ToList();
 1208:                 }
 1209:                 else list = new List<Ia.Ftn.Cl.Models.Ericsson.AxeSubscriber>();
 1210:             }
 1211:  
 1212:             return list.Distinct().ToList();
 1213:         }
 1214:  
 1215:         ////////////////////////////////////////////////////////////////////////////
 1216:  
 1217:         /// <summary>
 1218:         /// 
 1219:         /// </summary>
 1220:         public static List<Ia.Ftn.Cl.Models.Siemens.EwsdSubscriber> EwsdSubscriberListFromServiceIdList(List<string> serviceIdList)
 1221:         {
 1222:             List<Ia.Ftn.Cl.Models.Siemens.EwsdSubscriber> list;
 1223:  
 1224:             using (var db = new Ia.Ftn.Cl.Db())
 1225:             {
 1226:                 if (serviceIdList.Count > 0)
 1227:                 {
 1228:                     list = (from s in db.EwsdSubscribers
 1229:                             where serviceIdList.Contains(s.Id)
 1230:                             select s).AsNoTracking().ToList();
 1231:                 }
 1232:                 else list = new List<Ia.Ftn.Cl.Models.Siemens.EwsdSubscriber>();
 1233:             }
 1234:  
 1235:             return list.Distinct().ToList();
 1236:         }
 1237:  
 1238:         ////////////////////////////////////////////////////////////////////////////
 1239:  
 1240:         /// <summary>
 1241:         /// 
 1242:         /// </summary>
 1243:         public static List<Ia.Ftn.Cl.Models.Siemens.EwsdSubscriber> EwsdSubscriberList(List<int> numberList)
 1244:         {
 1245:             List<Ia.Ftn.Cl.Models.Siemens.EwsdSubscriber> list;
 1246:  
 1247:             using (var db = new Ia.Ftn.Cl.Db())
 1248:             {
 1249:                 if (numberList.Count > 0)
 1250:                 {
 1251:                     // this procedure was not used but might be slow. try to read using id
 1252:                     //var id = Ia.Ftn.Cl.Model.Business.Siemens.Subscriber.SubscriberId(23616858);
 1253:                     //var subscriber = (from es in db.EwsdSubscribers where es.Id == id select es.DN).SingleOrDefault();
 1254:  
 1255:                     list = (from s in db.EwsdSubscribers
 1256:                             where numberList.Contains(s.DN)
 1257:                             select s).AsNoTracking().ToList();
 1258:                 }
 1259:                 else list = new List<Ia.Ftn.Cl.Models.Siemens.EwsdSubscriber>();
 1260:             }
 1261:  
 1262:             return list.Distinct().ToList();
 1263:         }
 1264:  
 1265:         ////////////////////////////////////////////////////////////////////////////
 1266:  
 1267:         /// <summary>
 1268:         /// 
 1269:         /// </summary>
 1270:         public static List<Ia.Ftn.Cl.Models.OntServiceVoip> OntServiceVoipList(List<string> ontServiceVoipIdList)
 1271:         {
 1272:             List<Ia.Ftn.Cl.Models.OntServiceVoip> list;
 1273:  
 1274:             using (var db = new Ia.Ftn.Cl.Db())
 1275:             {
 1276:                 if (ontServiceVoipIdList.Count > 0)
 1277:                 {
 1278:                     list = (from ov in db.OntServiceVoips
 1279:                             where ontServiceVoipIdList.Contains(ov.Id)
 1280:                             select ov).AsNoTracking().ToList();
 1281:                 }
 1282:                 else list = new List<Ia.Ftn.Cl.Models.OntServiceVoip>();
 1283:             }
 1284:  
 1285:             return list.Distinct().ToList();
 1286:         }
 1287:  
 1288:         ////////////////////////////////////////////////////////////////////////////
 1289:  
 1290:         /// <summary>
 1291:         /// 
 1292:         /// </summary>
 1293:         public static List<Ia.Ftn.Cl.Models.Ui.Service2> ServiceList(List<string> serviceIdList)
 1294:         {
 1295:             List<Ia.Ftn.Cl.Models.Service2> list0;
 1296:             List<Ia.Ftn.Cl.Models.Ui.Service2> list;
 1297:  
 1298:             using (var db = new Ia.Ftn.Cl.Db())
 1299:             {
 1300:                 if (serviceIdList.Count > 0)
 1301:                 {
 1302:                     list0 = (from s in db.Service2 where serviceIdList.Contains(s.Id) select s).Include(u => u.Access).AsNoTracking().ToList();
 1303:  
 1304:                     list = (from s in list0
 1305:                             select new Ia.Ftn.Cl.Models.Ui.Service2()
 1306:                             {
 1307:                                 Id = s.Id,
 1308:                                 AbbriviatedCalling = s.AbbriviatedCalling,
 1309:                                 AlarmCall = s.AlarmCall,
 1310:                                 CallBarring = s.CallBarring,
 1311:                                 CallerId = s.CallerId,
 1312:                                 CallForwarding = s.CallForwarding,
 1313:                                 CallWaiting = s.CallWaiting,
 1314:                                 ConferenceCall = s.ConferenceCall,
 1315:                                 Created = s.Created,
 1316:                                 InternationalCalling = s.InternationalCalling,
 1317:                                 InternationalCallingUserControlled = s.InternationalCallingUserControlled,
 1318:                                 Port = s.Port,
 1319:                                 Pin = s.Pin,
 1320:                                 Service = s.Service,
 1321:                                 ServiceType = s.ServiceType,
 1322:                                 ServiceSuspension = s.ServiceSuspension,
 1323:                                 ServiceTypeName = s.ServiceType.ToString(),
 1324:                                 Updated = s.Updated,
 1325:                                 AccessId = (s.Access != null) ? s.Access.Id : string.Empty
 1326:                             }).ToList();
 1327:                 }
 1328:                 else list = new List<Ia.Ftn.Cl.Models.Ui.Service2>();
 1329:             }
 1330:  
 1331:             return list.Distinct().ToList();
 1332:         }
 1333:  
 1334:         ////////////////////////////////////////////////////////////////////////////
 1335:  
 1336:         /// <summary>
 1337:         /// 
 1338:         /// </summary>
 1339:         public static List<Ia.Ftn.Cl.Models.Ui.Nokia.Subscriber> SubscriberList(List<string> subscriberIdList)
 1340:         {
 1341:             List<Ia.Ftn.Cl.Models.Ui.Nokia.Subscriber> list;
 1342:  
 1343:             // below: db.Subscribers contains XML fields which can not be evaluated in a Union() function.
 1344:  
 1345:             using (var db = new Ia.Ftn.Cl.Db())
 1346:             {
 1347:                 if (subscriberIdList.Count > 0)
 1348:                 {
 1349:                     list = (from s in db.Subscribers
 1350:                             where subscriberIdList.Contains(s.Id)
 1351:                             select s).AsEnumerable().Select(s => new Ia.Ftn.Cl.Models.Ui.Nokia.Subscriber()
 1352:                             {
 1353:                                 Id = s.Id,
 1354:                                 AlternateOtasRealm = s.AlternateOtasRealm,
 1355:                                 PartyId = s.PartyId,
 1356:                                 AbbriviatedCalling = Ia.Ftn.Cl.Models.Business.Nokia.Subscriber.OneDigitSpeedDialIsAssigned(s._OneDigitSpeedDial),
 1357:                                 AlarmCall = Ia.Ftn.Cl.Models.Business.Nokia.Subscriber.ReminderCallIsAssigned(s._ReminderCall),
 1358:                                 CallerId = Ia.Ftn.Cl.Models.Business.Nokia.Subscriber.CallingLineIdIsAssigned(s._CallingLineId),
 1359:                                 CallForwarding = Ia.Ftn.Cl.Models.Business.Nokia.Subscriber.CallForwardingIsAssigned(s._CallForwardingVari),
 1360:                                 CallWaiting = Ia.Ftn.Cl.Models.Business.Nokia.Subscriber.CallWaitingIsAssigned(s._CallWaiting, false),
 1361:                                 ConferenceCall = Ia.Ftn.Cl.Models.Business.Nokia.Subscriber.ConferenceCallIsAssigned(s._ConferenceCalling),
 1362:                                 InternationalCalling = Ia.Ftn.Cl.Models.Business.Nokia.Subscriber.InternationalCallingIsAssigned(s._CallBarring),
 1363:                                 InternationalCallingUserControlled = Ia.Ftn.Cl.Models.Business.Nokia.Subscriber.InternationalCallingUserControlledIsAssigned(s._OutgoingCallBarring),
 1364:                                 //ServiceSuspention = Ia.Ftn.Cl.Model.Business.Nokia.Subscriber.ServiceSuspentionIsAssigned(s._ServiceSuspention),
 1365:                                 Created = s.Created,
 1366:                                 Updated = s.Updated,
 1367:                             }).ToList();
 1368:                 }
 1369:                 else list = new List<Ia.Ftn.Cl.Models.Ui.Nokia.Subscriber>();
 1370:             }
 1371:  
 1372:             return list.Distinct().ToList();
 1373:         }
 1374:  
 1375:         ////////////////////////////////////////////////////////////////////////////
 1376:  
 1377:         /// <summary>
 1378:         /// 
 1379:         /// </summary>
 1380:         public static List<string> AccessIdList(int oltId, int ponNumber, int ontInternalNumber)
 1381:         {
 1382:             List<string> list;
 1383:  
 1384:             using (var db = new Ia.Ftn.Cl.Db())
 1385:             {
 1386:                 list = (from a in db.Accesses
 1387:                         where a.Olt == oltId && a.Pon == ponNumber && a.Ont == ontInternalNumber
 1388:                         select a.Id).AsNoTracking().ToList();
 1389:             }
 1390:  
 1391:             return list.Distinct().ToList();
 1392:         }
 1393:  
 1394:         ////////////////////////////////////////////////////////////////////////////
 1395:  
 1396:         /// <summary>
 1397:         /// 
 1398:         /// </summary>
 1399:         public static List<string> AccessIdList(int oltId, int ponNumber)
 1400:         {
 1401:             List<string> list;
 1402:  
 1403:             using (var db = new Ia.Ftn.Cl.Db())
 1404:             {
 1405:                 list = (from a in db.Accesses
 1406:                         where a.Olt == oltId && a.Pon == ponNumber
 1407:                         select a.Id).AsNoTracking().ToList();
 1408:             }
 1409:  
 1410:             return list.Distinct().ToList();
 1411:         }
 1412:  
 1413:         ////////////////////////////////////////////////////////////////////////////
 1414:  
 1415:         /// <summary>
 1416:         /// 
 1417:         /// </summary>
 1418:         public static List<int> EmsDevIdListFromEmsBoardIdList(List<string> emsBoardIdList)
 1419:         {
 1420:             List<int> list;
 1421:  
 1422:             using (var db = new Ia.Ftn.Cl.Db())
 1423:             {
 1424:                 if (emsBoardIdList.Count > 0)
 1425:                 {
 1426:                     list = (from ed in db.EmsDevs
 1427:                             join eb in db.EmsBoards on ed.Id equals eb.EmsDev.Id
 1428:                             where emsBoardIdList.Contains(eb.Id)
 1429:                             select ed.Id).ToList();
 1430:                 }
 1431:                 else list = new List<int>();
 1432:             }
 1433:  
 1434:             return list.Distinct().ToList();
 1435:         }
 1436:  
 1437:         ////////////////////////////////////////////////////////////////////////////
 1438:  
 1439:         /// <summary>
 1440:         /// 
 1441:         /// </summary>
 1442:         public static List<int> EmsDevIdListFromAccessIdList(List<string> accessIdList)
 1443:         {
 1444:             List<int> list;
 1445:  
 1446:             using (var db = new Ia.Ftn.Cl.Db())
 1447:             {
 1448:                 if (accessIdList.Count > 0)
 1449:                 {
 1450:                     list = (from ed in db.EmsDevs
 1451:                             where accessIdList.Contains(ed.Access.Id)
 1452:                             select ed.Id).ToList();
 1453:                 }
 1454:                 else list = new List<int>();
 1455:             }
 1456:  
 1457:             return list.Distinct().ToList();
 1458:         }
 1459:  
 1460:         ////////////////////////////////////////////////////////////////////////////
 1461:  
 1462:         /// <summary>
 1463:         /// 
 1464:         /// </summary>
 1465:         public static List<int> EmsDevIdListFromEmsVoipPstnUserIdList(List<string> emsVoipPstnUserIdList)
 1466:         {
 1467:             List<int> list;
 1468:  
 1469:             using (var db = new Ia.Ftn.Cl.Db())
 1470:             {
 1471:                 if (emsVoipPstnUserIdList.Count > 0)
 1472:                 {
 1473:                     list = (from ed in db.EmsDevs
 1474:                             join evpu in db.EmsVoipPstnUsers on ed.DID equals evpu.DID
 1475:                             where emsVoipPstnUserIdList.Contains(evpu.Id)
 1476:                             select ed.Id).ToList();
 1477:                 }
 1478:                 else list = new List<int>();
 1479:             }
 1480:  
 1481:             return list.Distinct().ToList();
 1482:         }
 1483:  
 1484:         ////////////////////////////////////////////////////////////////////////////
 1485:  
 1486:         /// <summary>
 1487:         /// 
 1488:         /// </summary>
 1489:         public static List<string> EmsBoardIdListFromEmsPortIdList(List<string> emsPortIdList)
 1490:         {
 1491:             List<string> list;
 1492:  
 1493:             using (var db = new Ia.Ftn.Cl.Db())
 1494:             {
 1495:                 if (emsPortIdList.Count > 0)
 1496:                 {
 1497:                     list = (from eb in db.EmsBoards
 1498:                             join ep in db.EmsPorts on eb.Id equals ep.EmsBoard.Id
 1499:                             where emsPortIdList.Contains(ep.Id)
 1500:                             select eb.Id).AsNoTracking().ToList();
 1501:                 }
 1502:                 else list = new List<string>();
 1503:             }
 1504:  
 1505:             return list.Distinct().ToList();
 1506:         }
 1507:  
 1508:         ////////////////////////////////////////////////////////////////////////////
 1509:  
 1510:         /// <summary>
 1511:         /// 
 1512:         /// </summary>
 1513:         public static List<string> EmsBoardIdListFromAccessIdList(List<string> accessIdList)
 1514:         {
 1515:             List<string> list;
 1516:  
 1517:             using (var db = new Ia.Ftn.Cl.Db())
 1518:             {
 1519:                 if (accessIdList.Count > 0)
 1520:                 {
 1521:                     list = (from eb in db.EmsBoards
 1522:                             join ed in db.EmsDevs on eb.EmsDev.Id equals ed.Id
 1523:                             where accessIdList.Contains(ed.Access.Id)
 1524:                             select eb.Id).AsNoTracking().ToList();
 1525:                 }
 1526:                 else list = new List<string>();
 1527:             }
 1528:  
 1529:             return list.Distinct().ToList();
 1530:         }
 1531:  
 1532:         ////////////////////////////////////////////////////////////////////////////
 1533:  
 1534:         /// <summary>
 1535:         /// 
 1536:         /// </summary>
 1537:         public static List<string> EmsPortIdListFromEmsOntIdList(List<string> emsOntIdList)
 1538:         {
 1539:             List<string> list;
 1540:  
 1541:             using (var db = new Ia.Ftn.Cl.Db())
 1542:             {
 1543:                 if (emsOntIdList.Count > 0)
 1544:                 {
 1545:                     list = (from ep in db.EmsPorts
 1546:                             join eo in db.EmsOnts on ep.Id equals eo.EmsPort.Id
 1547:                             where emsOntIdList.Contains(eo.Id)
 1548:                             select ep.Id).AsNoTracking().ToList();
 1549:                 }
 1550:                 else list = new List<string>();
 1551:             }
 1552:  
 1553:             return list.Distinct().ToList();
 1554:         }
 1555:  
 1556:         ////////////////////////////////////////////////////////////////////////////
 1557:  
 1558:         /// <summary>
 1559:         /// 
 1560:         /// </summary>
 1561:         public static List<string> EmsPortIdListFromEmsVoipPstnUserIdList(List<string> emsVoipPstnUserIdList)
 1562:         {
 1563:             List<string> list;
 1564:  
 1565:             using (var db = new Ia.Ftn.Cl.Db())
 1566:             {
 1567:                 if (emsVoipPstnUserIdList.Count > 0)
 1568:                 {
 1569:                     // select * from EmsPorts where did  = 7340512 and fn = 0 and sn = 1 and pn = 0
 1570:                     var list0 = (from evpu in db.EmsVoipPstnUsers
 1571:                                  where emsVoipPstnUserIdList.Contains(evpu.Id)
 1572:                                  select evpu).AsNoTracking().ToList();
 1573:  
 1574:                     list = new List<string>();
 1575:  
 1576:                     foreach (var evpu in list0)
 1577:                     {
 1578:                         var l = (from ep in db.EmsPorts
 1579:                                  where ep.DID == evpu.DID && ep.FN == evpu.FN && ep.SN == evpu.SN && ep.PN == evpu.PN
 1580:                                  select ep.Id).AsNoTracking().SingleOrDefault();
 1581:  
 1582:                         if (l != null) list.Add(l);
 1583:                     }
 1584:                 }
 1585:                 else list = new List<string>();
 1586:             }
 1587:  
 1588:             return list.Distinct().ToList();
 1589:         }
 1590:  
 1591:         ////////////////////////////////////////////////////////////////////////////
 1592:  
 1593:         /// <summary>
 1594:         /// 
 1595:         /// </summary>
 1596:         public static List<string> EmsOntIdListFromNddOntIdList(List<string> nddOntIdList)
 1597:         {
 1598:             List<string> list;
 1599:  
 1600:             using (var db = new Ia.Ftn.Cl.Db())
 1601:             {
 1602:                 if (nddOntIdList.Count > 0)
 1603:                 {
 1604:                     list = (from eo in db.EmsOnts
 1605:                             where nddOntIdList.Contains(eo.Id)
 1606:                             select eo.Id).AsNoTracking().ToList();
 1607:                 }
 1608:                 else list = new List<string>();
 1609:             }
 1610:  
 1611:             return list.Distinct().ToList();
 1612:         }
 1613:  
 1614:         ////////////////////////////////////////////////////////////////////////////
 1615:  
 1616:         /// <summary>
 1617:         /// 
 1618:         /// </summary>
 1619:         public static List<string> EmsOntIpListFromNddOntIdList(List<string> nddOntIdList)
 1620:         {
 1621:             List<string> list;
 1622:  
 1623:             using (var db = new Ia.Ftn.Cl.Db())
 1624:             {
 1625:                 if (nddOntIdList.Count > 0)
 1626:                 {
 1627:                     list = (from eo in db.EmsOnts
 1628:                             where nddOntIdList.Contains(eo.Id)
 1629:                             select eo.IP).AsNoTracking().ToList();
 1630:                 }
 1631:                 else list = new List<string>();
 1632:             }
 1633:  
 1634:             return list.Distinct().ToList();
 1635:         }
 1636:  
 1637:         ////////////////////////////////////////////////////////////////////////////
 1638:  
 1639:         /// <summary>
 1640:         /// 
 1641:         /// </summary>
 1642:         public static List<string> SbrImpuListFromImpuSipDomainList(List<string> impuSipDomainList)
 1643:         {
 1644:             List<string> list;
 1645:  
 1646:             using (var db = new Ia.Ftn.Cl.Db())
 1647:             {
 1648:                 if (impuSipDomainList.Count > 0)
 1649:                 {
 1650:                     list = (from s in db.Sbrs
 1651:                             where impuSipDomainList.Contains(s.IMPU)
 1652:                             select s.IMPU).AsNoTracking().ToList();
 1653:                 }
 1654:                 else list = new List<string>();
 1655:             }
 1656:  
 1657:             return list.Distinct().ToList();
 1658:         }
 1659:  
 1660:         ////////////////////////////////////////////////////////////////////////////
 1661:  
 1662:         /// <summary>
 1663:         /// 
 1664:         /// </summary>
 1665:         public static List<string> OwSbrImpuListFromImpuSipDomainList(List<string> impuSipDomainList)
 1666:         {
 1667:             List<string> list;
 1668:  
 1669:             using (var db = new Ia.Ftn.Cl.Db())
 1670:             {
 1671:                 if (impuSipDomainList.Count > 0)
 1672:                 {
 1673:                     list = (from o in db.Owsbrs
 1674:                             where impuSipDomainList.Contains(o.IMPU)
 1675:                             select o.IMPU).AsNoTracking().ToList();
 1676:                 }
 1677:                 else list = new List<string>();
 1678:             }
 1679:  
 1680:             return list.Distinct().ToList();
 1681:         }
 1682:  
 1683:         ////////////////////////////////////////////////////////////////////////////
 1684:  
 1685:         /// <summary>
 1686:         /// 
 1687:         /// </summary>
 1688:         public static List<string> ServiceRequestServiceIdListFromAccessIdList(List<string> accessIdList)
 1689:         {
 1690:             List<string> list;
 1691:  
 1692:             using (var db = new Ia.Ftn.Cl.Db())
 1693:             {
 1694:                 if (accessIdList.Count > 0)
 1695:                 {
 1696:                     list = (from srs in db.ServiceRequestServices
 1697:                             where accessIdList.Contains(srs.Access.Id)
 1698:                             select srs.Id).AsNoTracking().ToList();
 1699:                 }
 1700:                 else list = new List<string>();
 1701:             }
 1702:  
 1703:             return list.Distinct().ToList();
 1704:         }
 1705:  
 1706:         ////////////////////////////////////////////////////////////////////////////
 1707:  
 1708:         /// <summary>
 1709:         /// 
 1710:         /// </summary>
 1711:         public static List<string> ServiceRequestServiceIdListFromServiceIdList(List<string> serviceIdList)
 1712:         {
 1713:             List<string> list;
 1714:  
 1715:             using (var db = new Ia.Ftn.Cl.Db())
 1716:             {
 1717:                 if (serviceIdList.Count > 0)
 1718:                 {
 1719:                     list = (from srs in db.ServiceRequestServices
 1720:                             where serviceIdList.Contains(srs.Id)
 1721:                             select srs.Id).AsNoTracking().ToList();
 1722:                 }
 1723:                 else list = new List<string>();
 1724:             }
 1725:  
 1726:             return list.Distinct().ToList();
 1727:         }
 1728:  
 1729:         ////////////////////////////////////////////////////////////////////////////
 1730:  
 1731:         /// <summary>
 1732:         /// 
 1733:         /// </summary>
 1734:         public static List<string> ServiceRequestServiceIdListFromServiceList(List<string> serviceList)
 1735:         {
 1736:             List<string> list;
 1737:  
 1738:             using (var db = new Ia.Ftn.Cl.Db())
 1739:             {
 1740:                 if (serviceList.Count > 0)
 1741:                 {
 1742:                     list = (from srs in db.ServiceRequestServices
 1743:                             where serviceList.Contains(srs.Service)
 1744:                             select srs.Id).AsNoTracking().ToList();
 1745:                 }
 1746:                 else list = new List<string>();
 1747:             }
 1748:  
 1749:             return list.Distinct().ToList();
 1750:         }
 1751:  
 1752:         ////////////////////////////////////////////////////////////////////////////
 1753:  
 1754:         /// <summary>
 1755:         /// 
 1756:         /// </summary>
 1757:         public static List<string> Service2IdListFromServiceIdList(List<string> serviceIdList)
 1758:         {
 1759:             List<string> list;
 1760:  
 1761:             if (serviceIdList.Count > 0)
 1762:             {
 1763:                 using (var db = new Ia.Ftn.Cl.Db())
 1764:                 {
 1765:                     list = (from s in db.Service2
 1766:                             where serviceIdList.Contains(s.Id)
 1767:                             select s.Id).AsNoTracking().ToList();
 1768:                 }
 1769:             }
 1770:             else list = new List<string>();
 1771:  
 1772:             return list.Distinct().ToList();
 1773:         }
 1774:  
 1775:         ////////////////////////////////////////////////////////////////////////////
 1776:  
 1777:         /// <summary>
 1778:         /// 
 1779:         /// </summary>
 1780:         public static List<string> ServiceIdListFromServiceList(List<string> serviceList)
 1781:         {
 1782:             List<string> list;
 1783:  
 1784:             using (var db = new Ia.Ftn.Cl.Db())
 1785:             {
 1786:                 if (serviceList.Count > 0)
 1787:                 {
 1788:                     list = (from s in db.Service2
 1789:                             where serviceList.Contains(s.Service)
 1790:                             select s.Id).AsNoTracking().ToList();
 1791:                 }
 1792:                 else list = new List<string>();
 1793:             }
 1794:  
 1795:             return list.Distinct().ToList();
 1796:         }
 1797:  
 1798:         ////////////////////////////////////////////////////////////////////////////
 1799:  
 1800:         /// <summary>
 1801:         /// 
 1802:         /// </summary>
 1803:         public static List<int> ReportIdListFromServiceList(List<string> serviceList)
 1804:         {
 1805:             List<int> list;
 1806:  
 1807:             //reportIdList = (from r in db.Reports where r.Service == accessName && r.ServiceType == 2 select r.Id).Distinct().ToList();
 1808:             // <type id="2" name="Ont Name" arabicName=""/>
 1809:  
 1810:             using (var db = new Ia.Ftn.Cl.Db())
 1811:             {
 1812:                 if (serviceList.Count > 0)
 1813:                 {
 1814:                     list = (from r in db.Reports
 1815:                             where serviceList.Contains(r.Service)
 1816:                             select r.Id).ToList();
 1817:                 }
 1818:                 else list = new List<int>();
 1819:             }
 1820:  
 1821:             return list.Distinct().ToList();
 1822:         }
 1823:  
 1824:         ////////////////////////////////////////////////////////////////////////////
 1825:  
 1826:         /// <summary>
 1827:         /// 
 1828:         /// </summary>
 1829:         public static List<int> ReportIdListFromAccessIdList(List<string> accessIdList)
 1830:         {
 1831:             string accessName;
 1832:             List<string> accessNameList;
 1833:             List<int> list;
 1834:  
 1835:             //reportIdList = (from r in db.Reports where r.Service == accessName && r.ServiceType == 2 select r.Id).Distinct().ToList();
 1836:             // <type id="2" name="Ont Name" arabicName=""/>
 1837:  
 1838:             if (accessIdList.Count > 0)
 1839:             {
 1840:                 var ontAccessIdToOntAccessNameDictionary = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntAccessIdToOntAccessNameDictionary;
 1841:  
 1842:                 accessNameList = new List<string>();
 1843:  
 1844:                 foreach (var id in accessIdList)
 1845:                 {
 1846:                     if (ontAccessIdToOntAccessNameDictionary.ContainsKey(id))
 1847:                     {
 1848:                         accessName = ontAccessIdToOntAccessNameDictionary[id];
 1849:  
 1850:                         accessNameList.Add(accessName);
 1851:                     }
 1852:                 }
 1853:  
 1854:                 list = ReportIdListFromServiceList(accessNameList); // Its OK
 1855:             }
 1856:             else list = new List<int>();
 1857:  
 1858:             return list.Distinct().ToList();
 1859:         }
 1860:  
 1861:         ////////////////////////////////////////////////////////////////////////////
 1862:  
 1863:         /// <summary>
 1864:         /// 
 1865:         /// </summary>
 1866:         public static List<string> ServiceIdListFromAccessIdList(List<string> accessIdList)
 1867:         {
 1868:             List<string> list;
 1869:  
 1870:             using (var db = new Ia.Ftn.Cl.Db())
 1871:             {
 1872:                 if (accessIdList.Count > 0)
 1873:                 {
 1874:                     list = (from s in db.Service2
 1875:                             where s.Access != null && accessIdList.Contains(s.Access.Id)
 1876:                             select s.Id).AsNoTracking().ToList();
 1877:                 }
 1878:                 else list = new List<string>();
 1879:             }
 1880:  
 1881:             return list.Distinct().ToList();
 1882:         }
 1883:  
 1884:         ////////////////////////////////////////////////////////////////////////////
 1885:  
 1886:         /// <summary>
 1887:         /// 
 1888:         /// </summary>
 1889:         public static List<string> AccessIdListFromServiceIdList(List<string> serviceIdList)
 1890:         {
 1891:             List<string> list;
 1892:  
 1893:             using (var db = new Ia.Ftn.Cl.Db())
 1894:             {
 1895:                 if (serviceIdList.Count > 0)
 1896:                 {
 1897:                     list = (from s in db.Service2
 1898:                             where serviceIdList.Contains(s.Id) && s.Access != null
 1899:                             select s.Access.Id).AsNoTracking().ToList();
 1900:                 }
 1901:                 else list = new List<string>();
 1902:             }
 1903:  
 1904:             return list.Distinct().ToList();
 1905:         }
 1906:  
 1907:         ////////////////////////////////////////////////////////////////////////////
 1908:  
 1909:         /// <summary>
 1910:         /// 
 1911:         /// </summary>
 1912:         public static List<string> AccessIdListFromServiceList(List<string> serviceList)
 1913:         {
 1914:             List<string> list;
 1915:  
 1916:             using (var db = new Ia.Ftn.Cl.Db())
 1917:             {
 1918:                 if (serviceList.Count > 0)
 1919:                 {
 1920:                     list = (from s in db.Service2
 1921:                             where serviceList.Contains(s.Service) && s.Access != null /*&& where s.ServiceType == Ia.Ftn.Cl.Model.Business.Service.ServiceType.ImsService*/
 1922:                             select s.Access.Id).AsNoTracking().ToList();
 1923:                 }
 1924:                 else list = new List<string>();
 1925:             }
 1926:  
 1927:             return list.Distinct().ToList();
 1928:         }
 1929:  
 1930:         ////////////////////////////////////////////////////////////////////////////
 1931:  
 1932:         /// <summary>
 1933:         /// 
 1934:         /// </summary>
 1935:         public static List<string> AccessIdListFromServiceRequestServiceIdList(List<string> serviceRequestServiceIdList)
 1936:         {
 1937:             List<string> list;
 1938:  
 1939:             using (var db = new Ia.Ftn.Cl.Db())
 1940:             {
 1941:                 if (serviceRequestServiceIdList.Count > 0)
 1942:                 {
 1943:                     list = (from srs in db.ServiceRequestServices
 1944:                             where serviceRequestServiceIdList.Contains(srs.Id) && srs.Access != null
 1945:                             select srs.Access.Id).AsNoTracking().ToList();
 1946:                 }
 1947:                 else list = new List<string>();
 1948:             }
 1949:  
 1950:             return list.Distinct().ToList();
 1951:         }
 1952:  
 1953:         ////////////////////////////////////////////////////////////////////////////
 1954:  
 1955:         /// <summary>
 1956:         /// 
 1957:         /// </summary>
 1958:         public static List<string> ServiceRequestOntIdListFromAccessIdList(List<string> accessIdList)
 1959:         {
 1960:             List<string> list;
 1961:  
 1962:             using (var db = new Ia.Ftn.Cl.Db())
 1963:             {
 1964:                 if (accessIdList.Count > 0)
 1965:                 {
 1966:                     list = (from sro in db.ServiceRequestOnts
 1967:                             where accessIdList.Contains(sro.Access.Id)
 1968:                             select sro.Id).AsNoTracking().ToList();
 1969:                 }
 1970:                 else list = new List<string>();
 1971:             }
 1972:  
 1973:             return list.Distinct().ToList();
 1974:         }
 1975:  
 1976:         ////////////////////////////////////////////////////////////////////////////
 1977:  
 1978:         /// <summary>
 1979:         /// 
 1980:         /// </summary>
 1981:         public static List<int> ServiceRequestIdListFromServiceList(List<string> serviceList)
 1982:         {
 1983:             List<int> list, numberList;
 1984:  
 1985:             if (serviceList.Count > 0)
 1986:             {
 1987:                 numberList = serviceList.Select(int.Parse).ToList();
 1988:  
 1989:                 using (var db = new Ia.Ftn.Cl.Db())
 1990:                 {
 1991:                     list = (from sr in db.ServiceRequests
 1992:                             where numberList.Contains(sr.Number)
 1993:                             select sr.Id).ToList();
 1994:                 }
 1995:             }
 1996:             else list = new List<int>();
 1997:  
 1998:             return list.Distinct().ToList();
 1999:         }
 2000:  
 2001:         ////////////////////////////////////////////////////////////////////////////
 2002:  
 2003:         /// <summary>
 2004:         /// 
 2005:         /// </summary>
 2006:         public static List<int> ServiceRequestIdListFromServiceAndRelatedChangedAndChangedToServiceList(List<string> serviceList)
 2007:         {
 2008:             List<int> list;//, numberList, numberAndChangedAndChangedToList;
 2009:  
 2010:             if (serviceList.Count > 0)
 2011:             {
 2012:                 var list0 = Ia.Ftn.Cl.Models.Data.ServiceRequest.ServiceListAndRelatedChangedAndChangedToServiceListByServiceList(serviceList);
 2013:                 serviceList = serviceList.Union(list0).Distinct().ToList();
 2014:  
 2015:                 list = Ia.Ftn.Cl.Models.Data.Maintenance.Find.ServiceRequestIdListFromServiceList(serviceList);
 2016:             }
 2017:             else list = new List<int>();
 2018:  
 2019:             return list.Distinct().ToList();
 2020:         }
 2021:  
 2022:         ////////////////////////////////////////////////////////////////////////////
 2023:  
 2024:         /// <summary>
 2025:         /// 
 2026:         /// </summary>
 2027:         public static List<int> ServiceRequestIdListFromServiceRequestServiceIdList(List<string> serviceRequestServiceIdList)
 2028:         {
 2029:             List<int> list;
 2030:  
 2031:             if (serviceRequestServiceIdList.Count > 0)
 2032:             {
 2033:                 using (var db = new Ia.Ftn.Cl.Db())
 2034:                 {
 2035:                     list = (from sr in db.ServiceRequests
 2036:                             where serviceRequestServiceIdList.Contains(sr.ServiceRequestService.Id)
 2037:                             select sr.Id).ToList();
 2038:                 }
 2039:             }
 2040:             else list = new List<int>();
 2041:  
 2042:             return list.Distinct().ToList();
 2043:         }
 2044:  
 2045:         ////////////////////////////////////////////////////////////////////////////
 2046:  
 2047:         /// <summary>
 2048:         /// 
 2049:         /// </summary>
 2050:         public static List<string> ServiceRequestAdministrativeIssueIdListFromServiceIdList(List<string> serviceIdList)
 2051:         {
 2052:             List<string> list;
 2053:  
 2054:             if (serviceIdList.Count > 0)
 2055:             {
 2056:                 using (var db = new Ia.Ftn.Cl.Db())
 2057:                 {
 2058:                     list = (from srai in db.ServiceRequestAdministrativeIssues
 2059:                             where serviceIdList.Contains(srai.Id)
 2060:                             select srai.Id).AsNoTracking().ToList();
 2061:                 }
 2062:             }
 2063:             else list = new List<string>();
 2064:  
 2065:             return list.Distinct().ToList();
 2066:         }
 2067:  
 2068:         ////////////////////////////////////////////////////////////////////////////
 2069:  
 2070:         /// <summary>
 2071:         /// 
 2072:         /// </summary>
 2073:         public static List<string> ServiceRequestHistoryIdListFromServiceAndRelatedChangedAndChangedToServiceList(List<string> serviceList)
 2074:         {
 2075:             List<int> numberList;
 2076:             List<string> list;
 2077:  
 2078:             if (serviceList.Count > 0)
 2079:             {
 2080:                 var list0 = Ia.Ftn.Cl.Models.Data.ServiceRequest.ServiceListAndRelatedChangedAndChangedToServiceListByServiceList(serviceList);
 2081:                 serviceList = serviceList.Union(list0).Distinct().ToList();
 2082:  
 2083:                 numberList = new List<int>();
 2084:  
 2085:                 foreach (string s in serviceList)
 2086:                 {
 2087:                     if (int.TryParse(s, out int i)) numberList.Add(i);
 2088:                 }
 2089:  
 2090:                 using (var db = new Ia.Ftn.Cl.Db())
 2091:                 {
 2092:                     list = (from srh in db.ServiceRequestHistories
 2093:                             where numberList.Contains(srh.Number)
 2094:                             select srh.Id).AsNoTracking().ToList();
 2095:                 }
 2096:             }
 2097:             else list = new List<string>();
 2098:  
 2099:             return list.Distinct().ToList();
 2100:         }
 2101:  
 2102:         ////////////////////////////////////////////////////////////////////////////
 2103:  
 2104:         /// <summary>
 2105:         /// 
 2106:         /// </summary>
 2107:         public static List<int> ServiceRequestTypeIdListFromServiceRequestIdList(List<int> serviceRequestIdList)
 2108:         {
 2109:             List<int> list;
 2110:  
 2111:             using (var db = new Ia.Ftn.Cl.Db())
 2112:             {
 2113:                 if (serviceRequestIdList.Count > 0)
 2114:                 {
 2115:                     list = (from srt in db.ServiceRequestTypes
 2116:                             where serviceRequestIdList.Contains(srt.ServiceRequest.Id)
 2117:                             select srt.Id).ToList();
 2118:                 }
 2119:                 else list = new List<int>();
 2120:             }
 2121:  
 2122:             return list.Distinct().ToList();
 2123:         }
 2124:  
 2125:         ////////////////////////////////////////////////////////////////////////////
 2126:  
 2127:         /// <summary>
 2128:         /// 
 2129:         /// </summary>
 2130:         public static List<string> NddOntIdList(int oltId, int ponNumber, int ontInternalNumber)
 2131:         {
 2132:             List<string> list;
 2133:  
 2134:             list = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList
 2135:                     where o.Pon.PonGroup.Olt.Id == oltId && o.Pon.Number == ponNumber && o.Number == ontInternalNumber
 2136:                     select o.Id).ToList();
 2137:  
 2138:             return list.Distinct().ToList();
 2139:         }
 2140:  
 2141:         ////////////////////////////////////////////////////////////////////////////
 2142:  
 2143:         /// <summary>
 2144:         /// 
 2145:         /// </summary>
 2146:         public static List<string> NddOntIdList(int oltId, int ponNumber)
 2147:         {
 2148:             List<string> list;
 2149:  
 2150:             list = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList
 2151:                     where o.Pon.PonGroup.Olt.Id == oltId && o.Pon.Number == ponNumber
 2152:                     select o.Id).ToList();
 2153:  
 2154:             return list.Distinct().ToList();
 2155:         }
 2156:  
 2157:         ////////////////////////////////////////////////////////////////////////////
 2158:  
 2159:         /// <summary>
 2160:         /// 
 2161:         /// </summary>
 2162:         public static List<string> NddOntIdListFromAccessIdList(List<string> accessIdList)
 2163:         {
 2164:             List<string> list;
 2165:  
 2166:             if (accessIdList.Count > 0)
 2167:             {
 2168:                 // this is not slow for general returns
 2169:                 list = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList
 2170:                         where accessIdList.Contains(o.Access.Id)
 2171:                         select o.Id).ToList();
 2172:             }
 2173:             else list = new List<string>();
 2174:  
 2175:             return list.Distinct().ToList();
 2176:         }
 2177:  
 2178:         ////////////////////////////////////////////////////////////////////////////
 2179:  
 2180:         /// <summary>
 2181:         /// 
 2182:         /// </summary>
 2183:         public static List<string> NddOntIdListFromIpList(List<string> ipList)
 2184:         {
 2185:             List<string> list;
 2186:  
 2187:             if (ipList.Count > 0)
 2188:             {
 2189:                 // this is not slow for general returns
 2190:                 list = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList
 2191:                         where ipList.Contains(o.Ip)
 2192:                         select o.Id).ToList();
 2193:             }
 2194:             else list = new List<string>();
 2195:  
 2196:             return list.Distinct().ToList();
 2197:         }
 2198:  
 2199:         ////////////////////////////////////////////////////////////////////////////   
 2200:  
 2201:         /// <summary>
 2202:         /// 
 2203:         /// </summary>
 2204:         public static List<string> NddOntIdListFromEmsOntSipInfoListAndEmsVoipPstnUserListByServiceList(List<string> serviceList)
 2205:         {
 2206:             string sipUserName, serviceWithCountryCode;
 2207:             List<string> list, emsOntSipInfoEmsOntIdList, emsVoipPstnUserEmsOntIdList;
 2208:             List<string> emsOntSipInfoSipUserNameList, emsVoipPstnUserDnList;
 2209:  
 2210:             if (serviceList.Count > 0)
 2211:             {
 2212:                 emsOntSipInfoSipUserNameList = new List<string>();
 2213:                 emsVoipPstnUserDnList = new List<string>();
 2214:  
 2215:                 foreach (var service in serviceList)
 2216:                 {
 2217:                     sipUserName = Ia.Ftn.Cl.Models.Business.NumberFormatConverter.SipUserName(service);
 2218:                     emsOntSipInfoSipUserNameList.Add(sipUserName);
 2219:  
 2220:                     serviceWithCountryCode = Ia.Ftn.Cl.Models.Business.NumberFormatConverter.ServiceWithCountryCode(service);
 2221:                     emsVoipPstnUserDnList.Add(serviceWithCountryCode);
 2222:                 }
 2223:  
 2224:                 using (var db = new Ia.Ftn.Cl.Db())
 2225:                 {
 2226:                     emsOntSipInfoEmsOntIdList = (from eosi in db.EmsOntSipInfoes
 2227:                                                  join eo in db.EmsOnts on eosi.EmsOnt.Id equals eo.Id
 2228:                                                  where emsOntSipInfoSipUserNameList.Contains(eosi.SIPUSERNAME)
 2229:                                                  select eo.Id).AsNoTracking().ToList();
 2230:  
 2231:                     emsOntSipInfoEmsOntIdList = emsOntSipInfoEmsOntIdList.Distinct().ToList();
 2232:  
 2233:                     emsVoipPstnUserEmsOntIdList = (from evpu in db.EmsVoipPstnUsers
 2234:                                                    join eo in db.EmsOnts on evpu.EmsOnt.Id equals eo.Id
 2235:                                                    where evpu.EmsOnt != null && emsVoipPstnUserDnList.Contains(evpu.DN)
 2236:                                                    select eo.Id).AsNoTracking().ToList();
 2237:  
 2238:                     emsVoipPstnUserEmsOntIdList = emsVoipPstnUserEmsOntIdList.Distinct().ToList();
 2239:  
 2240:                     list = emsOntSipInfoEmsOntIdList.Concat(emsVoipPstnUserEmsOntIdList).ToList();
 2241:                     list = list.Distinct().ToList();
 2242:                 }
 2243:             }
 2244:             else list = new List<string>();
 2245:  
 2246:             return list.ToList();
 2247:         }
 2248:  
 2249:         ////////////////////////////////////////////////////////////////////////////
 2250:  
 2251:         /// <summary>
 2252:         /// 
 2253:         /// </summary>
 2254:         public static List<string> OntServiceVoipIpList(List<string> ontServiceVoipIdList)
 2255:         {
 2256:             List<string> list;
 2257:  
 2258:             using (var db = new Ia.Ftn.Cl.Db())
 2259:             {
 2260:                 if (ontServiceVoipIdList.Count > 0)
 2261:                 {
 2262:                     list = (from osv in db.OntServiceVoips
 2263:                             where ontServiceVoipIdList.Contains(osv.Id)
 2264:                             select osv.Ip).AsNoTracking().ToList();
 2265:                 }
 2266:                 else list = new List<string>();
 2267:             }
 2268:  
 2269:             return list.Distinct().ToList();
 2270:         }
 2271:  
 2272:         ////////////////////////////////////////////////////////////////////////////
 2273:  
 2274:         /// <summary>
 2275:         /// 
 2276:         /// </summary>
 2277:         public static List<string> NddPonIpList(int oltId, int ponNumber)
 2278:         {
 2279:             var list = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList
 2280:                         where o.Pon.PonGroup.Olt.Id == oltId && o.Pon.Number == ponNumber
 2281:                         select o.Ip);//.ToList();
 2282:  
 2283:             return list.Distinct().ToList();
 2284:         }
 2285:  
 2286:         ////////////////////////////////////////////////////////////////////////////
 2287:  
 2288:         /// <summary>
 2289:         /// 
 2290:         /// </summary>
 2291:         public static List<string> OntIdListFromNddOntIdList(List<string> nddOntIdList)
 2292:         {
 2293:             List<string> list;
 2294:  
 2295:             using (var db = new Ia.Ftn.Cl.Db())
 2296:             {
 2297:                 if (nddOntIdList.Count > 0)
 2298:                 {
 2299:                     list = (from o in db.Onts
 2300:                             where nddOntIdList.Contains(o.Id)
 2301:                             select o.Id).AsNoTracking().ToList();
 2302:                 }
 2303:                 else list = new List<string>();
 2304:             }
 2305:  
 2306:             return list.Distinct().ToList();
 2307:         }
 2308:  
 2309:         ////////////////////////////////////////////////////////////////////////////
 2310:  
 2311:         /// <summary>
 2312:         /// 
 2313:         /// </summary>
 2314:         public static List<string> OntOntPotsIdListFromOntIdList(List<string> ontIdList)
 2315:         {
 2316:             List<string> list;
 2317:  
 2318:             using (var db = new Ia.Ftn.Cl.Db())
 2319:             {
 2320:                 if (ontIdList.Count > 0)
 2321:                 {
 2322:                     list = (from oop in db.OntOntPots
 2323:                             where ontIdList.Contains(oop.Ont.Id)
 2324:                             select oop.Id).AsNoTracking().ToList();
 2325:                 }
 2326:                 else list = new List<string>();
 2327:             }
 2328:  
 2329:             return list.Distinct().ToList();
 2330:         }
 2331:  
 2332:         ////////////////////////////////////////////////////////////////////////////
 2333:  
 2334:         /// <summary>
 2335:         /// 
 2336:         /// </summary>
 2337:         public static List<string> OntServiceVoipsIdListFromOntIdList(List<string> ontIdList)
 2338:         {
 2339:             List<string> list;
 2340:  
 2341:             using (var db = new Ia.Ftn.Cl.Db())
 2342:             {
 2343:                 if (ontIdList.Count > 0)
 2344:                 {
 2345:                     list = (from ov in db.OntServiceVoips
 2346:                             where ontIdList.Contains(ov.Ont.Id)
 2347:                             select ov.Id).AsNoTracking().ToList();
 2348:                 }
 2349:                 else list = new List<string>();
 2350:             }
 2351:  
 2352:             return list.Distinct().ToList();
 2353:         }
 2354:  
 2355:         ////////////////////////////////////////////////////////////////////////////
 2356:  
 2357:         /// <summary>
 2358:         /// 
 2359:         /// </summary>
 2360:         public static List<string> AccessIdListFromOntSerial(string serial)
 2361:         {
 2362:             List<string> list;
 2363:  
 2364:             using (var db = new Ia.Ftn.Cl.Db())
 2365:             {
 2366:                 if (!string.IsNullOrEmpty(serial))
 2367:                 {
 2368:                     list = (from o in db.Onts
 2369:                             where o.Serial == serial
 2370:                             select o.Access.Id).AsNoTracking().ToList();
 2371:                 }
 2372:                 else list = new List<string>();
 2373:             }
 2374:  
 2375:             return list.Distinct().ToList();
 2376:         }
 2377:  
 2378:         ////////////////////////////////////////////////////////////////////////////
 2379:  
 2380:         /// <summary>
 2381:         /// 
 2382:         /// </summary>
 2383:         public static List<string> AccessIdListFromEmsOntSerial(string serial)
 2384:         {
 2385:             List<string> list;
 2386:  
 2387:             using (var db = new Ia.Ftn.Cl.Db())
 2388:             {
 2389:                 if (!string.IsNullOrEmpty(serial))
 2390:                 {
 2391:                     list = (from eo in db.EmsOnts
 2392:                             where eo.SERIALNUM == serial
 2393:                             select eo.Access.Id).AsNoTracking().ToList();
 2394:                 }
 2395:                 else list = new List<string>();
 2396:             }
 2397:  
 2398:             return list.Distinct().ToList();
 2399:         }
 2400:  
 2401:         ////////////////////////////////////////////////////////////////////////////
 2402:  
 2403:         /// <summary>
 2404:         /// 
 2405:         /// </summary>
 2406:         public static List<string> AccessIdListFromEmsOntIp(string ip)
 2407:         {
 2408:             List<string> list;
 2409:  
 2410:             using (var db = new Ia.Ftn.Cl.Db())
 2411:             {
 2412:                 if (!string.IsNullOrEmpty(ip))
 2413:                 {
 2414:                     list = (from eo in db.EmsOnts
 2415:                             where eo.IP == ip
 2416:                             select eo.Access.Id).AsNoTracking().ToList();
 2417:                 }
 2418:                 else list = new List<string>();
 2419:             }
 2420:  
 2421:             return list.Distinct().ToList();
 2422:         }
 2423:  
 2424:         ////////////////////////////////////////////////////////////////////////////
 2425:  
 2426:         /// <summary>
 2427:         /// 
 2428:         /// </summary>
 2429:         public static List<string> OntServiceVoipsIdListFromIpList(List<string> ipList)
 2430:         {
 2431:             List<string> list;
 2432:  
 2433:             using (var db = new Ia.Ftn.Cl.Db())
 2434:             {
 2435:                 if (ipList.Count > 0)
 2436:                 {
 2437:                     list = (from ov in db.OntServiceVoips
 2438:                             where ipList.Contains(ov.Ip)
 2439:                             select ov.Id).AsNoTracking().ToList();
 2440:                 }
 2441:                 else list = new List<string>();
 2442:             }
 2443:  
 2444:             return list.Distinct().ToList();
 2445:         }
 2446:  
 2447:         ////////////////////////////////////////////////////////////////////////////
 2448:  
 2449:         /// <summary>
 2450:         /// 
 2451:         /// </summary>
 2452:         public static List<long> EventIdListFromOntIdList(List<string> ontIdList)
 2453:         {
 2454:             List<long> list;
 2455:  
 2456:             using (var db = new Ia.Ftn.Cl.Db())
 2457:             {
 2458:                 if (ontIdList.Count > 0)
 2459:                 {
 2460:                     list = (from e in db.Events
 2461:                             where ontIdList.Contains(e.Ont.Id) && e.Ont != null
 2462:                             select e.Id).ToList();
 2463:                 }
 2464:                 else list = new List<long>();
 2465:             }
 2466:  
 2467:             return list.Distinct().ToList();
 2468:         }
 2469:  
 2470:         ////////////////////////////////////////////////////////////////////////////
 2471:  
 2472:         /// <summary>
 2473:         /// 
 2474:         /// </summary>
 2475:         public static List<long> EventIdListFromNddOntIdList(List<string> nddOntIdList, int take)
 2476:         {
 2477:             List<long> list;
 2478:  
 2479:             using (var db = new Ia.Ftn.Cl.Db())
 2480:             {
 2481:                 if (nddOntIdList.Count > 0)
 2482:                 {
 2483:                     //foreach (var v in nddOntList)
 2484:                     //{
 2485:                     //eventSystemList.Add(v.Pon.PonGroup.Olt.AmsName);
 2486:                     //eventAidOntList.Add("ONT-1-1-" + v.Card + "-" + v.Port + "-" + v.Number);
 2487:                     //eventAidOntVoipList.Add("ONTVOIP-1-1-" + v.Card + "-" + v.Port + "-1");
 2488:  
 2489:                     //foreach (var w in ontOntPotsList) eventAidOntPotsList.Add("ONTPOTS-1-1-" + v.Card + "-" + v.Port + "-" + w.Card + "-" + w.Port);
 2490:                     //}
 2491:  
 2492:                     //eventSystemList = eventSystemList.Distinct().ToList();
 2493:                     //eventAidOntList = eventAidOntList.Distinct().ToList();
 2494:                     //eventAidOntVoipList = eventAidOntVoipList.Distinct().ToList();
 2495:  
 2496:                     /*
 2497:                     eventList = (from e in db.Events where eventSystemList.Contains(e.System) where eventAidOntList.Contains(e.Aid) select e)
 2498:                                 .Union(from e in db.Events where eventSystemList.Contains(e.System) where eventAidOntList.Contains(e.Aid) where eventAidOntVoipList.Contains(e.Aid) select e)
 2499:                                 .Union(from e in db.Events where eventSystemList.Contains(e.System) where eventAidOntList.Contains(e.Aid) where eventAidOntPotsList.Contains(e.Aid) select e)
 2500:                                 .ToList();
 2501:                                 */
 2502:  
 2503:  
 2504:                     list = (from e in db.Events
 2505:                             where e.Ont != null && nddOntIdList.Contains(e.Ont.Id)
 2506:                             orderby e.Created descending
 2507:                             select e.Id).Take(take).ToList();
 2508:                 }
 2509:                 else list = new List<long>();
 2510:             }
 2511:  
 2512:             return list.Distinct().ToList();
 2513:         }
 2514:  
 2515:         ////////////////////////////////////////////////////////////////////////////
 2516:  
 2517:         /// <summary>
 2518:         /// 
 2519:         /// </summary>
 2520:         public static List<int> AgcfGatewayRecordIdListFromIpList(List<string> ipList)
 2521:         {
 2522:             List<int> list;
 2523:  
 2524:             using (var db = new Ia.Ftn.Cl.Db())
 2525:             {
 2526:                 // try Ia.Ftn.Cl.Model.Data.Nokia.AgcfGatewayRecord.IdToIp1Dictionary;
 2527:  
 2528:                 if (ipList.Count > 0)
 2529:                 {
 2530:                     list = (from gr in db.AgcfGatewayRecords
 2531:                             where ipList.Contains(gr.IP1)
 2532:                             select gr.Id).ToList();
 2533:                 }
 2534:                 else list = new List<int>();
 2535:             }
 2536:  
 2537:             return list.Distinct().ToList();
 2538:         }
 2539:  
 2540:         ////////////////////////////////////////////////////////////////////////////
 2541:  
 2542:         /// <summary>
 2543:         /// 
 2544:         /// </summary>
 2545:         public static List<int> AgcfGatewayRecordIdListFromNddOntIdList(List<string> nddOntIdlist)
 2546:         {
 2547:             List<int> list;
 2548:             List<string> nddIpList;
 2549:  
 2550:             if (nddOntIdlist.Count > 0)
 2551:             {
 2552:                 nddIpList = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList
 2553:                              where nddOntIdlist.Contains(o.Id)
 2554:                              select o.Ip).ToList();
 2555:  
 2556:                 using (var db = new Ia.Ftn.Cl.Db())
 2557:                 {
 2558:                     list = (from gr in db.AgcfGatewayRecords
 2559:                             where nddIpList.Contains(gr.IP1)
 2560:                             select gr.Id).ToList();
 2561:                 }
 2562:             }
 2563:             else list = new List<int>();
 2564:  
 2565:             return list.Distinct().ToList();
 2566:         }
 2567:  
 2568:         ////////////////////////////////////////////////////////////////////////////
 2569:  
 2570:         /// <summary>
 2571:         /// 
 2572:         /// </summary>
 2573:         public static List<int> AgcfGatewayRecordIdListFromAgcfEndpointIdList(List<string> agcfEndpointIdList)
 2574:         {
 2575:             List<int> list;
 2576:  
 2577:             using (var db = new Ia.Ftn.Cl.Db())
 2578:             {
 2579:                 if (agcfEndpointIdList.Count > 0)
 2580:                 {
 2581:                     list = (from ep in db.AgcfEndpoints
 2582:                             where agcfEndpointIdList.Contains(ep.Id)
 2583:                             select ep.AgcfGatewayRecord.Id).ToList();
 2584:                 }
 2585:                 else list = new List<int>();
 2586:             }
 2587:  
 2588:             return list.Distinct().ToList();
 2589:         }
 2590:  
 2591:         ////////////////////////////////////////////////////////////////////////////
 2592:  
 2593:         /// <summary>
 2594:         /// 
 2595:         /// </summary>
 2596:         public static List<string> AgcfGatewayRecordIpListFromIdList(List<int> agcfGatewayRecordIdList)
 2597:         {
 2598:             List<string> list;
 2599:  
 2600:             using (var db = new Ia.Ftn.Cl.Db())
 2601:             {
 2602:                 if (agcfGatewayRecordIdList.Count > 0)
 2603:                 {
 2604:                     list = (from gr in db.AgcfGatewayRecords
 2605:                             where agcfGatewayRecordIdList.Contains(gr.Id)
 2606:                             select gr.IP1).ToList();
 2607:                 }
 2608:                 else list = new List<string>();
 2609:             }
 2610:  
 2611:             return list.Distinct().ToList();
 2612:         }
 2613:  
 2614:         ////////////////////////////////////////////////////////////////////////////
 2615:  
 2616:         /// <summary>
 2617:         /// 
 2618:         /// </summary>
 2619:         public static List<int> AgcfGatewayRecordIdListFromGatewayIdList(List<int> gatewayIdList)
 2620:         {
 2621:             List<int> list;
 2622:  
 2623:             using (var db = new Ia.Ftn.Cl.Db())
 2624:             {
 2625:                 if (gatewayIdList.Count > 0)
 2626:                 {
 2627:                     list = (from gr in db.AgcfGatewayRecords
 2628:                             where gatewayIdList.Contains(gr.GwId)
 2629:                             select gr.Id).ToList();
 2630:                 }
 2631:                 else list = new List<int>();
 2632:             }
 2633:  
 2634:             return list.Distinct().ToList();
 2635:         }
 2636:  
 2637:         ////////////////////////////////////////////////////////////////////////////
 2638:  
 2639:         /// <summary>
 2640:         /// 
 2641:         /// </summary>
 2642:         public static List<int> GatewayIdFromAgcfGatewayRecordIdListList(List<int> agcfGatewayRecordIdList)
 2643:         {
 2644:             List<int> list;
 2645:  
 2646:             if (agcfGatewayRecordIdList.Count > 0)
 2647:             {
 2648:                 using (var db = new Ia.Ftn.Cl.Db())
 2649:                 {
 2650:                     list = (from gr in db.AgcfGatewayRecords
 2651:                             where agcfGatewayRecordIdList.Contains(gr.Id)
 2652:                             select gr.GwId).ToList();
 2653:                 }
 2654:             }
 2655:             else list = new List<int>();
 2656:  
 2657:             return list.Distinct().ToList();
 2658:         }
 2659:  
 2660:         ////////////////////////////////////////////////////////////////////////////
 2661:  
 2662:         /// <summary>
 2663:         /// 
 2664:         /// </summary>
 2665:         public static List<string> AgcfEndpointIdListFromAgcfGatewayRecordIdList(List<int> agcfGatewayRecordIdList)
 2666:         {
 2667:             List<string> list;
 2668:  
 2669:             using (var db = new Ia.Ftn.Cl.Db())
 2670:             {
 2671:                 if (agcfGatewayRecordIdList.Count > 0)
 2672:                 {
 2673:                     list = (from e in db.AgcfEndpoints
 2674:                             where agcfGatewayRecordIdList.Contains(e.AgcfGatewayRecord.Id) && e.AgcfGatewayRecord != null
 2675:                             select e.Id).AsNoTracking().ToList();
 2676:                 }
 2677:                 else list = new List<string>();
 2678:             }
 2679:  
 2680:             return list.Distinct().ToList();
 2681:         }
 2682:  
 2683:         ////////////////////////////////////////////////////////////////////////////
 2684:         ////////////////////////////////////////////////////////////////////////////
 2685:  
 2686:         /// <summary>
 2687:         /// 
 2688:         /// </summary>
 2689:         public static List<string> MgwIdListFromAsbrIdList(List<string> asbrIdList)
 2690:         {
 2691:             List<string> list;
 2692:  
 2693:             using (var db = new Ia.Ftn.Cl.Db())
 2694:             {
 2695:                 if (asbrIdList.Count > 0)
 2696:                 {
 2697:                     /* this is just dumb!
 2698:                     list = (from m in db.Mgws
 2699:                             join a in db.Asbrs on m.Id equals a.Mgw.Id
 2700:                             where asbrIdList.Contains(a.Id)
 2701:                             select m.Id).ToList();
 2702:                     */
 2703:  
 2704:                     list = (from a in db.Asbrs
 2705:                             where asbrIdList.Contains(a.Id) && a.Mgw != null
 2706:                             select a.Mgw.Id).AsNoTracking().ToList();
 2707:                 }
 2708:                 else list = new List<string>();
 2709:             }
 2710:  
 2711:             return list.Distinct().ToList();
 2712:         }
 2713:  
 2714:         ////////////////////////////////////////////////////////////////////////////
 2715:  
 2716:         /// <summary>
 2717:         /// 
 2718:         /// </summary>
 2719:         public static List<string> MgwIdListFromIpList(List<string> ipList)
 2720:         {
 2721:             List<string> list, idList;
 2722:  
 2723:             using (var db = new Ia.Ftn.Cl.Db())
 2724:             {
 2725:                 if (ipList.Count > 0)
 2726:                 {
 2727:                     // below is very slow
 2728:                     //list = (from m in db.Mgws where ipList.Contains(m.RA1) select m.Id).AsNoTracking().ToList();
 2729:  
 2730:                     // I will use the fact the Id have the IP in the middle
 2731:                     // see mgwId = Ia.Ftn.Cl.Model.Business.Huawei.Mgw.MgwId(response.NetworkElement, eid);
 2732:  
 2733:                     idList = new List<string>();
 2734:  
 2735:                     foreach (var ip in ipList)
 2736:                     {
 2737:                         idList.Add(Ia.Ftn.Cl.Models.Business.Huawei.SoftX.TecNetworkElement.Domain + ":" + ip + ":" + Ia.Ftn.Cl.Models.Business.Huawei.SoftX.RemotePort);
 2738:                         idList.Add(Ia.Ftn.Cl.Models.Business.Huawei.SoftX.SkbNetworkElement.Domain + ":" + ip + ":" + Ia.Ftn.Cl.Models.Business.Huawei.SoftX.RemotePort);
 2739:                     }
 2740:  
 2741:                     list = (from m in db.Mgws
 2742:                             where idList.Contains(m.Id)
 2743:                             select m.Id).AsNoTracking().ToList();
 2744:                 }
 2745:                 else list = new List<string>();
 2746:             }
 2747:  
 2748:             return list.Distinct().ToList();
 2749:         }
 2750:  
 2751:         ////////////////////////////////////////////////////////////////////////////
 2752:  
 2753:         /// <summary>
 2754:         /// 
 2755:         /// </summary>
 2756:         public static List<string> MgwIpListFromIdList(List<string> mgwIdList)
 2757:         {
 2758:             List<string> list;
 2759:  
 2760:             using (var db = new Ia.Ftn.Cl.Db())
 2761:             {
 2762:                 if (mgwIdList.Count > 0)
 2763:                 {
 2764:                     list = (from m in db.Mgws
 2765:                             where mgwIdList.Contains(m.Id)
 2766:                             select m.RA1).AsNoTracking().ToList();
 2767:                 }
 2768:                 else list = new List<string>();
 2769:             }
 2770:  
 2771:             return list.Distinct().ToList();
 2772:         }
 2773:  
 2774:         ////////////////////////////////////////////////////////////////////////////
 2775:  
 2776:         /// <summary>
 2777:         /// 
 2778:         /// </summary>
 2779:         public static List<string> AsbrIdListFromImpuSipDomainList(List<string> impuSipDomainList)
 2780:         {
 2781:             string id;
 2782:             List<string> list, asbrIdInTecAndSkbNetworkElementList;
 2783:  
 2784:             if (impuSipDomainList.Count > 0)
 2785:             {
 2786:                 asbrIdInTecAndSkbNetworkElementList = new List<string>(impuSipDomainList.Count * 2);
 2787:  
 2788:                 foreach (var isd in impuSipDomainList)
 2789:                 {
 2790:                     id = Ia.Ftn.Cl.Models.Business.Huawei.Asbr.AsbrId(Ia.Ftn.Cl.Models.Business.Huawei.SoftX.TecNetworkElement.Domain, isd);
 2791:                     asbrIdInTecAndSkbNetworkElementList.Add(id);
 2792:  
 2793:                     id = Ia.Ftn.Cl.Models.Business.Huawei.Asbr.AsbrId(Ia.Ftn.Cl.Models.Business.Huawei.SoftX.SkbNetworkElement.Domain, isd);
 2794:                     asbrIdInTecAndSkbNetworkElementList.Add(id);
 2795:                 }
 2796:  
 2797:                 using (var db = new Ia.Ftn.Cl.Db())
 2798:                 {
 2799:                     list = (from a in db.Asbrs
 2800:                             where asbrIdInTecAndSkbNetworkElementList.Contains(a.Id)
 2801:                             select a.Id).AsNoTracking().ToList();
 2802:                 }
 2803:             }
 2804:             else list = new List<string>();
 2805:  
 2806:             return list.Distinct().ToList();
 2807:         }
 2808:  
 2809:         ////////////////////////////////////////////////////////////////////////////
 2810:         ////////////////////////////////////////////////////////////////////////////
 2811:  
 2812:         /// <summary>
 2813:         /// 
 2814:         /// </summary>
 2815:         public static List<string> AgcfEndpointIdListFromSubPartyIdList(List<string> subPartyIdList)
 2816:         {
 2817:             List<string> list;
 2818:  
 2819:             using (var db = new Ia.Ftn.Cl.Db())
 2820:             {
 2821:                 if (subPartyIdList.Count > 0)
 2822:                 {
 2823:                     list = (from sp in db.SubParties
 2824:                             where subPartyIdList.Contains(sp.Id)
 2825:                             select sp.AgcfEndpoint.Id).AsNoTracking().ToList();
 2826:                 }
 2827:                 else list = new List<string>();
 2828:             }
 2829:  
 2830:             return list.Distinct().ToList();
 2831:         }
 2832:  
 2833:         ////////////////////////////////////////////////////////////////////////////
 2834:  
 2835:         /// <summary>
 2836:         /// 
 2837:         /// </summary>
 2838:         public static List<string> AgcfEndpointIdListFromPrividUserList(List<string> prividUserList)
 2839:         {
 2840:             List<string> list0, list;
 2841:  
 2842:             using (var db = new Ia.Ftn.Cl.Db())
 2843:             {
 2844:                 if (prividUserList.Count > 0)
 2845:                 {
 2846:                     list0 = new List<string>();
 2847:  
 2848:                     foreach (var prividUser in prividUserList)
 2849:                     {
 2850:                         list0.Add(Ia.Ftn.Cl.Models.Nokia.AgcfEndpoint.AgcfEndpointId(prividUser));
 2851:                     }
 2852:  
 2853:                     list = (from ep in db.AgcfEndpoints
 2854:                                 //where prividUserList.Contains(ep.PrividUser)
 2855:                             where list0.Contains(ep.Id)
 2856:                             select ep.Id).AsNoTracking().ToList();
 2857:                 }
 2858:                 else list = new List<string>();
 2859:             }
 2860:  
 2861:             return list.Distinct().ToList();
 2862:         }
 2863:  
 2864:         ////////////////////////////////////////////////////////////////////////////
 2865:  
 2866:         /// <summary>
 2867:         /// 
 2868:         /// </summary>
 2869:         public static List<string> AgcfEndpointIdListFromGatewayIdList(List<int> gatewayIdList)
 2870:         {
 2871:             List<string> list;
 2872:  
 2873:             using (var db = new Ia.Ftn.Cl.Db())
 2874:             {
 2875:                 if (gatewayIdList.Count > 0)
 2876:                 {
 2877:                     list = (from ep in db.AgcfEndpoints
 2878:                             where gatewayIdList.Contains(ep.GwId)
 2879:                             select ep.Id).AsNoTracking().ToList();
 2880:                 }
 2881:                 else list = new List<string>();
 2882:             }
 2883:  
 2884:             return list.Distinct().ToList();
 2885:         }
 2886:  
 2887:         ////////////////////////////////////////////////////////////////////////////
 2888:  
 2889:         /// <summary>
 2890:         /// 
 2891:         /// </summary>
 2892:         public static List<string> SubPartyIdListFromAgcfEndpointIdList(List<string> agcfEndpointIdList)
 2893:         {
 2894:             List<string> list;
 2895:  
 2896:             using (var db = new Ia.Ftn.Cl.Db())
 2897:             {
 2898:                 if (agcfEndpointIdList.Count > 0)
 2899:                 {
 2900:                     list = (from sp in db.SubParties
 2901:                             where agcfEndpointIdList.Contains(sp.AgcfEndpoint.Id) && sp.AgcfEndpoint != null
 2902:                             select sp.Id).AsNoTracking().ToList();
 2903:                 }
 2904:                 else list = new List<string>();
 2905:             }
 2906:  
 2907:             return list.Distinct().ToList();
 2908:         }
 2909:  
 2910:         ////////////////////////////////////////////////////////////////////////////
 2911:  
 2912:         /// <summary>
 2913:         /// 
 2914:         /// </summary>
 2915:         public static List<string> SubPartyIdListFromPartyIdList(List<string> partyIdList)
 2916:         {
 2917:             List<string> list;
 2918:  
 2919:             using (var db = new Ia.Ftn.Cl.Db())
 2920:             {
 2921:                 if (partyIdList.Count > 0)
 2922:                 {
 2923:                     list = (from sp in db.SubParties
 2924:                             where partyIdList.Contains(sp.PartyId)
 2925:                             select sp.Id).AsNoTracking().ToList();
 2926:                 }
 2927:                 else list = new List<string>();
 2928:             }
 2929:  
 2930:             return list.Distinct().ToList();
 2931:         }
 2932:  
 2933:         ////////////////////////////////////////////////////////////////////////////
 2934:  
 2935:         /// <summary>
 2936:         /// 
 2937:         /// </summary>
 2938:         public static List<string> SubscriberIdListFromSubPartyIdList(List<string> subPartyIdList)
 2939:         {
 2940:             List<string> list;
 2941:  
 2942:             using (var db = new Ia.Ftn.Cl.Db())
 2943:             {
 2944:                 if (subPartyIdList.Count > 0)
 2945:                 {
 2946:                     list = (from s in db.Subscribers
 2947:                             where subPartyIdList.Contains(s.SubParty.Id)
 2948:                             select s.Id).AsNoTracking().ToList();
 2949:                 }
 2950:                 else list = new List<string>();
 2951:             }
 2952:  
 2953:             return list.Distinct().ToList();
 2954:         }
 2955:  
 2956:         ////////////////////////////////////////////////////////////////////////////
 2957:  
 2958:         /// <summary>
 2959:         /// 
 2960:         /// </summary>
 2961:         public static List<string> SubscriberIdListFromPartyIdList(List<string> partyIdList)
 2962:         {
 2963:             List<string> list;
 2964:  
 2965:             using (var db = new Ia.Ftn.Cl.Db())
 2966:             {
 2967:                 if (partyIdList.Count > 0)
 2968:                 {
 2969:                     // note that Id is PartyId. Maybe I could use it subscriber.Id = Ia.Ftn.Cl.Model.Nokia.Subscriber.SubscriberId(partyId);
 2970:                     //list = (from s in db.Subscribers where partyIdList.Contains(s.PartyId) select s.Id).AsNoTracking().ToList();
 2971:                     list = (from s in db.Subscribers where partyIdList.Contains(s.Id) select s.Id).AsNoTracking().ToList();
 2972:                 }
 2973:                 else list = new List<string>();
 2974:             }
 2975:  
 2976:             return list.Distinct().ToList();
 2977:         }
 2978:  
 2979:         ////////////////////////////////////////////////////////////////////////////
 2980:  
 2981:         /// <summary>
 2982:         /// 
 2983:         /// </summary>
 2984:         public static List<string> ServiceListFromGatewayIdList(List<int> gatewayIdList)
 2985:         {
 2986:             List<string> list;
 2987:  
 2988:             using (var db = new Ia.Ftn.Cl.Db())
 2989:             {
 2990:                 if (gatewayIdList.Count > 0)
 2991:                 {
 2992:                     list = new List<string>();
 2993:  
 2994:                     var list0 = (from s in db.Subscribers
 2995:                                  join sp in db.SubParties on s.SubParty.Id equals sp.Id
 2996:                                  join ep in db.AgcfEndpoints on sp.AgcfEndpoint.Id equals ep.Id
 2997:                                  join gr in db.AgcfGatewayRecords on ep.AgcfGatewayRecord.Id equals gr.Id
 2998:                                  where gatewayIdList.Contains(gr.GwId)
 2999:                                  select s.PartyId).AsNoTracking().ToList();
 3000:  
 3001:                     foreach (var partyId in list0)
 3002:                     {
 3003:                         list.Add(Ia.Ftn.Cl.Models.Business.NumberFormatConverter.Service(partyId));
 3004:                     }
 3005:                 }
 3006:                 else list = new List<string>();
 3007:             }
 3008:  
 3009:             return list.Distinct().ToList();
 3010:         }
 3011:  
 3012:         ////////////////////////////////////////////////////////////////////////////
 3013:         ////////////////////////////////////////////////////////////////////////////   
 3014:  
 3015:         /// <summary>
 3016:         /// 
 3017:         /// </summary>
 3018:         public static void SynchronizeNumberFormatLists(ref List<string> partyIdList, ref List<string> prividUserList, ref List<string> serviceList, ref List<int> numberList, ref List<long> serviceLongList, ref List<string> impuSipDomainList, ref List<string> sipUserNameList, ref List<string> serviceWithCountryCodeList, ref List<string> serviceIdList)
 3019:         {
 3020:             int number;
 3021:             long numberWithCountryCode;
 3022:             string service, impuSipDomain, sipUserName, serviceWithCountryCode, partyId, prividUser;
 3023:  
 3024:             foreach (var pi in partyIdList)
 3025:             {
 3026:                 service = Ia.Ftn.Cl.Models.Business.NumberFormatConverter.Service(pi);
 3027:  
 3028:                 if (!string.IsNullOrEmpty(service))
 3029:                 {
 3030:                     number = int.Parse(service);
 3031:                     numberWithCountryCode = long.Parse(Ia.Ftn.Cl.Models.Business.Service.CountryCode.ToString() + number);
 3032:                     impuSipDomain = Ia.Ftn.Cl.Models.Business.NumberFormatConverter.ImpuSipDomain(service);
 3033:                     sipUserName = Ia.Ftn.Cl.Models.Business.NumberFormatConverter.SipUserName(service);
 3034:                     serviceWithCountryCode = Ia.Ftn.Cl.Models.Business.NumberFormatConverter.ServiceWithCountryCode(service);
 3035:                     partyId = Ia.Ftn.Cl.Models.Business.NumberFormatConverter.PartyId(service);
 3036:                     prividUser = Ia.Ftn.Cl.Models.Business.NumberFormatConverter.PrividUser(service);
 3037:  
 3038:                     serviceList.Add(service);
 3039:                     numberList.Add(number);
 3040:                     serviceLongList.Add(numberWithCountryCode);
 3041:                     impuSipDomainList.Add(impuSipDomain);
 3042:                     sipUserNameList.Add(sipUserName);
 3043:                     serviceWithCountryCodeList.Add(serviceWithCountryCode);
 3044:                     //partyIdList.Add(partyId);
 3045:                     prividUserList.Add(prividUser);
 3046:                 }
 3047:             }
 3048:  
 3049:             foreach (var s in serviceList)
 3050:             {
 3051:                 service = Ia.Ftn.Cl.Models.Business.NumberFormatConverter.Service(s);
 3052:  
 3053:                 if (!string.IsNullOrEmpty(service))
 3054:                 {
 3055:                     number = int.Parse(service);
 3056:                     numberWithCountryCode = long.Parse(Ia.Ftn.Cl.Models.Business.Service.CountryCode.ToString() + number);
 3057:                     impuSipDomain = Ia.Ftn.Cl.Models.Business.NumberFormatConverter.ImpuSipDomain(service);
 3058:                     sipUserName = Ia.Ftn.Cl.Models.Business.NumberFormatConverter.SipUserName(service);
 3059:                     serviceWithCountryCode = Ia.Ftn.Cl.Models.Business.NumberFormatConverter.ServiceWithCountryCode(service);
 3060:                     partyId = Ia.Ftn.Cl.Models.Business.NumberFormatConverter.PartyId(service);
 3061:                     prividUser = Ia.Ftn.Cl.Models.Business.NumberFormatConverter.PrividUser(service);
 3062:  
 3063:                     //serviceList.Add(service);
 3064:                     numberList.Add(number);
 3065:                     serviceLongList.Add(numberWithCountryCode);
 3066:                     impuSipDomainList.Add(impuSipDomain);
 3067:                     sipUserNameList.Add(sipUserName);
 3068:                     serviceWithCountryCodeList.Add(serviceWithCountryCode);
 3069:                     partyIdList.Add(partyId);
 3070:                     prividUserList.Add(prividUser);
 3071:                 }
 3072:             }
 3073:  
 3074:             serviceList = serviceList.Distinct().ToList();
 3075:             numberList = numberList.Distinct().ToList();
 3076:             serviceLongList = serviceLongList.Distinct().ToList();
 3077:             impuSipDomainList = impuSipDomainList.Distinct().ToList();
 3078:             sipUserNameList = sipUserNameList.Distinct().ToList();
 3079:             serviceWithCountryCodeList = serviceWithCountryCodeList.Distinct().ToList();
 3080:             partyIdList = partyIdList.Distinct().ToList();
 3081:             prividUserList = prividUserList.Distinct().ToList();
 3082:  
 3083:             serviceIdList = Ia.Ftn.Cl.Models.Business.Service.ServiceListToServiceIdListForAllServiceTypes(serviceList);
 3084:         }
 3085:  
 3086:         ////////////////////////////////////////////////////////////////////////////   
 3087:  
 3088:         /// <summary>
 3089:         /// 
 3090:         /// </summary>
 3091:         public static void UpdateServiceListFromServiceRequestServiceIdOrService2IdList(List<string> serviceRequestServiceIdListOrService2IdList, ref List<string> serviceList)
 3092:         {
 3093:             string service;
 3094:  
 3095:             foreach (var si in serviceRequestServiceIdListOrService2IdList)
 3096:             {
 3097:                 service = Ia.Ftn.Cl.Models.Business.ServiceRequestService.ServiceIdToService(si);
 3098:  
 3099:                 if (!string.IsNullOrEmpty(service)) serviceList.Add(service);
 3100:             }
 3101:  
 3102:             serviceList = serviceList.Distinct().ToList();
 3103:         }
 3104:  
 3105:         ////////////////////////////////////////////////////////////////////////////   
 3106:  
 3107:         /// <summary>
 3108:         /// 
 3109:         /// </summary>
 3110:         public static void CollectServiceListFromEmsOntSipInfoListAndEmsVoipPstnUserListByEmsOntIdList(List<string> emsOntIdList, ref List<string> serviceList)
 3111:         {
 3112:             string service;
 3113:             List<string> emsOntSipInfoSipUserNameList, emsVoipPstnUserDnList;
 3114:  
 3115:             if (emsOntIdList.Count > 0)
 3116:             {
 3117:                 using (var db = new Ia.Ftn.Cl.Db())
 3118:                 {
 3119:                     emsOntSipInfoSipUserNameList = (from eosi in db.EmsOntSipInfoes
 3120:                                                     where emsOntIdList.Contains(eosi.EmsOnt.Id)
 3121:                                                     select eosi.SIPUSERNAME).AsNoTracking().ToList();
 3122:  
 3123:                     emsOntSipInfoSipUserNameList = emsOntSipInfoSipUserNameList.Distinct().ToList();
 3124:  
 3125:                     emsVoipPstnUserDnList = (from evpu in db.EmsVoipPstnUsers
 3126:                                              where evpu.EmsOnt != null && emsOntIdList.Contains(evpu.EmsOnt.Id)
 3127:                                              select evpu.DN).AsNoTracking().ToList();
 3128:  
 3129:                     emsVoipPstnUserDnList = emsVoipPstnUserDnList.Distinct().ToList();
 3130:                 }
 3131:  
 3132:                 foreach (var eosisun in emsOntSipInfoSipUserNameList)
 3133:                 {
 3134:                     service = Ia.Ftn.Cl.Models.Business.NumberFormatConverter.Service(eosisun);
 3135:  
 3136:                     if (!string.IsNullOrEmpty(service)) serviceList.Add(service);
 3137:                 }
 3138:  
 3139:                 foreach (var evpud in emsVoipPstnUserDnList)
 3140:                 {
 3141:                     service = Ia.Ftn.Cl.Models.Business.NumberFormatConverter.Service(evpud);
 3142:  
 3143:                     if (!string.IsNullOrEmpty(service)) serviceList.Add(service);
 3144:                 }
 3145:             }
 3146:             else
 3147:             {
 3148:  
 3149:             }
 3150:  
 3151:             serviceList = serviceList.Distinct().ToList();
 3152:         }
 3153:  
 3154:         ////////////////////////////////////////////////////////////////////////////   
 3155:  
 3156:         /// <summary>
 3157:         /// 
 3158:         /// </summary>
 3159:         public static void CollectServiceListFromAgcfEndpointList(List<Ia.Ftn.Cl.Models.Ui.Nokia.AgcfEndpoint> agcfEndpointList, ref List<string> serviceList)
 3160:         {
 3161:             string service;
 3162:  
 3163:             foreach (var ep in agcfEndpointList)
 3164:             {
 3165:                 service = Ia.Ftn.Cl.Models.Business.NumberFormatConverter.Service(ep.PrividUser);
 3166:  
 3167:                 if (!string.IsNullOrEmpty(service)) serviceList.Add(service);
 3168:             }
 3169:  
 3170:             serviceList = serviceList.Distinct().ToList();
 3171:         }
 3172:  
 3173:         ////////////////////////////////////////////////////////////////////////////   
 3174:  
 3175:         /// <summary>
 3176:         /// 
 3177:         /// </summary>
 3178:         public static void CollectServiceListFromSubscriberList(List<Ia.Ftn.Cl.Models.Ui.Nokia.Subscriber> subscriberList, ref List<string> serviceList)
 3179:         {
 3180:             string service;
 3181:  
 3182:             foreach (var s in subscriberList)
 3183:             {
 3184:                 service = Ia.Ftn.Cl.Models.Business.NumberFormatConverter.Service(s.PartyId);
 3185:  
 3186:                 if (!string.IsNullOrEmpty(service)) serviceList.Add(service);
 3187:             }
 3188:  
 3189:             serviceList = serviceList.Distinct().ToList();
 3190:         }
 3191:  
 3192:         ////////////////////////////////////////////////////////////////////////////
 3193:         ////////////////////////////////////////////////////////////////////////////   
 3194:     }
 3195:  
 3196:     ////////////////////////////////////////////////////////////////////////////
 3197:     ////////////////////////////////////////////////////////////////////////////   
 3198: }