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