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

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

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