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

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