)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Skip Navigation LinksHome » Code Library » Ims

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

Optical Fiber Network's Operations Support System Management Intranet (OFN OSS) support class for Nokia's Optical Fiber Network (OFN) data model.

    1: using Microsoft.EntityFrameworkCore;
    2: using System;
    3: using System.Collections.Generic;
    4: using System.Data;
    5: using System.Linq;
    6: using System.Text;
    7: using System.Web;
    8:  
    9: namespace Ia.Ngn.Cl.Model.Data.Nokia
   10: {
   11:     ////////////////////////////////////////////////////////////////////////////
   12:  
   13:     /// <summary publish="true">
   14:     /// Optical Fiber Network's Operations Support System Management Intranet (OFN OSS) support class for Nokia's Optical Fiber Network (OFN) data model.
   15:     /// </summary>
   16:     /// 
   17:     /// <remarks> 
   18:     /// Copyright © 2014-2019 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   19:     ///
   20:     /// This library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
   21:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   22:     ///
   23:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   24:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   25:     /// 
   26:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   27:     /// 
   28:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   29:     /// </remarks> 
   30:     public class Ims
   31:     {
   32:         private static List<string> agcfGatewayRecordIp1sWithinWhichSubPartiesHaveServiceBundle2CategoryList, agcfGatewayRecordIp1sThatIndicateFsdb0List;
   33:  
   34:         private static readonly object objectLock = new object();
   35:  
   36:         ////////////////////////////////////////////////////////////////////////////
   37:  
   38:         /// <summary>
   39:         ///
   40:         /// </summary>
   41:         public Ims() { }
   42:  
   43:         ////////////////////////////////////////////////////////////////////////////
   44:  
   45:         /// <summary>
   46:         ///
   47:         /// </summary>
   48:         public static List<Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord> AgcfGatewayRecordsWithinNddOntListWithWrongSecondaryIpList()
   49:         {
   50:             string ip;
   51:             Dictionary<string, string> agcfGatewayRecordIpToMateExternalIPAddrDictionary;
   52:             Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord agcfGatewayRecord;
   53:             List<Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont> ngnOntList;
   54:             List<Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord> agcfGatewayRecordList, agcfGatewayRecordList2;
   55:  
   56:             ngnOntList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList;
   57:             agcfGatewayRecordList = Ia.Ngn.Cl.Model.Data.Nokia.AgcfGatewayRecord.List();
   58:  
   59:             agcfGatewayRecordIpToMateExternalIPAddrDictionary = Ia.Ngn.Cl.Model.Data.Nokia.AgcfGatewayRecord.IpToMateExternalIPAddrDictionary;
   60:  
   61:             agcfGatewayRecordList2 = new List<Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord>();
   62:  
   63:             foreach (var v in ngnOntList)
   64:             {
   65:                 if (agcfGatewayRecordIpToMateExternalIPAddrDictionary.ContainsKey(v.Ip))
   66:                 {
   67:                     ip = agcfGatewayRecordIpToMateExternalIPAddrDictionary[v.Ip];
   68:  
   69:                     if (ip != v.MgcSecondaryIp)
   70:                     {
   71:                         agcfGatewayRecord = (from gr in agcfGatewayRecordList
   72:                                              where gr.IP1 == v.Ip
   73:                                              select gr).SingleOrDefault();
   74:  
   75:                         if (agcfGatewayRecord != null)
   76:                         {
   77:                             agcfGatewayRecordList2.Add(agcfGatewayRecord);
   78:                         }
   79:                     }
   80:                 }
   81:             }
   82:  
   83:             return agcfGatewayRecordList2;
   84:         }
   85:  
   86:         ////////////////////////////////////////////////////////////////////////////
   87:  
   88:         /// <summary>
   89:         ///
   90:         /// </summary>
   91:         public static List<string> ServiceWhereSubscriberAlternateOtasRealmGroupNumberDoesNotEqualSubPartyAssocOtasRealmGroupNumberList()
   92:         {
   93:             List<string> list;
   94:  
   95:             using (var db = new Ia.Ngn.Cl.Model.Ngn())
   96:             {
   97:                 list = (from su in db.Subscribers
   98:                         join sp in db.SubParties on su.SubParty.Id equals sp.Id
   99:                         //join ep in db.AgcfEndpoints on sp.AgcfEndpoint.Id equals ep.Id
  100:                         where sp.AssocOtasRealm.Substring(0, 26) != su.AlternateOtasRealm.Substring(0, 26)
  101:                         // "stas-stdn.fsimsgroup0-001." length = 26
  102:                         select su.PartyId).AsNoTracking().ToList();
  103:             }
  104:  
  105:             return list;
  106:         }
  107:  
  108:         ////////////////////////////////////////////////////////////////////////////
  109:  
  110:         /// <summary>
  111:         ///
  112:         /// </summary>
  113:         public static void CreateH248SubscriberAndSubPartyAndAgcfEndpoint(Ia.Ngn.Cl.Model.Client.Nokia.Ims ims, int gwId, string service, int flatTermId, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt, out string result)
  114:         {
  115:             Ia.Ngn.Cl.Model.Business.Nokia.Ims.Response entNgfsSubscriberResponse, entNgfsAgcfEndpointResponse;
  116:  
  117:             ims.EntNgfsSubscriberAndNgfsSubPartyV2_H248(service, gwId, nddOnt, out entNgfsSubscriberResponse);
  118:  
  119:             if (entNgfsSubscriberResponse.ResultCode == Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.Successful)
  120:             {
  121:                 ims.EntNgfsAgcfEndpointV2(service, gwId, flatTermId, nddOnt, out entNgfsAgcfEndpointResponse);
  122:  
  123:                 // remove number if creation of endpoint failed
  124:                 if (entNgfsAgcfEndpointResponse.ResultCode != Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.Successful)
  125:                 {
  126:                     ims.DltNgfsSubscriberAndNgfsSubPartyV2(service, nddOnt, out entNgfsSubscriberResponse);
  127:                 }
  128:                 else
  129:                 {
  130:  
  131:                 }
  132:             }
  133:             else
  134:             {
  135:                 entNgfsAgcfEndpointResponse = new Ia.Ngn.Cl.Model.Business.Nokia.Ims.Response();
  136:  
  137:                 entNgfsAgcfEndpointResponse.ResultCode = Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.Null;
  138:             }
  139:  
  140:             result = service + "," + gwId + "," + flatTermId + "," + entNgfsSubscriberResponse.ResultCode.ToString() + "," + entNgfsAgcfEndpointResponse.ResultCode.ToString();
  141:         }
  142:  
  143:         ////////////////////////////////////////////////////////////////////////////
  144:  
  145:         /// <summary>
  146:         ///
  147:         /// </summary>
  148:         public static void CreateSipSubscriber(Ia.Ngn.Cl.Model.Client.Nokia.Ims ims, string service, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt, out string result)
  149:         {
  150:             ims.EntNgfsSubscriberAndNgfsSubPartyV2_Sip(service, nddOnt, out Ia.Ngn.Cl.Model.Business.Nokia.Ims.Response response);
  151:  
  152:             result = service + "," + response.ResultCode.ToString();
  153:         }
  154:  
  155:         ////////////////////////////////////////////////////////////////////////////
  156:  
  157:         /// <summary>
  158:         ///
  159:         /// </summary>
  160:         public static void Modify248SubscriberAndSubPartyAndDeleteAgcfEndpointToSip(Ia.Ngn.Cl.Model.Client.Nokia.Ims ims, string service, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt, out string result)
  161:         {
  162:             Ia.Ngn.Cl.Model.Business.Nokia.Ims.Response edNgfsSubscriberResponse, dltNgfsAgcfEndpointResponse;
  163:  
  164:             ims.EdNgfsSubscriberAndNgfsSubPartyV2_H248ToSip(service, nddOnt, out edNgfsSubscriberResponse);
  165:  
  166:             if (edNgfsSubscriberResponse.ResultCode == Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.Successful)
  167:             {
  168:                 ims.DltNgfsAgcfEndpointV2(service, nddOnt, out dltNgfsAgcfEndpointResponse);
  169:             }
  170:             else
  171:             {
  172:                 dltNgfsAgcfEndpointResponse = new Ia.Ngn.Cl.Model.Business.Nokia.Ims.Response();
  173:  
  174:                 dltNgfsAgcfEndpointResponse.ResultCode = Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.Null;
  175:             }
  176:  
  177:             result = service + "," + edNgfsSubscriberResponse.ResultCode.ToString() + "," + dltNgfsAgcfEndpointResponse.ResultCode.ToString();
  178:         }
  179:  
  180:         ////////////////////////////////////////////////////////////////////////////
  181:  
  182:         /// <summary>
  183:         ///
  184:         /// </summary>
  185:         public static void DeleteAgcfEndpointAndH248SubscriberAndSubParty(Ia.Ngn.Cl.Model.Client.Nokia.Ims ims, string service, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt, out string result)
  186:         {
  187:             ims.DltNgfsAgcfEndpointV2(service, nddOnt, out Ia.Ngn.Cl.Model.Business.Nokia.Ims.Response dltNgfsAgcfEndpointResponse);
  188:  
  189:             ims.DltNgfsSubscriberAndNgfsSubPartyV2(service, nddOnt, out Ia.Ngn.Cl.Model.Business.Nokia.Ims.Response dltNgfsSubscriberResponse);
  190:  
  191:             result = service + "," + dltNgfsSubscriberResponse.ResultCode.ToString() + "," + dltNgfsAgcfEndpointResponse.ResultCode.ToString();
  192:         }
  193:  
  194:         ////////////////////////////////////////////////////////////////////////////
  195:  
  196:         /// <summary>
  197:         ///
  198:         /// </summary>
  199:         public static void DeleteAgcfEndpointAndH248SubscriberAndSubParty(Ia.Ngn.Cl.Model.Client.Nokia.Ims ims, string service, string primarySwitch, string fsdb, out string result)
  200:         {
  201:             ims.DltNgfsAgcfEndpointV2(service, primarySwitch, fsdb, out Ia.Ngn.Cl.Model.Business.Nokia.Ims.Response dltNgfsAgcfEndpointResponse);
  202:  
  203:             ims.DltNgfsSubscriberAndNgfsSubPartyV2(service, primarySwitch, fsdb, out Ia.Ngn.Cl.Model.Business.Nokia.Ims.Response dltNgfsSubscriberResponse);
  204:  
  205:             result = service + "," + dltNgfsSubscriberResponse.ResultCode.ToString() + "," + dltNgfsAgcfEndpointResponse.ResultCode.ToString();
  206:         }
  207:  
  208:         ////////////////////////////////////////////////////////////////////////////
  209:  
  210:         /// <summary>
  211:         ///
  212:         /// </summary>
  213:         public static void DeleteH248SubscriberAndSubParty(Ia.Ngn.Cl.Model.Client.Nokia.Ims ims, string service, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt, out string result)
  214:         {
  215:             // I use this function sometimes to delete wrong subscriber entries by staff
  216:  
  217:             ims.DltNgfsSubscriberAndNgfsSubPartyV2(service, nddOnt, out Ia.Ngn.Cl.Model.Business.Nokia.Ims.Response dltNgfsSubscriberResponse);
  218:  
  219:             result = service + "," + dltNgfsSubscriberResponse.ResultCode.ToString();
  220:         }
  221:  
  222:         ////////////////////////////////////////////////////////////////////////////
  223:  
  224:         /// <summary>
  225:         ///
  226:         /// </summary>
  227:         public static void DeleteSipSubscriber(Ia.Ngn.Cl.Model.Client.Nokia.Ims ims, string service, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt, out string result)
  228:         {
  229:             ims.DltNgfsSubscriberAndNgfsSubPartyV2(service, nddOnt, out Ia.Ngn.Cl.Model.Business.Nokia.Ims.Response dltNgfsSubscriberResponse);
  230:  
  231:             result = service + "," + dltNgfsSubscriberResponse.ResultCode.ToString();
  232:         }
  233:  
  234:         ////////////////////////////////////////////////////////////////////////////
  235:         ////////////////////////////////////////////////////////////////////////////
  236:  
  237:  
  238:  
  239:  
  240:  
  241:  
  242:         ////////////////////////////////////////////////////////////////////////////
  243:         ////////////////////////////////////////////////////////////////////////////
  244:  
  245:         /// <summary>
  246:         ///
  247:         /// </summary>
  248:         public static void UpdateSupplementaryService(Ia.Ngn.Cl.Model.Client.Nokia.Ims ims, string service, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt, Ia.Ngn.Cl.Model.Business.Service.SupplementaryService supplementaryService, bool supplementaryServiceState, out string result)
  249:         {
  250:             Ia.Ngn.Cl.Model.Business.Nokia.Ims.Response response;
  251:  
  252:             switch (supplementaryService)
  253:             {
  254:                 case (Ia.Ngn.Cl.Model.Business.Service.SupplementaryService.CallerId):
  255:                     {
  256:                         ims.EdNgfsSubscriberV2_CallingLineId(service, nddOnt, supplementaryServiceState, out response);
  257:                         result = service + "," + nddOnt.Access.Name + ",CallerId: " + supplementaryServiceState.ToString().ToLower() + "," + response.ResultCode.ToString();
  258:                         break;
  259:                     }
  260:                 case (Ia.Ngn.Cl.Model.Business.Service.SupplementaryService.AbbriviatedCalling):
  261:                     {
  262:                         ims.EdNgfsSubscriberV2_OneDigitSpeedDial(service, nddOnt, supplementaryServiceState, out response);
  263:                         result = service + "," + nddOnt.Access.Name + ",AbbriviatedCalling: " + supplementaryServiceState.ToString().ToLower() + "," + response.ResultCode.ToString();
  264:                         break;
  265:                     }
  266:                 case (Ia.Ngn.Cl.Model.Business.Service.SupplementaryService.CallForwarding):
  267:                     {
  268:                         ims.EdNgfsSubscriberV2_CallForwardingVari(service, nddOnt, supplementaryServiceState, out response);
  269:                         result = service + "," + nddOnt.Access.Name + ",CallForwarding: " + supplementaryServiceState.ToString().ToLower() + "," + response.ResultCode.ToString();
  270:                         break;
  271:                     }
  272:                 case (Ia.Ngn.Cl.Model.Business.Service.SupplementaryService.CallWaiting):
  273:                     {
  274:                         ims.EdNgfsSubscriberV2_CallWaiting(service, nddOnt, supplementaryServiceState, out Ia.Ngn.Cl.Model.Business.Nokia.Ims.Response subscriberResponse);
  275:  
  276:                         if (nddOnt.Pon.PonGroup.Olt.IsSip == false) // if H.248
  277:                         {
  278:                             result = service + "," + nddOnt.Access.Name + ",CallWaiting: " + supplementaryServiceState.ToString().ToLower() + ", subscriber: " + subscriberResponse.ResultCode.ToString();
  279:                         }
  280:                         else
  281:                         {
  282:                             ims.EdNgfsAgcfEndpointV2_CallWaiting(service, nddOnt, supplementaryServiceState, out Ia.Ngn.Cl.Model.Business.Nokia.Ims.Response agcfEndpointResponse);
  283:  
  284:                             result = service + "," + nddOnt.Access.Name + ",CallWaiting: " + supplementaryServiceState.ToString().ToLower() + ", subscriber: " + subscriberResponse.ResultCode.ToString() + ", agcfEndpoint: " + agcfEndpointResponse.ResultCode.ToString();
  285:                         }
  286:  
  287:                         break;
  288:                     }
  289:                 case (Ia.Ngn.Cl.Model.Business.Service.SupplementaryService.ConferenceCall):
  290:                     {
  291:                         ims.EdNgfsSubscriberV2_ConferenceCall(service, nddOnt, supplementaryServiceState, out response);
  292:                         result = service + "," + nddOnt.Access.Name + ",ConferenceCall: " + supplementaryServiceState.ToString().ToLower() + "," + response.ResultCode.ToString();
  293:                         break;
  294:                     }
  295:                 case (Ia.Ngn.Cl.Model.Business.Service.SupplementaryService.WakeupCall):
  296:                     {
  297:                         ims.EdNgfsSubscriberV2_ReminderCall(service, nddOnt, supplementaryServiceState, out response);
  298:                         result = service + "," + nddOnt.Access.Name + ",WakeupCall: " + supplementaryServiceState.ToString().ToLower() + "," + response.ResultCode.ToString();
  299:                         break;
  300:                     }
  301:                 case (Ia.Ngn.Cl.Model.Business.Service.SupplementaryService.InternationalCallingUserControlled):
  302:                     {
  303:                         ims.EdNgfsSubscriberV2_InternationalCallingUserControlled(service, nddOnt, supplementaryServiceState, out response);
  304:                         result = service + "," + nddOnt.Access.Name + ",InternationalCallingUserControlled: " + supplementaryServiceState.ToString().ToLower() + "," + response.ResultCode.ToString();
  305:                         break;
  306:                     }
  307:                 case (Ia.Ngn.Cl.Model.Business.Service.SupplementaryService.InternationalCalling):
  308:                     {
  309:                         ims.EdNgfsSubscriberV2_InternationalCalling(service, nddOnt, supplementaryServiceState, out response);
  310:                         result = service + "," + nddOnt.Access.Name + ",InternationalCalling: " + supplementaryServiceState.ToString().ToLower() + "," + response.ResultCode.ToString();
  311:                         break;
  312:                     }
  313:                 case (Ia.Ngn.Cl.Model.Business.Service.SupplementaryService.ServiceSuspension):
  314:                     {
  315:                         ims.EdNgfsSubscriberV2_ServiceSuspension(service, nddOnt, supplementaryServiceState, out response);
  316:                         result = service + "," + nddOnt.Access.Name + ",ServiceSuspension: " + supplementaryServiceState.ToString().ToLower() + "," + response.ResultCode.ToString();
  317:                         break;
  318:                     }
  319:                 default:
  320:                     {
  321:                         result = service + ",unknown SupplementaryService: " + supplementaryServiceState.ToString().ToLower();
  322:                         break;
  323:                     }
  324:             }
  325:         }
  326:  
  327:         ////////////////////////////////////////////////////////////////////////////
  328:  
  329:         /// <summary>
  330:         ///
  331:         /// </summary>
  332:         public static void AssignServiceSuspensionStateToServiceSubscriber(Ia.Ngn.Cl.Model.Client.Nokia.Ims ims, string service, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt, bool serviceSuspensionState, out string result)
  333:         {
  334:             ims.EdNgfsSubscriberV2_ServiceSuspension(service, nddOnt, serviceSuspensionState, out Ia.Ngn.Cl.Model.Business.Nokia.Ims.Response response);
  335:  
  336:             result = service + "," + nddOnt.Access.Name + ",service suspension: " + serviceSuspensionState.ToString().ToLower() + "," + response.ResultCode.ToString();
  337:         }
  338:  
  339:         ////////////////////////////////////////////////////////////////////////////
  340:  
  341:         /// <summary>
  342:         ///
  343:         /// </summary>
  344:         public static Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord ReadAgcfGatewayRecordForGwId(Ia.Ngn.Cl.Model.Client.Nokia.Ims ims, int gwId, out string result)
  345:         {
  346:             bool b;
  347:             string r;
  348:             Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord agcfGatewayRecord;
  349:  
  350:             r = string.Empty;
  351:  
  352:             agcfGatewayRecord = ims.RtrvNgfsAgcfGatewayRecordV2(gwId, out Ia.Ngn.Cl.Model.Business.Nokia.Ims.Response response);
  353:  
  354:             if (response.ResultCode == Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.Successful || response.ResultCode == Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.PlxServiceObjectDoesNotExist)
  355:             {
  356:                 b = Ia.Ngn.Cl.Model.Data.Nokia.Ims.UpdateAgcfGatewayRecord(gwId, response, agcfGatewayRecord, out r);
  357:             }
  358:  
  359:             result = "GatewayRecord: " + gwId + ": " + response.ResultCode.ToString() + ": " + r;
  360:  
  361:             return agcfGatewayRecord;
  362:         }
  363:  
  364:         /*
  365:         ////////////////////////////////////////////////////////////////////////////
  366: 
  367:         /// <summary>
  368:         ///
  369:         /// </summary>
  370:         public static void ReadAgcfEndpointListForGwId(Ia.Ngn.Cl.Model.Client.Nokia.Ims ims, int gwId, out string result)
  371:         {
  372:             bool b;
  373:             int agcfGatewayRecordId;
  374:             Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt;
  375:             Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord agcfGatewayRecord;
  376:             List<Ia.Ngn.Cl.Model.Nokia.AgcfEndpoint> agcfEndpointList;
  377: 
  378:             // below: read the AgcfGatewayRecord
  379:             agcfGatewayRecordId = Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord.AgcfGatewayRecordId(Ia.Ngn.Cl.Model.Business.Nokia.AgcfGatewayTable.NgfsAgcfGatewayTableAid, gwId);
  380:             agcfGatewayRecord = Ia.Ngn.Cl.Model.Data.Nokia.AgcfGatewayRecord.Read(agcfGatewayRecordId);
  381: 
  382:             if (agcfGatewayRecord != null)
  383:             {
  384:                 nddOnt = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntIpToOntDictionary.ContainsKey(agcfGatewayRecord.IP1) ? Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntIpToOntDictionary[agcfGatewayRecord.IP1] : null;
  385: 
  386:                 if (nddOnt != null)
  387:                 {
  388:                     agcfEndpointList = ims.RtrvNgfsAgcfEndpointV2List(agcfGatewayRecord.GwId, nddOnt, out Ia.Ngn.Cl.Model.Business.Nokia.Ims.Response response);
  389: 
  390:                     if (response.ResultCode == Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.Successful || response.ResultCode == Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.PlxServiceObjectDoesNotExist || response.ResultCode == Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.SuccessfulButNoParameters)
  391:                     {
  392:                         b = Ia.Ngn.Cl.Model.Data.Nokia.Ims.UpdateNgfsAgcfEndpointList(gwId, agcfGatewayRecordId, response, agcfEndpointList);
  393:                     }
  394:                     else if (response.ResultCode == Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.SessionInvalid) 
  395:                     { 
  396:                     }
  397:                     else throw new Exception(@"Undefined result code """ + response + @""" seen in Ia.Ngn.Cl.Model.Data.Nokia.Ims.ResultCode");
  398: 
  399:                     result = "Endpoint: GwId:" + gwId + ", " + response.ResultCode.ToString();
  400:                 }
  401:                 else
  402:                 {
  403:                     result = "Endpoint: " + "Error: nddOnt == null, GwId:" + gwId;
  404:                 }
  405:             }
  406:             else
  407:             {
  408:                 result = "Endpoint: " + "GwId:" + gwId + ", Exception: " + @"agcfGatewayRecord is null, agcfGatewayRecordsId=" + agcfGatewayRecordId;
  409:             }
  410:         }
  411:         */
  412:  
  413:         ////////////////////////////////////////////////////////////////////////////
  414:  
  415:         /// <summary>
  416:         ///
  417:         /// </summary>
  418:         public static void CreateAgcfGatewayRecordForGwId(Ia.Ngn.Cl.Model.Client.Nokia.Ims ims, int gwId, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt, out string result)
  419:         {
  420:             ims.EntNgfsAgcfGwCombinedRecV2(gwId, nddOnt, out Ia.Ngn.Cl.Model.Business.Nokia.Ims.Response response);
  421:  
  422:             result = response.ResultCode.ToString();
  423:         }
  424:  
  425:         ////////////////////////////////////////////////////////////////////////////
  426:  
  427:         /// <summary>
  428:         ///
  429:         /// </summary>
  430:         public static void ReadUpdateAgcfGatewayRecordAndAgcfEndpointListAndSubPartyAndSubscriberAndServiceForGwId(Ia.Ngn.Cl.Model.Client.Nokia.Ims nokiaIms/*, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt*/, int gwId, out string result)
  431:         {
  432:             bool agcfGatewayRecordUpdated, agcfEndpointListUpdated, ngfsSubPartyUpdated, ngfsSubscriberUpdated;
  433:             int agcfGatewayRecordId, imsService;
  434:             string service, primarySwitch, partyId, prividUser, subPartyId, r;
  435:             //Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt;
  436:             Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord agcfGatewayRecord;
  437:             Ia.Ngn.Cl.Model.Nokia.SubParty subParty;
  438:             Ia.Ngn.Cl.Model.Nokia.Subscriber subscriber;
  439:             List<Ia.Ngn.Cl.Model.Nokia.AgcfEndpoint> agcfEndpointList;
  440:  
  441:             // Read GwId->Ep(s)->Sp->Sub, and ask about non FSDB sub search on XML
  442:  
  443:             result = "gwId: " + gwId;
  444:  
  445:             agcfGatewayRecordId = Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord.AgcfGatewayRecordId(Ia.Ngn.Cl.Model.Business.Nokia.AgcfGatewayTable.NgfsAgcfGatewayTableAid, gwId);
  446:             agcfGatewayRecord = nokiaIms.RtrvNgfsAgcfGatewayRecordV2(gwId, out Ia.Ngn.Cl.Model.Business.Nokia.Ims.Response response);
  447:  
  448:             if (response.ResultCode == Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.Successful || response.ResultCode == Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.PlxServiceObjectDoesNotExist)
  449:             {
  450:                 agcfGatewayRecordUpdated = Ia.Ngn.Cl.Model.Data.Nokia.Ims.UpdateAgcfGatewayRecord(gwId, response, agcfGatewayRecord, out r);
  451:  
  452:                 if (!string.IsNullOrEmpty(r)) result += ", UpdateAgcfGatewayRecord: " + r;
  453:  
  454:                 if (agcfGatewayRecord != null)
  455:                 {
  456:                     imsService = Ia.Ngn.Cl.Model.Business.Nokia.Ims.ImsServiceFromAgcfSipIaPort(agcfGatewayRecord.AgcfSipIaPort);
  457:                     primarySwitch = Ia.Ngn.Cl.Model.Business.Nokia.Ims.PrimarySwitchFromAgcfGatewayRecord(agcfGatewayRecord.IsPrimary);
  458:  
  459:                     //if (nddOnt != null) result += " " + nddOnt.Access.Name;
  460:                     //else result += " warning: nddOnt is null for IP: " + agcfGatewayRecord.IP1;
  461:  
  462:                     agcfEndpointList = nokiaIms.RtrvNgfsAgcfEndpointV2List(agcfGatewayRecord.GwId, primarySwitch, imsService, out response);
  463:  
  464:                     if (response.ResultCode == Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.Successful || response.ResultCode == Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.PlxServiceObjectDoesNotExist || response.ResultCode == Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.SuccessfulButNoParameters)
  465:                     {
  466:                         agcfEndpointListUpdated = Ia.Ngn.Cl.Model.Data.Nokia.Ims.UpdateNgfsAgcfEndpointList(gwId, agcfGatewayRecordId, response, agcfEndpointList);
  467:  
  468:                         agcfEndpointList = Ia.Ngn.Cl.Model.Data.Nokia.AgcfEndpoint.List(gwId);
  469:  
  470:                         if (agcfEndpointList != null)
  471:                         {
  472:                             foreach (Ia.Ngn.Cl.Model.Nokia.AgcfEndpoint agcfEndpoint in agcfEndpointList)
  473:                             {
  474:                                 prividUser = agcfEndpoint.PrividUser;
  475:                                 partyId = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.PartyId(prividUser);
  476:  
  477:                                 subParty = nokiaIms.RtrvNgfsSubPartyV2(partyId, primarySwitch, imsService, out response);
  478:  
  479:                                 if (response.ResultCode == Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.Successful || response.ResultCode == Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.PlxServiceObjectDoesNotExist)
  480:                                 {
  481:                                     ngfsSubPartyUpdated = Ia.Ngn.Cl.Model.Data.Nokia.Ims.UpdateNgfsSubParty(partyId, agcfEndpoint.Id, response, subParty);
  482:  
  483:                                     // below: read the SubParty
  484:                                     subPartyId = Ia.Ngn.Cl.Model.Nokia.SubParty.SubPartyId(partyId);
  485:                                     subParty = Ia.Ngn.Cl.Model.Data.Nokia.SubParty.Read(subPartyId);
  486:  
  487:                                     if (subParty != null)
  488:                                     {
  489:                                         subscriber = nokiaIms.RtrvNgfsSubscriberV2(partyId, primarySwitch, imsService, out response);
  490:  
  491:                                         if (response.ResultCode == Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.Successful || response.ResultCode == Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.PlxServiceObjectDoesNotExist)
  492:                                         {
  493:                                             service = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.Service(partyId);
  494:  
  495:                                             ngfsSubscriberUpdated = Ia.Ngn.Cl.Model.Data.Nokia.Ims.UpdateNgfsSubscriber(partyId, subPartyId, response, subscriber);
  496:  
  497:                                             Ia.Ngn.Cl.Model.Data.Nokia.Ims.UpdateServiceFromAgcfGatewayRecordAndAgcfEndpointAndSubPartyAndSubscriber(service, agcfGatewayRecord, agcfEndpoint, subParty, subscriber);
  498:  
  499:                                             result += "," + service;
  500:                                         }
  501:                                         else
  502:                                         {
  503:                                             result += " error: subscriber: " + response.ResultCode.ToString();
  504:                                         }
  505:                                     }
  506:                                     else
  507:                                     {
  508:                                         result += " subParty is null";
  509:                                     }
  510:                                 }
  511:                                 else
  512:                                 {
  513:                                     result += " error: subParty: " + response.ResultCode.ToString();
  514:                                 }
  515:                             }
  516:                         }
  517:                         else
  518:                         {
  519:                             result += " agcfEndpointList is null";
  520:                         }
  521:                     }
  522:                     else
  523:                     {
  524:                         result += " error: agcfEndpointList: " + response.ResultCode.ToString();
  525:                     }
  526:                 }
  527:                 else
  528:                 {
  529:                     result += " agcfGatewayRecord is null";
  530:                 }
  531:             }
  532:             else
  533:             {
  534:                 result += " error: agcfGatewayRecord: " + response.ResultCode.ToString();
  535:             }
  536:  
  537:             // temp
  538:             //Ia.Ngn.Cl.Model.Data.Nokia.Ims.ReadAgcfGatewayRecordFromSkbForGwId(nokiaIms, gwId, out r2);
  539:             //result += ". AgcfGatewayRecord (SKB): " + r2;
  540:         }
  541:  
  542:         ////////////////////////////////////////////////////////////////////////////
  543:  
  544:         /// <summary>
  545:         ///
  546:         /// </summary>
  547:         public static void ReadUpdateSubPartyAndSubscriberAndServiceForService(Ia.Ngn.Cl.Model.Client.Nokia.Ims nokiaIms, string _service, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt, out string result)
  548:         {
  549:             bool updated;
  550:             int imsService;
  551:             string service, primarySwitch, partyId, subPartyId;
  552:             Ia.Ngn.Cl.Model.Nokia.SubParty subParty;
  553:             Ia.Ngn.Cl.Model.Nokia.Subscriber subscriber;
  554:             Ia.Ngn.Cl.Model.Business.Nokia.Ims.Response subPartyResponse, subscriberResponse;
  555:  
  556:             result = string.Empty;
  557:  
  558:             partyId = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.PartyId(_service);
  559:             subPartyId = Ia.Ngn.Cl.Model.Nokia.SubParty.SubPartyId(partyId);
  560:             service = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.Service(partyId);
  561:  
  562:             if (nddOnt != null)
  563:             {
  564:                 imsService = nddOnt.ImsService;
  565:                 primarySwitch = nddOnt.PrimarySwitch;
  566:  
  567:                 subParty = nokiaIms.RtrvNgfsSubPartyV2(subPartyId, primarySwitch, imsService, out subPartyResponse);
  568:                 subscriber = nokiaIms.RtrvNgfsSubscriberV2(partyId, primarySwitch, imsService, out subscriberResponse);
  569:  
  570:                 updated = Ia.Ngn.Cl.Model.Data.Nokia.Ims.UpdateNgfsSubPartyAndNgfsSubscriberWithoutEndPoint(subPartyId, subParty, subPartyResponse, partyId, subscriber, subscriberResponse);
  571:                 Ia.Ngn.Cl.Model.Data.Nokia.Ims.UpdateServiceFromSubPartyAndSubscriber(service, nddOnt.Access.Id);
  572:             }
  573:             else
  574:             {
  575:                 /*
  576:                 foreach (Ia.Ngn.Cl.Model.Business.Nokia.Ims.ImsBasicService ibs in Ia.Ngn.Cl.Model.Business.Nokia.Ims.ImsBasicServiceList)
  577:                 {
  578:                     Ia.Ngn.Cl.Model.Data.Nokia.Ims.ReadSubPartyAndSubscriber(nokiaIms, service, ibs.PrimarySwitch, ibs.Fsdb, ibs.Service, out string r);
  579: 
  580:                     result += r + ",";
  581:                 }
  582:                 */
  583:             }
  584:         }
  585:  
  586:         ////////////////////////////////////////////////////////////////////////////
  587:  
  588:         /// <summary>
  589:         ///
  590:         /// </summary>
  591:         public static void ReadSubPartyAndSubscriber(Ia.Ngn.Cl.Model.Client.Nokia.Ims nokiaIms, string _service, string primarySwitch, string fsdb, int imsService, out string result)
  592:         {
  593:             bool updated;
  594:             string service, partyId, subPartyId;
  595:             Ia.Ngn.Cl.Model.Nokia.SubParty subParty;
  596:             Ia.Ngn.Cl.Model.Nokia.Subscriber subscriber;
  597:             Ia.Ngn.Cl.Model.Business.Nokia.Ims.Response subPartyResponse, subscriberResponse;
  598:  
  599:             result = string.Empty;
  600:  
  601:             partyId = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.PartyId(_service);
  602:             subPartyId = Ia.Ngn.Cl.Model.Nokia.SubParty.SubPartyId(partyId);
  603:             service = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.Service(partyId);
  604:  
  605:             subParty = nokiaIms.RtrvNgfsSubPartyV2(subPartyId, primarySwitch, imsService, out subPartyResponse);
  606:             subscriber = nokiaIms.RtrvNgfsSubscriberV2(partyId, primarySwitch, imsService, out subscriberResponse);
  607:  
  608:             updated = Ia.Ngn.Cl.Model.Data.Nokia.Ims.UpdateNgfsSubPartyAndNgfsSubscriberWithoutEndPoint(subPartyId, subParty, subPartyResponse, partyId, subscriber, subscriberResponse);
  609:             Ia.Ngn.Cl.Model.Data.Nokia.Ims.UpdateServiceFromSubPartyAndSubscriber(service, string.Empty);
  610:         }
  611:  
  612:         ////////////////////////////////////////////////////////////////////////////
  613:  
  614:         /// <summary>
  615:         ///
  616:         /// </summary>
  617:         public static void DeleteAgcfGatewayRecordForGwId(Ia.Ngn.Cl.Model.Client.Nokia.Ims nokiaIms, Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord agcfGatewayRecord, out string result)
  618:         {
  619:             string primarySwitch, secondarySwitch;
  620:  
  621:             primarySwitch = Ia.Ngn.Cl.Model.Business.Nokia.Ims.PrimarySwitchFromAgcfGatewayRecord(agcfGatewayRecord.IsPrimary);
  622:             secondarySwitch = Ia.Ngn.Cl.Model.Business.Nokia.Ims.SecondarySwitchFromAgcfGatewayRecord(agcfGatewayRecord.IsPrimary);
  623:  
  624:             nokiaIms.DltNgfsAgcfGwCombinedRecV2(agcfGatewayRecord.GwId, primarySwitch, out Ia.Ngn.Cl.Model.Business.Nokia.Ims.Response primarySwitchDeleteResponse);
  625:             nokiaIms.DltNgfsAgcfGwCombinedRecV2(agcfGatewayRecord.GwId, secondarySwitch, out Ia.Ngn.Cl.Model.Business.Nokia.Ims.Response secondarySwitchDeleteResponse);
  626:  
  627:             result = "Primary: " + primarySwitchDeleteResponse.ResultCode.ToString() + " (FailureReason: " + primarySwitchDeleteResponse.FailureReason.ToString() + "), Secondary: " + secondarySwitchDeleteResponse.ResultCode.ToString() + " (FailureReason: " + secondarySwitchDeleteResponse.FailureReason.ToString() + "). ";
  628:         }
  629:  
  630:         ////////////////////////////////////////////////////////////////////////////
  631:  
  632:         /// <summary>
  633:         ///
  634:         /// </summary>
  635:         public static void DeleteAgcfGatewayRecordForGwId(Ia.Ngn.Cl.Model.Client.Nokia.Ims nokiaIms, int gwId, out string result)
  636:         {
  637:             string firstSwitch, secondSwitch;
  638:  
  639:             firstSwitch = Ia.Ngn.Cl.Model.Business.Nokia.Ims.TEC;
  640:             secondSwitch = Ia.Ngn.Cl.Model.Business.Nokia.Ims.SKB;
  641:  
  642:             nokiaIms.DltNgfsAgcfGwCombinedRecV2(gwId, firstSwitch, out Ia.Ngn.Cl.Model.Business.Nokia.Ims.Response primarySwitchDeleteResponse);
  643:             nokiaIms.DltNgfsAgcfGwCombinedRecV2(gwId, secondSwitch, out Ia.Ngn.Cl.Model.Business.Nokia.Ims.Response secondarySwitchDeleteResponse);
  644:  
  645:             result = "First: " + primarySwitchDeleteResponse.ResultCode.ToString() + ", Second: " + secondarySwitchDeleteResponse.ResultCode.ToString() + ". ";
  646:         }
  647:  
  648:         /*
  649:         ////////////////////////////////////////////////////////////////////////////
  650: 
  651:         /// <summary>
  652:         ///
  653:         /// </summary>
  654:         public static void ReadAgcfEndpointAndSubPartyAndSubscriberForService(Ia.Ngn.Cl.Model.Client.Nokia.Ims ims, int gwId, string service, out string result)
  655:         {
  656:             bool ngfsSubPartyUpdated, ngfsSubscriberUpdated;
  657:             int imsService;
  658:             string primarySwitch, partyId, prividUser, subPartyId;
  659:             Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt;
  660:             Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord agcfGatewayRecord;
  661:             Ia.Ngn.Cl.Model.Nokia.AgcfEndpoint agcfEndpoint;
  662:             Ia.Ngn.Cl.Model.Nokia.SubParty subParty;
  663:             Ia.Ngn.Cl.Model.Nokia.Subscriber subscriber;
  664:             Ia.Ngn.Cl.Model.Business.Nokia.Ims.Response response;
  665: 
  666:             result = "service: " + service + ", gwId: " + gwId;
  667: 
  668:             prividUser = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.PrividUser(service);
  669:             partyId = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.PartyId(service);
  670: 
  671:             Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord agcfGatewayRecord;
  672: 
  673:             agcfEndpoint = ims.RtrvNgfsAgcfEndpointV2(prividUser, primarySwitch, imsService, out response);
  674: 
  675:             if (response.ResultCode == Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.Successful || response.ResultCode == Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.PLX_SERVICE_OBJECT_DOES_NOT_EXIST || response.ResultCode == Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.SuccessfulButNoParameters)
  676:             {
  677:                 agcfEndpoint = Ia.Ngn.Cl.Model.Data.Nokia.AgcfEndpoint.Read(prividUser);
  678: 
  679:                 if (agcfEndpoint != null)
  680:                 {
  681:                     nddOnt = (from q in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList where q.Ip == agcfEndpoint.AgcfGatewayRecord.IP1 select q).SingleOrDefault();
  682:                     imsService = Ia.Ngn.Cl.Model.Business.Nokia.Ims.ImsServiceFromAgcfSipIaPort(agcfEndpoint.AgcfGatewayRecord.AgcfSipIaPort);
  683:                     primarySwitch = Ia.Ngn.Cl.Model.Business.Nokia.Ims.PrimarySwitchFromAgcfGatewayRecord(agcfEndpoint.AgcfGatewayRecord.IsPrimary);
  684: 
  685:                     if (nddOnt != null) result += " " + nddOnt.Access.Name;
  686:                     else result += " warning: nddOnt is null for IP: " + agcfEndpoint.AgcfGatewayRecord.IP1;
  687: 
  688:                     subParty = ims.RtrvNgfsSubPartyV2(partyId, primarySwitch, imsService, out response);
  689: 
  690:                     if (response.ResultCode == Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.Successful || response.ResultCode == Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.PLX_SERVICE_OBJECT_DOES_NOT_EXIST)
  691:                     {
  692:                         ngfsSubPartyUpdated = Ia.Ngn.Cl.Model.Data.Nokia.Ims.UpdateNgfsSubParty(partyId, agcfEndpoint.Id, response, subParty);
  693: 
  694:                         // below: read the SubParty
  695:                         subPartyId = Ia.Ngn.Cl.Model.Nokia.SubParty.SubPartyId(partyId);
  696:                         subParty = Ia.Ngn.Cl.Model.Nokia.SubParty.Read(subPartyId);
  697: 
  698:                         if (subParty != null)
  699:                         {
  700:                             subscriber = ims.RtrvNgfsSubscriberV2(partyId, primarySwitch, imsService, out response);
  701: 
  702:                             if (response.ResultCode == Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.Successful || response.ResultCode == Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.PLX_SERVICE_OBJECT_DOES_NOT_EXIST)
  703:                             {
  704:                                 service = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.Service(partyId);
  705: 
  706:                                 ngfsSubscriberUpdated = Ia.Ngn.Cl.Model.Data.Nokia.Ims.UpdateNgfsSubscriber(partyId, subPartyId, response, subscriber);
  707: 
  708:                                 Ia.Ngn.Cl.Model.Data.Nokia.Ims.UpdateServiceFromAgcfEndpointAndSubPartyAndSubscriber(service, agcfEndpoint, subParty, subscriber);
  709: 
  710:                                 result += "," + service;
  711:                             }
  712:                             else
  713:                             {
  714:                                 result += " error: subscriber: " + response.ResultCode.ToString();
  715:                             }
  716:                         }
  717:                         else
  718:                         {
  719:                             result += " subParty is null";
  720:                         }
  721:                     }
  722:                     else
  723:                     {
  724:                         result += " error: subParty: " + response.ResultCode.ToString();
  725:                     }
  726:                 }
  727:                 else
  728:                 {
  729:                     result += " agcfEndpoint is null";
  730:                 }
  731:             }
  732:             else
  733:             {
  734:                 result += " error: agcfEndpointList: " + response.ResultCode.ToString();
  735:             }
  736:         }
  737:         */
  738:  
  739:         ////////////////////////////////////////////////////////////////////////////
  740:  
  741:         /// <summary>
  742:         ///
  743:         /// </summary>
  744:         public static bool UpdateAgcfGatewayRecord(int gwId, Ia.Ngn.Cl.Model.Business.Nokia.Ims.Response response, Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord newAgcfGatewayRecord, out string result)
  745:         {
  746:             bool updated;
  747:             int id, tableId;
  748:             Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord agcfGatewayRecord;
  749:  
  750:             tableId = Ia.Ngn.Cl.Model.Business.Nokia.AgcfGatewayTable.NgfsAgcfGatewayTableAid;
  751:  
  752:             result = string.Empty;
  753:  
  754:             using (var db = new Ia.Ngn.Cl.Model.Ngn())
  755:             {
  756:                 id = Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord.AgcfGatewayRecordId(tableId, gwId);
  757:  
  758:                 agcfGatewayRecord = (from gr in db.AgcfGatewayRecords where gr.Id == id select gr).Include(gr => gr.AgcfEndpoints).SingleOrDefault();
  759:  
  760:                 switch (response.ResultCode)
  761:                 {
  762:                     case Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.Successful:
  763:                         {
  764:                             if (agcfGatewayRecord == null)
  765:                             {
  766:                                 newAgcfGatewayRecord.Created = newAgcfGatewayRecord.Updated = DateTime.UtcNow.AddHours(3);
  767:                                 db.AgcfGatewayRecords.Add(newAgcfGatewayRecord);
  768:  
  769:                                 updated = true;
  770:                             }
  771:                             else
  772:                             {
  773:                                 if (agcfGatewayRecord.Update(newAgcfGatewayRecord))
  774:                                 {
  775:                                     db.AgcfGatewayRecords.Attach(agcfGatewayRecord);
  776:                                     db.Entry(agcfGatewayRecord).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
  777:  
  778:                                     updated = true;
  779:                                 }
  780:                                 else updated = false;
  781:                             }
  782:  
  783:                             break;
  784:                         }
  785:                     case Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.PlxServiceObjectDoesNotExist:
  786:                         {
  787:                             if (agcfGatewayRecord != null)
  788:                             {
  789:                                 // below: delete if foreign key is not null or zero
  790:                                 if (agcfGatewayRecord.AgcfEndpoints == null || agcfGatewayRecord.AgcfEndpoints.Count == 0)
  791:                                 {
  792:                                     db.AgcfGatewayRecords.Remove(agcfGatewayRecord);
  793:  
  794:                                     updated = true;
  795:                                 }
  796:                                 else
  797:                                 {
  798:                                     updated = false;
  799:  
  800:                                     result = "AGCF gateway record for GwId " + gwId + " does not exist in IMS, but agcfGatewayRecord.AgcfEndpoints != null && agcfGatewayRecord.AgcfEndpoints.Count > 0. ";
  801:                                 }
  802:                             }
  803:                             else updated = false;
  804:  
  805:                             break;
  806:                         }
  807:                     default: updated = false; break;
  808:                 }
  809:  
  810:                 db.SaveChanges();
  811:             }
  812:  
  813:             return updated;
  814:         }
  815:  
  816:         ////////////////////////////////////////////////////////////////////////////
  817:  
  818:         /// <summary>
  819:         ///
  820:         /// </summary>
  821:         public static bool UpdateNgfsAgcfEndpoint(string prividUser, Ia.Ngn.Cl.Model.Business.Nokia.Ims.Response response, Ia.Ngn.Cl.Model.Nokia.AgcfEndpoint newAgcfEndpoint)
  822:         {
  823:             bool isOk;
  824:             int agcfGatewayRecordsId;
  825:             string id;
  826:             Ia.Ngn.Cl.Model.Nokia.AgcfEndpoint agcfEndpoint;
  827:  
  828:             isOk = false;
  829:  
  830:             using (var db = new Ia.Ngn.Cl.Model.Ngn())
  831:             {
  832:                 id = Ia.Ngn.Cl.Model.Nokia.AgcfEndpoint.AgcfEndpointId(prividUser);
  833:  
  834:                 agcfEndpoint = (from ep in db.AgcfEndpoints where ep.Id == id select ep).SingleOrDefault();
  835:  
  836:                 switch (response.ResultCode)
  837:                 {
  838:                     case Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.Successful:
  839:                         {
  840:                             if (agcfEndpoint == null)
  841:                             {
  842:                                 newAgcfEndpoint.Created = newAgcfEndpoint.Updated = DateTime.UtcNow.AddHours(3);
  843:                                 db.AgcfEndpoints.Add(newAgcfEndpoint);
  844:                             }
  845:                             else
  846:                             {
  847:                                 // below: reference
  848:                                 agcfGatewayRecordsId = Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord.AgcfGatewayRecordId(Ia.Ngn.Cl.Model.Business.Nokia.AgcfGatewayTable.NgfsAgcfGatewayTableAid, newAgcfEndpoint.GwId);
  849:                                 newAgcfEndpoint.AgcfGatewayRecord = (from gr in db.AgcfGatewayRecords where gr.Id == agcfGatewayRecordsId select gr).SingleOrDefault();
  850:  
  851:                                 if (agcfEndpoint.Update(newAgcfEndpoint))
  852:                                 {
  853:                                     db.AgcfEndpoints.Attach(agcfEndpoint);
  854:                                     db.Entry(agcfEndpoint).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
  855:                                 }
  856:                             }
  857:  
  858:                             break;
  859:                         }
  860:                     case Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.PlxServiceObjectDoesNotExist:
  861:                         {
  862:                             if (agcfEndpoint != null)
  863:                             {
  864:                                 // below: skip delete if the foreign key is not null
  865:                                 if (agcfEndpoint.SubParties == null)
  866:                                 {
  867:                                     db.AgcfEndpoints.Remove(agcfEndpoint);
  868:                                 }
  869:                             }
  870:                             break;
  871:                         }
  872:                 }
  873:  
  874:                 db.SaveChanges();
  875:  
  876:                 isOk = true;
  877:             }
  878:  
  879:             return isOk;
  880:         }
  881:  
  882:         ////////////////////////////////////////////////////////////////////////////
  883:  
  884:         /// <summary>
  885:         ///
  886:         /// </summary>
  887:         public static bool UpdateNgfsAgcfEndpointList(int gwId, int agcfGatewayRecordId, Ia.Ngn.Cl.Model.Business.Nokia.Ims.Response response, List<Ia.Ngn.Cl.Model.Nokia.AgcfEndpoint> newAgcfEndpointList)
  888:         {
  889:             bool updated;
  890:             Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord agcfGatewayRecord;
  891:             Ia.Ngn.Cl.Model.Nokia.AgcfEndpoint agcfEndpoint;
  892:             List<Ia.Ngn.Cl.Model.Nokia.AgcfEndpoint> agcfEndpointList;
  893:  
  894:             updated = false;
  895:  
  896:             using (var db = new Ia.Ngn.Cl.Model.Ngn())
  897:             {
  898:                 agcfEndpointList = (from ep in db.AgcfEndpoints where ep.GwId == gwId select ep).Include(ep => ep.SubParties).ToList();
  899:  
  900:                 switch (response.ResultCode)
  901:                 {
  902:                     case Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.Successful:
  903:                         {
  904:                             // below: add or update read endpoints
  905:                             foreach (Ia.Ngn.Cl.Model.Nokia.AgcfEndpoint newAgcfEndpoint in newAgcfEndpointList)
  906:                             {
  907:                                 // below: reference
  908:                                 agcfGatewayRecord = (from gr in db.AgcfGatewayRecords where gr.Id == agcfGatewayRecordId select gr).SingleOrDefault();
  909:                                 agcfEndpoint = (from ep in db.AgcfEndpoints where ep.Id == newAgcfEndpoint.Id select ep).SingleOrDefault();
  910:                                 newAgcfEndpoint.AgcfGatewayRecord = agcfGatewayRecord;
  911:  
  912:                                 if (agcfEndpoint == null)
  913:                                 {
  914:                                     newAgcfEndpoint.Created = newAgcfEndpoint.Updated = DateTime.UtcNow.AddHours(3);
  915:                                     db.AgcfEndpoints.Add(newAgcfEndpoint);
  916:  
  917:                                     updated = updated || true;
  918:                                 }
  919:                                 else
  920:                                 {
  921:                                     if (agcfEndpoint.Update(newAgcfEndpoint))
  922:                                     {
  923:                                         db.AgcfEndpoints.Attach(agcfEndpoint);
  924:                                         db.Entry(agcfEndpoint).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
  925:  
  926:                                         updated = updated || true;
  927:                                     }
  928:                                     else updated = updated || false;
  929:                                 }
  930:                             }
  931:  
  932:                             // below: remove stored endpoint that do not exist in read
  933:                             if (agcfEndpointList != null && agcfEndpointList.Count > 0)
  934:                             {
  935:                                 foreach (Ia.Ngn.Cl.Model.Nokia.AgcfEndpoint storedAgcfEndpoint in agcfEndpointList)
  936:                                 {
  937:                                     agcfEndpoint = (from a in newAgcfEndpointList where a.Id == storedAgcfEndpoint.Id select a).SingleOrDefault();
  938:  
  939:                                     if (agcfEndpoint == null && (storedAgcfEndpoint.SubParties == null || storedAgcfEndpoint.SubParties.Count == 0))
  940:                                     {
  941:                                         db.AgcfEndpoints.Remove(storedAgcfEndpoint);
  942:  
  943:                                         updated = updated || true;
  944:                                     }
  945:                                 }
  946:                             }
  947:  
  948:                             break;
  949:                         }
  950:                     case Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.SuccessfulButNoParameters:
  951:                     case Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.PlxServiceObjectDoesNotExist:
  952:                         {
  953:                             if (agcfEndpointList != null && agcfEndpointList.Count > 0)
  954:                             {
  955:                                 foreach (Ia.Ngn.Cl.Model.Nokia.AgcfEndpoint deletedAgcfEndpoint in agcfEndpointList)
  956:                                 {
  957:                                     // below: delete if foreign key is not null or zero
  958:                                     if (deletedAgcfEndpoint.SubParties == null || deletedAgcfEndpoint.SubParties.Count == 0)
  959:                                     {
  960:                                         db.AgcfEndpoints.Remove(deletedAgcfEndpoint);
  961:  
  962:                                         updated = updated || true;
  963:                                     }
  964:                                     else updated = updated || false;
  965:  
  966:                                 }
  967:                             }
  968:                             break;
  969:                         }
  970:                     default: updated = updated || false; break;
  971:                 }
  972:  
  973:                 db.SaveChanges();
  974:             }
  975:  
  976:             return updated;
  977:         }
  978:  
  979:         ////////////////////////////////////////////////////////////////////////////
  980:  
  981:         /// <summary>
  982:         ///
  983:         /// </summary>
  984:         public static bool UpdateNgfsSubParty(string partyId, string agcfEndpointId, Ia.Ngn.Cl.Model.Business.Nokia.Ims.Response response, Ia.Ngn.Cl.Model.Nokia.SubParty newSubParty)
  985:         {
  986:             bool updated;
  987:             string id;
  988:             Ia.Ngn.Cl.Model.Nokia.SubParty subParty;
  989:  
  990:             using (var db = new Ia.Ngn.Cl.Model.Ngn())
  991:             {
  992:                 id = Ia.Ngn.Cl.Model.Nokia.SubParty.SubPartyId(partyId);
  993:  
  994:                 subParty = (from sp in db.SubParties where sp.Id == id select sp).Include(sp => sp.Subscribers).SingleOrDefault();
  995:  
  996:                 switch (response.ResultCode)
  997:                 {
  998:                     case Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.Successful:
  999:                         {
 1000:                             // below: reference
 1001:                             agcfEndpointId = Ia.Ngn.Cl.Model.Nokia.AgcfEndpoint.AgcfEndpointId(agcfEndpointId);
 1002:                             newSubParty.AgcfEndpoint = (from ep in db.AgcfEndpoints where ep.Id == agcfEndpointId select ep).SingleOrDefault();
 1003:  
 1004:                             if (subParty == null)
 1005:                             {
 1006:                                 newSubParty.Created = newSubParty.Updated = DateTime.UtcNow.AddHours(3);
 1007:                                 db.SubParties.Add(newSubParty);
 1008:  
 1009:                                 updated = true;
 1010:                             }
 1011:                             else
 1012:                             {
 1013:                                 // below: they don't
 1014:                                 // <PrimaryPUID>icsSubAgcfpuid</PrimaryPUID> in <SubParty> element of ent-ngfs-subscriber-v2 has to match <Dn>icsSubAgcfpuid</Dn> in ent-ngfs-agcfendpoint-v2
 1015:  
 1016:                                 if (subParty.Update(newSubParty))
 1017:                                 {
 1018:                                     db.SubParties.Attach(subParty);
 1019:                                     db.Entry(subParty).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
 1020:  
 1021:                                     updated = true;
 1022:                                 }
 1023:                                 else updated = false;
 1024:                             }
 1025:  
 1026:                             break;
 1027:                         }
 1028:                     case Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.PlxServiceObjectDoesNotExist:
 1029:                         {
 1030:                             if (subParty != null)
 1031:                             {
 1032:                                 // below: delete if foreign key is not null or zero
 1033:                                 if (subParty.Subscribers == null || subParty.Subscribers.Count == 0)
 1034:                                 {
 1035:                                     db.SubParties.Remove(subParty);
 1036:  
 1037:                                     updated = true;
 1038:                                 }
 1039:                                 else updated = false;
 1040:                             }
 1041:                             else updated = false;
 1042:                             break;
 1043:                         }
 1044:                     default: updated = false; break;
 1045:                 }
 1046:  
 1047:                 db.SaveChanges();
 1048:             }
 1049:  
 1050:             return updated;
 1051:         }
 1052:  
 1053:         ////////////////////////////////////////////////////////////////////////////
 1054:  
 1055:         /// <summary>
 1056:         ///
 1057:         /// </summary>
 1058:         public static bool UpdateNgfsSubPartyAndNgfsSubscriberWithoutEndPoint(string subPartyId, Ia.Ngn.Cl.Model.Nokia.SubParty retrievedSubParty, Ia.Ngn.Cl.Model.Business.Nokia.Ims.Response retrievedSubPartyResponse, string partyId, Ia.Ngn.Cl.Model.Nokia.Subscriber retrievedSubscriber, Ia.Ngn.Cl.Model.Business.Nokia.Ims.Response retrievedSubscriberResponse)
 1059:         {
 1060:             bool updated;
 1061:             Ia.Ngn.Cl.Model.Nokia.SubParty subParty;
 1062:             Ia.Ngn.Cl.Model.Nokia.Subscriber subscriber;
 1063:  
 1064:             updated = false;
 1065:  
 1066:             using (var db = new Ia.Ngn.Cl.Model.Ngn())
 1067:             {
 1068:                 subParty = (from sp in db.SubParties where sp.Id == subPartyId select sp).SingleOrDefault();
 1069:                 subscriber = (from s in db.Subscribers where s.Id == partyId select s).SingleOrDefault();
 1070:  
 1071:                 if (retrievedSubParty != null && retrievedSubPartyResponse.ResultCode == Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.Successful && retrievedSubscriber != null && retrievedSubscriberResponse.ResultCode == Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.Successful)
 1072:                 {
 1073:                     if (subParty == null)
 1074:                     {
 1075:                         retrievedSubParty.Created = retrievedSubParty.Updated = DateTime.UtcNow.AddHours(3);
 1076:                         db.SubParties.Add(retrievedSubParty);
 1077:  
 1078:                         updated = true;
 1079:                     }
 1080:                     else
 1081:                     {
 1082:                         if (subParty.Update(retrievedSubParty))
 1083:                         {
 1084:                             db.SubParties.Attach(subParty);
 1085:                             db.Entry(subParty).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
 1086:  
 1087:                             updated = true;
 1088:                         }
 1089:                     }
 1090:  
 1091:                     // below: reference
 1092:                     retrievedSubscriber.SubParty = (from sp in db.SubParties where sp.Id == retrievedSubParty.Id select sp).SingleOrDefault();
 1093:  
 1094:                     if (subscriber == null)
 1095:                     {
 1096:                         retrievedSubscriber.Created = retrievedSubscriber.Updated = DateTime.UtcNow.AddHours(3);
 1097:                         db.Subscribers.Add(retrievedSubscriber);
 1098:  
 1099:                         updated = true;
 1100:                     }
 1101:                     else
 1102:                     {
 1103:                         if (subscriber.Update(retrievedSubscriber))
 1104:                         {
 1105:                             db.Subscribers.Attach(subscriber);
 1106:                             db.Entry(subscriber).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
 1107:  
 1108:                             updated = true;
 1109:                         }
 1110:                     }
 1111:                 }
 1112:                 else if (retrievedSubParty == null && retrievedSubPartyResponse.ResultCode == Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.PlxServiceObjectDoesNotExist && retrievedSubscriber == null && retrievedSubscriberResponse.ResultCode == Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.PlxServiceObjectDoesNotExist)
 1113:                 {
 1114:                     if (subscriber != null)
 1115:                     {
 1116:                         db.Subscribers.Remove(subscriber);
 1117:  
 1118:                         updated = true;
 1119:                     }
 1120:  
 1121:                     if (subParty != null)
 1122:                     {
 1123:                         db.SubParties.Remove(subParty);
 1124:  
 1125:                         updated = true;
 1126:                     }
 1127:                 }
 1128:                 else
 1129:                 {
 1130:  
 1131:                 }
 1132:  
 1133:                 db.SaveChanges();
 1134:             }
 1135:  
 1136:             return updated;
 1137:         }
 1138:  
 1139:         ////////////////////////////////////////////////////////////////////////////
 1140:  
 1141:         /// <summary>
 1142:         ///
 1143:         /// </summary>
 1144:         public static bool UpdateNgfsSubscriber(string partyId, string subPartyId, Ia.Ngn.Cl.Model.Business.Nokia.Ims.Response response, Ia.Ngn.Cl.Model.Nokia.Subscriber newSubscriber)
 1145:         {
 1146:             bool updated;
 1147:             string id;
 1148:             Ia.Ngn.Cl.Model.Nokia.Subscriber subscriber;
 1149:  
 1150:             using (var db = new Ia.Ngn.Cl.Model.Ngn())
 1151:             {
 1152:                 id = Ia.Ngn.Cl.Model.Nokia.Subscriber.SubscriberId(partyId);
 1153:  
 1154:                 subscriber = (from s in db.Subscribers where s.Id == id select s).SingleOrDefault();
 1155:  
 1156:                 switch (response.ResultCode)
 1157:                 {
 1158:                     case Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.Successful:
 1159:                         {
 1160:                             // below: reference
 1161:                             newSubscriber.SubParty = (from s in db.SubParties where s.Id == subPartyId select s).SingleOrDefault();
 1162:  
 1163:                             if (subscriber == null)
 1164:                             {
 1165:                                 newSubscriber.Created = newSubscriber.Updated = DateTime.UtcNow.AddHours(3);
 1166:                                 db.Subscribers.Add(newSubscriber);
 1167:  
 1168:                                 updated = true;
 1169:                             }
 1170:                             else
 1171:                             {
 1172:                                 if (subscriber.Update(newSubscriber))
 1173:                                 {
 1174:                                     db.Subscribers.Attach(subscriber);
 1175:                                     db.Entry(subscriber).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
 1176:  
 1177:                                     updated = true;
 1178:                                 }
 1179:                                 else updated = false;
 1180:                             }
 1181:  
 1182:                             break;
 1183:                         }
 1184:                     case Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.PlxServiceObjectDoesNotExist:
 1185:                         {
 1186:                             if (subscriber != null)
 1187:                             {
 1188:                                 db.Subscribers.Remove(subscriber);
 1189:  
 1190:                                 updated = true;
 1191:                             }
 1192:                             else updated = false;
 1193:  
 1194:                             break;
 1195:                         }
 1196:                     default: updated = false; break;
 1197:                 }
 1198:  
 1199:                 db.SaveChanges();
 1200:             }
 1201:  
 1202:             return updated;
 1203:         }
 1204:  
 1205:         ////////////////////////////////////////////////////////////////////////////
 1206:  
 1207:         /// <summary>
 1208:         ///
 1209:         /// </summary>
 1210:         public static bool UpdateServiceFromAgcfGatewayRecordAndAgcfEndpointAndSubPartyAndSubscriber(string service, Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord agcfGatewayRecord, Ia.Ngn.Cl.Model.Nokia.AgcfEndpoint agcfEndpoint, Ia.Ngn.Cl.Model.Nokia.SubParty subParty, Ia.Ngn.Cl.Model.Nokia.Subscriber subscriber)
 1211:         {
 1212:             bool insert, update, delete;
 1213:             int serviceType;
 1214:             string serviceId;
 1215:             Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt;
 1216:             Ia.Ngn.Cl.Model.Service2 service2, newService;
 1217:  
 1218:             insert = update = delete = false;
 1219:             //result = new Ia.Cl.Model.Result();
 1220:  
 1221:             serviceType = Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService;
 1222:             serviceId = Ia.Ngn.Cl.Model.Business.Service2.ServiceId(service, serviceType);
 1223:  
 1224:             using (var db = new Ia.Ngn.Cl.Model.Ngn())
 1225:             {
 1226:                 if (agcfGatewayRecord != null && agcfEndpoint != null && subParty != null && subscriber != null)
 1227:                 {
 1228:                     newService = new Ia.Ngn.Cl.Model.Service2();
 1229:  
 1230:                     newService.Id = serviceId;
 1231:                     newService.AreaCode = Ia.Ngn.Cl.Model.Business.Service.CountryCode;
 1232:                     newService.Service = service;
 1233:                     newService.ServiceType = serviceType;
 1234:  
 1235:                     newService.CallerId = Ia.Ngn.Cl.Model.Business.Nokia.Subscriber.CallingLineIdIsAssigned(subscriber._CallingLineId);
 1236:                     newService.AbbriviatedCalling = Ia.Ngn.Cl.Model.Business.Nokia.Subscriber.OneDigitSpeedDialIsAssigned(subscriber._OneDigitSpeedDial);
 1237:                     newService.CallForwarding = Ia.Ngn.Cl.Model.Business.Nokia.Subscriber.CallForwardingIsAssigned(subscriber._CallForwardingVari);
 1238:                     newService.CallWaiting = Ia.Ngn.Cl.Model.Business.Nokia.Subscriber.CallWaitingIsAssigned(subscriber._CallWaiting, agcfEndpoint.CallWaitingLc);
 1239:                     newService.ConferenceCall = Ia.Ngn.Cl.Model.Business.Nokia.Subscriber.ConferenceCallIsAssigned(subscriber._ConferenceCalling);
 1240:                     newService.InternationalCalling = Ia.Ngn.Cl.Model.Business.Nokia.Subscriber.InternationalCallingIsAssigned(subscriber._CallBarring);
 1241:                     newService.InternationalCallingUserControlled = Ia.Ngn.Cl.Model.Business.Nokia.Subscriber.InternationalCallingUserControlledIsAssigned(subscriber._OutgoingCallBarring);
 1242:  
 1243:                     newService.AlarmCall = Ia.Ngn.Cl.Model.Business.Nokia.Subscriber.ReminderCallIsAssigned(subscriber._ReminderCall);
 1244:                     newService.WakeupCall = Ia.Ngn.Cl.Model.Business.Nokia.Subscriber.ReminderCallIsAssigned(subscriber._ReminderCall);
 1245:  
 1246:                     newService.ServiceSuspension = subParty.ServiceSuspension;
 1247:                     //newService.CallBarring = subParty.ServiceSuspension;
 1248:  
 1249:                     newService.Pin = int.TryParse(subParty.Pin, out int i) ? i : 0;
 1250:  
 1251:                     nddOnt = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntIpToOntDictionary.ContainsKey(agcfGatewayRecord.IP1) ? Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntIpToOntDictionary[agcfGatewayRecord.IP1] : null;
 1252:  
 1253:                     if (nddOnt != null) newService.Access = (from a in db.Accesses where a.Id == nddOnt.Access.Id select a).SingleOrDefault();
 1254:                     else newService.Access = null;
 1255:  
 1256:                     service2 = (from s in db.Service2
 1257:                                 where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && s.Id == newService.Id
 1258:                                 select s).SingleOrDefault();
 1259:  
 1260:                     if (service2 == null)
 1261:                     {
 1262:                         newService.Created = newService.Updated = DateTime.UtcNow.AddHours(3);
 1263:                         db.Service2.Add(newService);
 1264:  
 1265:                         insert = true;
 1266:                     }
 1267:                     else
 1268:                     {
 1269:                         if (service2.Update(newService))
 1270:                         {
 1271:                             db.Service2.Attach(service2);
 1272:                             db.Entry(service2).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
 1273:  
 1274:                             update = true;
 1275:                         }
 1276:                         else update = false;
 1277:                     }
 1278:                 }
 1279:                 else
 1280:                 {
 1281:                     service2 = (from s in db.Service2
 1282:                                 where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && s.Id == serviceId
 1283:                                 select s).SingleOrDefault();
 1284:  
 1285:                     if (service2 != null)
 1286:                     {
 1287:                         db.Service2.Remove(service2);
 1288:  
 1289:                         delete = true;
 1290:                     }
 1291:                 }
 1292:  
 1293:                 db.SaveChanges();
 1294:             }
 1295:  
 1296:             //result.AddSuccess(service + ": state: " + Ia.Ngn.Cl.Model.Ui.Text.ExpressionOfInsertOrUpdateOrDelete(insert, update, delete));
 1297:  
 1298:             return insert || update || delete;
 1299:         }
 1300:  
 1301:         ////////////////////////////////////////////////////////////////////////////
 1302:  
 1303:         /// <summary>
 1304:         ///
 1305:         /// </summary>
 1306:         public static bool UpdateServiceFromSubPartyAndSubscriber(string service, string accessId)
 1307:         {
 1308:             bool insert, update, delete;
 1309:             int serviceType;
 1310:             string serviceId;
 1311:             Ia.Ngn.Cl.Model.Nokia.SubParty subParty;
 1312:             Ia.Ngn.Cl.Model.Nokia.Subscriber subscriber;
 1313:             Ia.Ngn.Cl.Model.Service2 service2, newService;
 1314:  
 1315:             insert = update = delete = false;
 1316:             //result = new Ia.Cl.Model.Result();
 1317:  
 1318:             serviceType = Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService;
 1319:             serviceId = Ia.Ngn.Cl.Model.Business.Service2.ServiceId(service, serviceType);
 1320:  
 1321:             using (var db = new Ia.Ngn.Cl.Model.Ngn())
 1322:             {
 1323:                 var partyId = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.PartyId(service);
 1324:                 var subPartyId = Ia.Ngn.Cl.Model.Nokia.SubParty.SubPartyId(partyId);
 1325:  
 1326:                 subParty = (from sp in db.SubParties where sp.Id == subPartyId select sp).SingleOrDefault();
 1327:                 subscriber = (from s in db.Subscribers where s.Id == partyId select s).SingleOrDefault();
 1328:  
 1329:                 if (subParty != null && subscriber != null)
 1330:                 {
 1331:                     newService = new Ia.Ngn.Cl.Model.Service2();
 1332:  
 1333:                     newService.Id = serviceId;
 1334:                     newService.AreaCode = Ia.Ngn.Cl.Model.Business.Service.CountryCode;
 1335:                     newService.Service = service;
 1336:                     newService.ServiceType = serviceType;
 1337:  
 1338:                     newService.CallerId = Ia.Ngn.Cl.Model.Business.Nokia.Subscriber.CallingLineIdIsAssigned(subscriber._CallingLineId);
 1339:                     newService.AbbriviatedCalling = Ia.Ngn.Cl.Model.Business.Nokia.Subscriber.OneDigitSpeedDialIsAssigned(subscriber._OneDigitSpeedDial);
 1340:                     newService.CallForwarding = Ia.Ngn.Cl.Model.Business.Nokia.Subscriber.CallForwardingIsAssigned(subscriber._CallForwardingVari);
 1341:                     newService.CallWaiting = Ia.Ngn.Cl.Model.Business.Nokia.Subscriber.CallWaitingIsAssigned(subscriber._CallWaiting, false);// agcfEndpoint.CallWaitingLc);
 1342:                     newService.ConferenceCall = Ia.Ngn.Cl.Model.Business.Nokia.Subscriber.ConferenceCallIsAssigned(subscriber._ConferenceCalling);
 1343:                     newService.InternationalCalling = Ia.Ngn.Cl.Model.Business.Nokia.Subscriber.InternationalCallingIsAssigned(subscriber._CallBarring);
 1344:                     newService.InternationalCallingUserControlled = Ia.Ngn.Cl.Model.Business.Nokia.Subscriber.InternationalCallingUserControlledIsAssigned(subscriber._OutgoingCallBarring);
 1345:  
 1346:                     newService.AlarmCall = Ia.Ngn.Cl.Model.Business.Nokia.Subscriber.ReminderCallIsAssigned(subscriber._ReminderCall);
 1347:                     newService.WakeupCall = Ia.Ngn.Cl.Model.Business.Nokia.Subscriber.ReminderCallIsAssigned(subscriber._ReminderCall);
 1348:  
 1349:                     newService.ServiceSuspension = subParty.ServiceSuspension;
 1350:                     //newService.CallBarring = subParty.ServiceSuspension;
 1351:  
 1352:                     newService.Pin = int.TryParse(subParty.Pin, out int i) ? i : 0;
 1353:  
 1354:                     if (!string.IsNullOrEmpty(accessId)) newService.Access = (from a in db.Accesses where a.Id == accessId select a).SingleOrDefault();
 1355:                     else newService.Access = null;
 1356:  
 1357:                     service2 = (from s in db.Service2
 1358:                                 where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && s.Id == newService.Id
 1359:                                 select s).SingleOrDefault();
 1360:  
 1361:                     if (service2 == null)
 1362:                     {
 1363:                         newService.Created = newService.Updated = DateTime.UtcNow.AddHours(3);
 1364:                         db.Service2.Add(newService);
 1365:  
 1366:                         insert = true;
 1367:                     }
 1368:                     else
 1369:                     {
 1370:                         if (service2.Update(newService))
 1371:                         {
 1372:                             db.Service2.Attach(service2);
 1373:                             db.Entry(service2).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
 1374:  
 1375:                             update = true;
 1376:                         }
 1377:                         else update = false;
 1378:                     }
 1379:                 }
 1380:                 else
 1381:                 {
 1382:                     service2 = (from s in db.Service2
 1383:                                 where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && s.Id == serviceId
 1384:                                 select s).SingleOrDefault();
 1385:  
 1386:                     if (service2 != null)
 1387:                     {
 1388:                         db.Service2.Remove(service2);
 1389:  
 1390:                         delete = true;
 1391:                     }
 1392:                 }
 1393:  
 1394:                 db.SaveChanges();
 1395:             }
 1396:  
 1397:             //result.AddSuccess(service + ": state: " + Ia.Ngn.Cl.Model.Ui.Text.ExpressionOfInsertOrUpdateOrDelete(insert, update, delete));
 1398:  
 1399:             return insert || update || delete;
 1400:         }
 1401:  
 1402:         /*
 1403:         ////////////////////////////////////////////////////////////////////////////
 1404: 
 1405:         /// <summary>
 1406:         ///
 1407:         /// </summary>
 1408:         public static bool UpdateServiceList(Dictionary<long, Ia.Ngn.Cl.Model.Service> dnServiceDictionary)
 1409:         {
 1410:             bool isOk;
 1411:             int serviceType;
 1412:             long dn;
 1413:             string serviceId;
 1414:             Ia.Ngn.Cl.Model.Service service;
 1415:             Ia.Ngn.Cl.Model.Service2 service2, newService2;
 1416: 
 1417:             isOk = false;
 1418: 
 1419:             using (var db = new Ia.Ngn.Cl.Model.Ngn())
 1420:             {
 1421:                 // below:
 1422:                 foreach (KeyValuePair<long, Ia.Ngn.Cl.Model.Service> u in dnServiceDictionary)
 1423:                 {
 1424:                     dn = u.Key;
 1425:                     service = u.Value;
 1426: 
 1427:                     serviceType = Ia.Ngn.Cl.Model.Business.Service.ServiceType.Ngn;
 1428:                     serviceId = Ia.Ngn.Cl.Model.Service2.ServiceId(dn.ToString().Remove(0, 3), serviceType); // temp: remove 3 digits
 1429: 
 1430:                     // below:
 1431:                     if (service != null)
 1432:                     {
 1433:                         newService2 = new Ia.Ngn.Cl.Model.Service2();
 1434: 
 1435:                         newService2.Id = serviceId;
 1436:                         newService2.AreaCode = Ia.Ngn.Cl.Model.Data.Service.CountryCode;
 1437:                         newService2.Service = dn.ToString();
 1438:                         newService2.ServiceType = serviceType;
 1439: 
 1440:                         //newService2.ServiceSuspension = ??
 1441:                         newService2.CallBarring = service.OCBUC_ass;
 1442:                         newService2.CallForwarding = service.CFU_ass;
 1443:                         newService2.ConferenceCall = service.CONF;
 1444:                         //newService2.ConferenceCall = service.TPS_ass;
 1445: 
 1446:                         newService2.AlarmCall = service.ALM_ass;
 1447:                         newService2.CallWaiting = service.CW_ass;
 1448:                         newService2.Pin = service.PIN_code;
 1449: 
 1450:                         newService2.CallerId = service.CLIP;
 1451: 
 1452:                         service2 = (from q in db.Service2s where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.NgnService && q.Id == newService2.Id select q).SingleOrDefault();
 1453: 
 1454:                         if (service2 == null)
 1455:                         {
 1456:                             newService2.Created = newService2.Updated = DateTime.UtcNow.AddHours(3);
 1457:                             db.Service2s.Add(newService2);
 1458:                         }
 1459:                         else
 1460:                         {
 1461:                             if (service2.Update(newService2))
 1462:                             {
 1463:                                 db.Service2s.Attach(service2);
 1464:                                 db.Entry(service2).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
 1465:                             }
 1466:                         }
 1467:                     }
 1468:                     else
 1469:                     {
 1470:                         service2 = (from q in db.Service2s where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.NgnService && q.Id == serviceId select q).SingleOrDefault();
 1471: 
 1472:                         if (service2 != null) db.Service2s.Remove(service2);
 1473:                     }
 1474:                 }
 1475: 
 1476:                 db.SaveChanges();
 1477: 
 1478:                 isOk = true;
 1479:             }
 1480: 
 1481:             return isOk;
 1482:         }
 1483:          */
 1484:  
 1485:         ////////////////////////////////////////////////////////////////////////////
 1486:  
 1487:         /// <summary>
 1488:         ///
 1489:         /// </summary>
 1490:         public static List<int> AllPossibleGatewayIdList
 1491:         {
 1492:             get
 1493:             {
 1494:                 // below: GwId are defined by Nokia
 1495:  
 1496:                 List<int> allPossibleGatewayIdList;
 1497:  
 1498:                 allPossibleGatewayIdList = new List<int>(Ia.Ngn.Cl.Model.Business.Nokia.Ims.LastGatewayId - Ia.Ngn.Cl.Model.Business.Nokia.Ims.FirstGatewayId);
 1499:  
 1500:                 //allPossibleGatewayIdList = Ia.Ngn.Cl.Model.Data.Nokia.Default.GatewayIdList;
 1501:  
 1502:                 for (int i = Ia.Ngn.Cl.Model.Business.Nokia.Ims.FirstGatewayId; i <= Ia.Ngn.Cl.Model.Business.Nokia.Ims.LastGatewayId; i++)
 1503:                 {
 1504:                     allPossibleGatewayIdList.Add(i);
 1505:                 }
 1506:  
 1507:                 return allPossibleGatewayIdList;
 1508:             }
 1509:         }
 1510:  
 1511:         ////////////////////////////////////////////////////////////////////////////
 1512:  
 1513:         /// <summary>
 1514:         ///
 1515:         /// </summary>
 1516:         public static List<Ia.Ngn.Cl.Model.Ont> AllPossibleOntNotInAgcfGatewayRecordList(Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Olt olt)
 1517:         {
 1518:             DiscrepancyBetweenOntListAndAgctGatewayRecordList(olt, out List<Ia.Ngn.Cl.Model.Ont> ontsNotInAgcfGatewayRecordsList, out List<Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord> agcfGatewayRecordsNoInOntsList);
 1519:  
 1520:             return ontsNotInAgcfGatewayRecordsList;
 1521:         }
 1522:  
 1523:         ////////////////////////////////////////////////////////////////////////////
 1524:  
 1525:         /// <summary>
 1526:         ///
 1527:         /// </summary>
 1528:         public static List<Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont> NddOntNotInAgcfGatewayRecordList(Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Olt olt)
 1529:         {
 1530:             List<Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont> ngnOntList;
 1531:             List<Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont> ngnOntsNotInAgcfGatewayRecordsList;
 1532:             List<Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord> agcfGatewayRecordList;
 1533:  
 1534:             // below: NGN ONT list
 1535:             ngnOntList = (from o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList
 1536:                           where o.Pon.PonGroup.Olt.Id == olt.Id
 1537:                           select o).ToList();
 1538:  
 1539:             using (var db = new Ia.Ngn.Cl.Model.Ngn())
 1540:             {
 1541:                 // below: AgcfGatewayRecord list
 1542:                 agcfGatewayRecordList = (from a in db.AgcfGatewayRecords select a).AsNoTracking().ToList();
 1543:             }
 1544:  
 1545:             // below: ONTs not in AgcfGatewayRecord list
 1546:             ngnOntsNotInAgcfGatewayRecordsList = (from no in ngnOntList
 1547:                                                   join a in agcfGatewayRecordList on no.Ip equals a.IP1
 1548:                                                   into gj
 1549:                                                   from sub in gj.DefaultIfEmpty()
 1550:                                                   where sub == null
 1551:                                                   select no).ToList();
 1552:  
 1553:             return ngnOntsNotInAgcfGatewayRecordsList;
 1554:         }
 1555:  
 1556:         ////////////////////////////////////////////////////////////////////////////
 1557:  
 1558:         /// <summary>
 1559:         ///
 1560:         /// </summary>
 1561:         public static List<Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont> NddNokiaSwitchOntInNonSipOltWithAccessButNoAgcfGatewayRecordList()
 1562:         {
 1563:             var accessIdDictionary = Ia.Ngn.Cl.Model.Data.Access.IdDictionary;
 1564:  
 1565:             var ontList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList;
 1566:  
 1567:             var nddOntWithinAccessList = (from o in ontList
 1568:                                           where o.Pon.PonGroup.Olt.IsSip == false
 1569:                                           && o.Pon.PonGroup.Olt.Odf.Router.Vendor == Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor.Nokia
 1570:                                           && accessIdDictionary.ContainsKey(o.Access.Id)
 1571:                                           //&& accessIdList.Contains(o.Access.Id) // very slow
 1572:                                           select o).ToList();
 1573:  
 1574:             var agcfGatewayRecordIp1List = Ia.Ngn.Cl.Model.Data.Nokia.AgcfGatewayRecord.IpList();
 1575:  
 1576:             // below: ONTs in Accesses but not in AgcfGatewayRecord list
 1577:             var nddOntList = (from no in nddOntWithinAccessList
 1578:                               join grip1 in agcfGatewayRecordIp1List on no.Ip equals grip1
 1579:                               into gj
 1580:                               from sub in gj.DefaultIfEmpty()
 1581:                               where sub == null
 1582:                               select no).ToList();
 1583:  
 1584:             return nddOntList;
 1585:         }
 1586:  
 1587:         ////////////////////////////////////////////////////////////////////////////
 1588:  
 1589:         /// <summary>
 1590:         ///
 1591:         /// </summary>
 1592:         public static List<Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord> AgcfGatewayRecordWithNoNddNokiaSwitchOntInNonSipOltAndNullOrEmptyAgcfEndpointList()
 1593:         {
 1594:             List<string> accessIdList;
 1595:             List<Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont> ontList, nddOntWithNoAccessList;
 1596:             List<Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord> agcfGatewayRecordList, agcfGatewayRecordWithNoNddOntList, agcfGatewayRecordWithNoNddOntAccessList;
 1597:             List<Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont> nokiaSwitchOntInNonSipOltList;
 1598:  
 1599:             using (var db = new Ia.Ngn.Cl.Model.Ngn())
 1600:             {
 1601:                 accessIdList = (from a in db.Accesses select a.Id).AsNoTracking().ToList();
 1602:  
 1603:                 agcfGatewayRecordList = (from a in db.AgcfGatewayRecords
 1604:                                          select a)/*.Include(u => u.AgcfEndpoints)*/.AsNoTracking().ToList();
 1605:  
 1606:                 ontList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList;
 1607:  
 1608:                 nokiaSwitchOntInNonSipOltList = (from o in ontList
 1609:                                                  where o.Pon.PonGroup.Olt.IsSip == false
 1610:                                                  && o.Pon.PonGroup.Olt.Odf.Router.Vendor == Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor.Nokia
 1611:                                                  select o).ToList();
 1612:  
 1613:                 // below: AgcfGatewayRecord with no corresponding NDD ONT entries
 1614:                 agcfGatewayRecordWithNoNddOntList = (from gr in agcfGatewayRecordList
 1615:                                                      join no in nokiaSwitchOntInNonSipOltList
 1616:                                                      on gr.IP1 equals no.Ip
 1617:                                                      into gj
 1618:                                                      from sub in gj.DefaultIfEmpty()
 1619:                                                      where sub == null
 1620:                                                      select gr).ToList();
 1621:  
 1622:                 // below: NDD ONTs with no access
 1623:                 nddOntWithNoAccessList = (from o in nokiaSwitchOntInNonSipOltList
 1624:                                           join a in accessIdList on o.Access.Id equals a
 1625:                                           into gj
 1626:                                           from sub in gj.DefaultIfEmpty()
 1627:                                           where sub == null
 1628:                                           select o).ToList();
 1629:  
 1630:                 // below: AgcfGatewayRecord with no corresponding NDD ONT access entries
 1631:                 agcfGatewayRecordWithNoNddOntAccessList = (from gr in agcfGatewayRecordList
 1632:                                                            join no in nddOntWithNoAccessList
 1633:                                                            on gr.IP1 equals no.Ip
 1634:                                                            select gr).ToList();
 1635:             }
 1636:  
 1637:             return agcfGatewayRecordWithNoNddOntList.Union(agcfGatewayRecordWithNoNddOntAccessList).ToList();
 1638:         }
 1639:  
 1640:         ////////////////////////////////////////////////////////////////////////////
 1641:  
 1642:         /// <summary>
 1643:         ///
 1644:         /// </summary>
 1645:         public static List<Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont> NddOntWithAgcfGatewayRecordAndNotEmptyAgcfEndpointAndNullAccessList()
 1646:         {
 1647:             List<string> accessIdList;
 1648:             List<Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont> nddOntWithNoAccessList, nddOntWithAgcfGatewayRecordAndNotEmptyAgcfEndpointAndNullAccessList;
 1649:             List<Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord> agcfGatewayRecordList, agcfGatewayRecordWithNddOntAndNotEmptyAgcfEndpointList;
 1650:  
 1651:             using (var db = new Ia.Ngn.Cl.Model.Ngn())
 1652:             {
 1653:                 accessIdList = (from a in db.Accesses select a.Id).AsNoTracking().ToList();
 1654:  
 1655:                 agcfGatewayRecordList = (from a in db.AgcfGatewayRecords select a).Include(u => u.AgcfEndpoints).AsNoTracking().ToList();
 1656:  
 1657:                 // below: AgcfGatewayRecord with corresponding NDD ONT entries and not empty AgcfEndpoints
 1658:                 agcfGatewayRecordWithNddOntAndNotEmptyAgcfEndpointList = (from gr in agcfGatewayRecordList
 1659:                                                                           join no in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList
 1660:                                                                           on gr.IP1 equals no.Ip
 1661:                                                                           where gr.AgcfEndpoints != null && gr.AgcfEndpoints.Count > 0
 1662:                                                                           select gr).ToList();
 1663:  
 1664:                 // below: NDD ONTs with no access
 1665:                 nddOntWithNoAccessList = (from o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList
 1666:                                           join a in accessIdList on o.Access.Id equals a
 1667:                                           into gj
 1668:                                           from sub in gj.DefaultIfEmpty()
 1669:                                           where sub == null
 1670:                                           select o).ToList();
 1671:  
 1672:                 // below: AgcfGatewayRecord with corresponding NDD ONT entries and not empty AgcfEndpoints, but with no corresponding NDD ONT access entries
 1673:                 nddOntWithAgcfGatewayRecordAndNotEmptyAgcfEndpointAndNullAccessList = (from no in nddOntWithNoAccessList
 1674:                                                                                        join gr in agcfGatewayRecordList
 1675:                                                                                        on no.Ip equals gr.IP1
 1676:                                                                                        select no).ToList();
 1677:             }
 1678:  
 1679:             return nddOntWithAgcfGatewayRecordAndNotEmptyAgcfEndpointAndNullAccessList.ToList();
 1680:         }
 1681:  
 1682:         ////////////////////////////////////////////////////////////////////////////
 1683:  
 1684:         /// <summary>
 1685:         ///
 1686:         /// </summary>
 1687:         public static List<Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont> NddOntWithNoAccessList()
 1688:         {
 1689:             List<string> accessIdList;
 1690:             List<Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont> nddOntList;
 1691:  
 1692:             using (var db = new Ia.Ngn.Cl.Model.Ngn())
 1693:             {
 1694:                 accessIdList = (from a in db.Accesses select a.Id).AsNoTracking().ToList();
 1695:  
 1696:                 // below:
 1697:                 nddOntList = (from o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList
 1698:                               join a in accessIdList on o.Access.Id equals a
 1699:                               into gj
 1700:                               from sub in gj.DefaultIfEmpty()
 1701:                               where sub == null
 1702:                               select o).ToList();
 1703:             }
 1704:  
 1705:             return nddOntList;
 1706:         }
 1707:  
 1708:         ////////////////////////////////////////////////////////////////////////////
 1709:  
 1710:         /// <summary>
 1711:         ///
 1712:         /// </summary>
 1713:         public static List<Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord> AllPossibleAgcfGatewayRecordsNoInOntsList(Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Olt olt)
 1714:         {
 1715:             DiscrepancyBetweenOntListAndAgctGatewayRecordList(olt, out List<Ia.Ngn.Cl.Model.Ont> ontsNotInAgcfGatewayRecordsList, out List<Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord> agcfGatewayRecordsNoInOntsList);
 1716:  
 1717:             return agcfGatewayRecordsNoInOntsList;
 1718:         }
 1719:  
 1720:         ////////////////////////////////////////////////////////////////////////////
 1721:  
 1722:         /// <summary>
 1723:         ///
 1724:         /// </summary>
 1725:         private static void DiscrepancyBetweenOntListAndAgctGatewayRecordList(Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Olt olt, out List<Ia.Ngn.Cl.Model.Ont> ontsNotInAgcfGatewayRecordsList, out List<Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord> agcfGatewayRecordsNoInOntsList)
 1726:         {
 1727:             List<Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont> ngnOntList;
 1728:             List<Ia.Ngn.Cl.Model.Ont> ontList;
 1729:             List<Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord> agcfGatewayRecordList;
 1730:  
 1731:             // below: NGN ONT list
 1732:             ngnOntList = (from o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList
 1733:                           where o.Pon.PonGroup.Olt.Id == olt.Id
 1734:                           select o).ToList();
 1735:  
 1736:             using (var db = new Ia.Ngn.Cl.Model.Ngn())
 1737:             {
 1738:                 // below: ONT list
 1739:                 ontList = (from o in db.Onts
 1740:                            where o.Access != null && o.Access.Olt == olt.Id
 1741:                            select o).AsNoTracking().ToList();
 1742:  
 1743:                 // below: AgcfGatewayRecord list
 1744:                 agcfGatewayRecordList = (from a in db.AgcfGatewayRecords select a).AsNoTracking().ToList();
 1745:             }
 1746:  
 1747:             // below: ONTs not in AgcfGatewayRecord list
 1748:             ontsNotInAgcfGatewayRecordsList = (from o in ontList
 1749:                                                join no in ngnOntList on o.Id equals no.Id
 1750:                                                join a in agcfGatewayRecordList on no.Ip equals a.IP1
 1751:                                                into gj
 1752:                                                from sub in gj.DefaultIfEmpty()
 1753:                                                where sub == null
 1754:                                                select o).ToList();
 1755:  
 1756:             // below: AgcfGatewayRecords with IPs that are not in NGN ONT list
 1757:             agcfGatewayRecordsNoInOntsList = (from a in agcfGatewayRecordList
 1758:                                               join no in ngnOntList on a.IP1 equals no.Ip
 1759:                                               into gj
 1760:                                               from sub in gj.DefaultIfEmpty()
 1761:                                               where sub == null
 1762:                                               select a).ToList();
 1763:  
 1764:         }
 1765:  
 1766:         ////////////////////////////////////////////////////////////////////////////
 1767:  
 1768:         /// <summary>
 1769:         ///
 1770:         /// </summary>
 1771:         private static List<Ia.Ngn.Cl.Model.Nokia.AgcfEndpoint> AgcfEndpointsWithNoSubPartyReferenceList
 1772:         {
 1773:             get
 1774:             {
 1775:                 List<Ia.Ngn.Cl.Model.Nokia.AgcfEndpoint> agcfEndpointList;
 1776:  
 1777:                 using (var db = new Ia.Ngn.Cl.Model.Ngn())
 1778:                 {
 1779:                     agcfEndpointList = (from e in db.AgcfEndpoints
 1780:                                         join s in db.SubParties on e equals s.AgcfEndpoint
 1781:                                         into gj
 1782:                                         from u in gj.DefaultIfEmpty()
 1783:                                         where u == null
 1784:                                         select e).ToList();
 1785:                 }
 1786:  
 1787:                 return agcfEndpointList;
 1788:             }
 1789:         }
 1790:  
 1791:         ////////////////////////////////////////////////////////////////////////////
 1792:  
 1793:         /// <summary>
 1794:         ///
 1795:         /// </summary>
 1796:         public static List<string> ServiceProvisionedManuallyWithNonStandardHenceNotFunctionalPartyIdNames
 1797:         {
 1798:             get
 1799:             {
 1800:                 List<string> list;
 1801:  
 1802:                 list = new List<string>();
 1803:  
 1804:                 using (var db = new Ia.Ngn.Cl.Model.Ngn())
 1805:                 {
 1806:                     // exclude 1-800 numbers and numbers without AgcfEndpoints
 1807:  
 1808:                     // select Id from Subscribers where Id not like '+965________'
 1809:                     var subscriberSubpartyIdList = (from s in db.Subscribers where !(s.Id.StartsWith("+965") && s.Id.Length == 12) && !s.Id.StartsWith("+96518") select s.SubParty.Id).ToList();
 1810:  
 1811:                     // select DisplayName,PartyId from SubParties where AgcfEndpoint_Id not like 'priv____________'
 1812:                     var subPartyIdList = (from sp in db.SubParties where !(sp.AgcfEndpoint.Id.StartsWith("priv") && sp.AgcfEndpoint.Id.Length == 16) && !sp.Id.StartsWith("+96518") && sp.AgcfEndpoint != null select sp.Id).ToList();
 1813:  
 1814:                     // select PrividUser, GwId from AgcfEndpoints where Id not like 'priv____________'
 1815:                     var agcfEndpointDnList = (from ep in db.AgcfEndpoints where !(ep.Id.StartsWith("priv") && ep.Id.Length == 16) && !ep.Dn.StartsWith("+96518") select ep.Dn).ToList();
 1816:  
 1817:                     list.AddRange(subscriberSubpartyIdList);
 1818:                     list.AddRange(subPartyIdList);
 1819:                     list.AddRange(agcfEndpointDnList);
 1820:                 }
 1821:  
 1822:                 return list;
 1823:             }
 1824:         }
 1825:  
 1826:         ////////////////////////////////////////////////////////////////////////////
 1827:         ////////////////////////////////////////////////////////////////////////////
 1828:  
 1829:         /// <summary>
 1830:         ///
 1831:         /// </summary>
 1832:         public static List<string> AgcfGatewayRecordIp1sWithinWhichSubPartiesHaveServiceBundle2CategoryList
 1833:         {
 1834:             get
 1835:             {
 1836:                 if (agcfGatewayRecordIp1sWithinWhichSubPartiesHaveServiceBundle2CategoryList == null || agcfGatewayRecordIp1sWithinWhichSubPartiesHaveServiceBundle2CategoryList.Count == 0)
 1837:                 {
 1838:                     lock (objectLock)
 1839:                     {
 1840:                         agcfGatewayRecordIp1sWithinWhichSubPartiesHaveServiceBundle2CategoryList = Ia.Ngn.Cl.Model.Data.Nokia.Ims._AgcfGatewayRecordIp1sWithinWhichSubPartiesHaveServiceBundle2CategoryList;
 1841:                     }
 1842:                 }
 1843:  
 1844:                 return agcfGatewayRecordIp1sWithinWhichSubPartiesHaveServiceBundle2CategoryList;
 1845:             }
 1846:         }
 1847:  
 1848:         ////////////////////////////////////////////////////////////////////////////
 1849:  
 1850:         /// <summary>
 1851:         ///
 1852:         /// </summary>
 1853:         private static List<string> _AgcfGatewayRecordIp1sWithinWhichSubPartiesHaveServiceBundle2CategoryList
 1854:         {
 1855:             get
 1856:             {
 1857:                 using (var db = new Ia.Ngn.Cl.Model.Ngn())
 1858:                 {
 1859:                     agcfGatewayRecordIp1sWithinWhichSubPartiesHaveServiceBundle2CategoryList = (from sp in db.SubParties
 1860:                                                                                                 where sp.Category == "SERVICEBUNDLE2"
 1861:                                                                                                 join e in db.AgcfEndpoints on sp.AgcfEndpoint.Id equals e.Id
 1862:                                                                                                 join gr in db.AgcfGatewayRecords on e.AgcfGatewayRecord.Id equals gr.Id
 1863:                                                                                                 select gr.IP1).Distinct().ToList();
 1864:  
 1865:                     /*
 1866: select distinct gr.IP1 from AgcfGatewayRecords gr 
 1867: left outer join AgcfEndpoints ep on ep.AgcfGatewayRecord_Id = gr.Id
 1868: left outer join SubParties sp on sp.AgcfEndpoint_Id = ep.Id
 1869: where sp.Category = 'SERVICEBUNDLE2'
 1870: */
 1871:                 }
 1872:  
 1873:                 return agcfGatewayRecordIp1sWithinWhichSubPartiesHaveServiceBundle2CategoryList;
 1874:             }
 1875:         }
 1876:  
 1877:         ////////////////////////////////////////////////////////////////////////////
 1878:         ////////////////////////////////////////////////////////////////////////////
 1879:  
 1880:         /// <summary>
 1881:         ///
 1882:         /// </summary>
 1883:         public static List<string> AgcfGatewayRecordIp1sThatIndicateFsdb0List
 1884:         {
 1885:             get
 1886:             {
 1887:                 if (agcfGatewayRecordIp1sThatIndicateFsdb0List == null || agcfGatewayRecordIp1sThatIndicateFsdb0List.Count == 0)
 1888:                 {
 1889:                     lock (objectLock)
 1890:                     {
 1891:                         agcfGatewayRecordIp1sThatIndicateFsdb0List = Ia.Ngn.Cl.Model.Data.Nokia.Ims._AgcfGatewayRecordIp1sThatIndicateFsdb0List;
 1892:                     }
 1893:                 }
 1894:  
 1895:                 return agcfGatewayRecordIp1sThatIndicateFsdb0List;
 1896:             }
 1897:         }
 1898:  
 1899:         ////////////////////////////////////////////////////////////////////////////
 1900:  
 1901:         /// <summary>
 1902:         ///
 1903:         /// </summary>
 1904:         private static List<string> _AgcfGatewayRecordIp1sThatIndicateFsdb0List
 1905:         {
 1906:             get
 1907:             {
 1908:                 using (var db = new Ia.Ngn.Cl.Model.Ngn())
 1909:                 {
 1910:                     agcfGatewayRecordIp1sThatIndicateFsdb0List = (from gr in db.AgcfGatewayRecords where gr.AgcfSipIaPort == "agcf-stdn.imsgroup0-000" select gr.IP1).Distinct().ToList();
 1911:  
 1912:                     // select distinct IP1 from AgcfGatewayRecords where AgcfSipIaPort = 'agcf-stdn.imsgroup0-000'
 1913:                 }
 1914:  
 1915:                 return agcfGatewayRecordIp1sThatIndicateFsdb0List;
 1916:             }
 1917:         }
 1918:  
 1919:         ////////////////////////////////////////////////////////////////////////////
 1920:         ////////////////////////////////////////////////////////////////////////////
 1921:     }
 1922:  
 1923:     ////////////////////////////////////////////////////////////////////////////
 1924:     ////////////////////////////////////////////////////////////////////////////   
 1925: }