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

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