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