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

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » Ims

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

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

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