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

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