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

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » Ims

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

Optical Fiber Network Management Intranet Portal (OFN) support class for Nokia's Next Generation Network (NGN) data model.

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