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

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » Service2

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

Service support class for Next Generation Network (NGN) data model.

   1:  using System;
   2:  using System.Collections;
   3:  using System.Collections.Generic;
   4:  using System.Data;
   5:  using System.Data.Entity;
   6:  using System.Linq;
   7:   
   8:  namespace Ia.Ngn.Cl.Model.Data
   9:  {
  10:      ////////////////////////////////////////////////////////////////////////////
  11:   
  12:      /// <summary publish="true">
  13:      /// Service support class for Next Generation Network (NGN) data model.
  14:      /// </summary>
  15:      /// 
  16:      /// <remarks> 
  17:      /// Copyright © 2006-2019 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
  18:      ///
  19:      /// 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
  20:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  21:      ///
  22:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  23:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  24:      /// 
  25:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  26:      /// 
  27:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  28:      /// </remarks> 
  29:      public partial class Service2
  30:      {
  31:          public Service2() { }
  32:   
  33:          ////////////////////////////////////////////////////////////////////////////
  34:   
  35:          /// <summary>
  36:          /// Read service2
  37:          /// </summary>
  38:          public static Ia.Ngn.Cl.Model.Service2 Read(string service)
  39:          {
  40:              Ia.Ngn.Cl.Model.Service2 service2;
  41:   
  42:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  43:              {
  44:                  service2 = (from s in db.Service2s
  45:                              where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Service == service
  46:                              select s).SingleOrDefault();
  47:              }
  48:   
  49:              return service2;
  50:          }
  51:   
  52:          ////////////////////////////////////////////////////////////////////////////
  53:   
  54:          /// <summary>
  55:          /// Read service2s for service list
  56:          /// </summary>
  57:          public static List<Ia.Ngn.Cl.Model.Service2> ReadList(List<string> serviceList)
  58:          {
  59:              List<Ia.Ngn.Cl.Model.Service2> service2List;
  60:   
  61:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  62:              {
  63:                  service2List = (from s in db.Service2s
  64:                                  where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && serviceList.Contains(s.Service)
  65:                                  select s).ToList();
  66:              }
  67:   
  68:              return service2List;
  69:          }
  70:   
  71:          ////////////////////////////////////////////////////////////////////////////
  72:   
  73:          /// <summary>
  74:          /// Read PSTN service2
  75:          /// </summary>
  76:          public static Ia.Ngn.Cl.Model.Service2 ReadPstn(string service)
  77:          {
  78:              Ia.Ngn.Cl.Model.Service2 service2;
  79:   
  80:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  81:              {
  82:                  service2 = (from s in db.Service2s
  83:                              where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.PstnService && s.Service == service
  84:                              select s).SingleOrDefault();
  85:              }
  86:   
  87:              return service2;
  88:          }
  89:   
  90:          ////////////////////////////////////////////////////////////////////////////
  91:   
  92:          /// <summary>
  93:          /// Read PSTN service2s for service list
  94:          /// </summary>
  95:          public static List<Ia.Ngn.Cl.Model.Service2> ReadPstnList(List<string> serviceList)
  96:          {
  97:              List<Ia.Ngn.Cl.Model.Service2> service2List;
  98:   
  99:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 100:              {
 101:                  service2List = (from s in db.Service2s
 102:                                  where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.PstnService && serviceList.Contains(s.Service)
 103:                                  select s).ToList();
 104:              }
 105:   
 106:              return service2List;
 107:          }
 108:   
 109:          ////////////////////////////////////////////////////////////////////////////
 110:   
 111:          /// <summary>
 112:          /// Read service of a number
 113:          /// </summary>
 114:          public static Ia.Ngn.Cl.Model.Service2 Read(long number)
 115:          {
 116:              Ia.Ngn.Cl.Model.Service2 service;
 117:   
 118:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 119:              {
 120:                  service = (from s in db.Service2s
 121:                             where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Service == number.ToString()
 122:                             select s).SingleOrDefault();
 123:              }
 124:   
 125:              return service;
 126:          }
 127:   
 128:          ////////////////////////////////////////////////////////////////////////////
 129:   
 130:          /// <summary>
 131:          /// Read service from Id
 132:          /// </summary>
 133:          public static Ia.Ngn.Cl.Model.Service2 ReadByIdIncludeAccess(string serviceId)
 134:          {
 135:              Ia.Ngn.Cl.Model.Service2 service2;
 136:   
 137:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 138:              {
 139:                  service2 = (from s in db.Service2s.Include(a => a.Access)
 140:                              where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Id == serviceId
 141:                              select s).SingleOrDefault();
 142:              }
 143:   
 144:              return service2;
 145:          }
 146:   
 147:          ////////////////////////////////////////////////////////////////////////////
 148:   
 149:          /// <summary>
 150:          /// Read service of a number
 151:          /// </summary>
 152:          public static Ia.Ngn.Cl.Model.Service2 ReadWithAccess(string service)
 153:          {
 154:              Ia.Ngn.Cl.Model.Service2 service2;
 155:   
 156:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 157:              {
 158:                  service2 = (from s in db.Service2s.Include(a => a.Access)
 159:                              where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Service == service
 160:                              select s).SingleOrDefault();
 161:              }
 162:   
 163:              return service2;
 164:          }
 165:   
 166:          ////////////////////////////////////////////////////////////////////////////
 167:   
 168:          /// <summary>
 169:          ///
 170:          /// </summary>
 171:          public static List<Ia.Ngn.Cl.Model.Service2> List()
 172:          {
 173:              List<Ia.Ngn.Cl.Model.Service2> serviceList;
 174:   
 175:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 176:              {
 177:                  serviceList = (from s in db.Service2s where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService select s).ToList();
 178:              }
 179:   
 180:              return serviceList;
 181:          }
 182:   
 183:          ////////////////////////////////////////////////////////////////////////////
 184:   
 185:          /// <summary>
 186:          ///
 187:          /// </summary>
 188:          public static List<string> List(List<int> domainList)
 189:          {
 190:              List<string> stringDomainList;
 191:              List<string> serviceList;
 192:   
 193:              stringDomainList = new List<string>();
 194:   
 195:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 196:              {
 197:                  if (domainList != null)
 198:                  {
 199:                      foreach (int i in domainList) stringDomainList.Add(i.ToString());
 200:   
 201:                      serviceList = (from s in db.Service2s
 202:                                     where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && stringDomainList.Any(u => s.Service.StartsWith(u.ToString()))
 203:                                     select s.Service).ToList();
 204:                  }
 205:                  else
 206:                  {
 207:                      serviceList = (from s in db.Service2s where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService select s.Service).ToList();
 208:                  }
 209:              }
 210:   
 211:              return serviceList;
 212:          }
 213:   
 214:          ////////////////////////////////////////////////////////////////////////////
 215:   
 216:          /// <summary>
 217:          ///
 218:          /// </summary>
 219:          public static List<string> ServiceList
 220:          {
 221:              get
 222:              {
 223:                  List<string> list;
 224:   
 225:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 226:                  {
 227:                      list = (from s in db.Service2s where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService select s.Service).ToList();
 228:                  }
 229:   
 230:                  return list;
 231:              }
 232:          }
 233:   
 234:          ////////////////////////////////////////////////////////////////////////////
 235:   
 236:          /// <summary>
 237:          /// 
 238:          /// </summary>
 239:          public static List<string> NgnAndPstnServiceIdList
 240:          {
 241:              get
 242:              {
 243:                  List<string> list;
 244:   
 245:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 246:                  {
 247:                      list = (from s in db.Service2s select s.Id).ToList();
 248:                  }
 249:   
 250:                  return list.ToList();
 251:              }
 252:          }
 253:   
 254:          ////////////////////////////////////////////////////////////////////////////
 255:   
 256:          /// <summary>
 257:          /// 
 258:          /// </summary>
 259:          public static List<string> ServiceIdList
 260:          {
 261:              get
 262:              {
 263:                  List<string> list;
 264:   
 265:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 266:                  {
 267:                      list = (from s in db.Service2s /*where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService*/ select s.Id).ToList();
 268:                  }
 269:   
 270:                  return list.ToList();
 271:              }
 272:          }
 273:   
 274:          ////////////////////////////////////////////////////////////////////////////
 275:   
 276:          /// <summary>
 277:          /// 
 278:          /// </summary>
 279:          public static List<Ia.Ngn.Cl.Model.Business.ServiceOnt> ServiceOntList
 280:          {
 281:              get
 282:              {
 283:                  List<Ia.Ngn.Cl.Model.Business.ServiceOnt> list;
 284:   
 285:                  var ontAccessIdToOntForOltIdListDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntDictionary;
 286:   
 287:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 288:                  {
 289:                      list = (from s in db.Service2s
 290:                              where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService
 291:                              select new Ia.Ngn.Cl.Model.Business.ServiceOnt { ServiceId = s.Id, Service = s.Service, AccessId = s.Access != null ? s.Access.Id : string.Empty, CreatedDateTime = s.Created }).ToList();
 292:                  }
 293:   
 294:                  foreach (var l in list)
 295:                  {
 296:                      l.Ont = ontAccessIdToOntForOltIdListDictionary.ContainsKey(l.AccessId) ? ontAccessIdToOntForOltIdListDictionary[l.AccessId] : null;
 297:                  }
 298:   
 299:                  return list;
 300:              }
 301:          }
 302:   
 303:          ////////////////////////////////////////////////////////////////////////////
 304:   
 305:          /// <summary>
 306:          /// 
 307:          /// </summary>
 308:          public static List<Ia.Ngn.Cl.Model.Service2> PstnServiceList
 309:          {
 310:              get
 311:              {
 312:                  List<Ia.Ngn.Cl.Model.Service2> list;
 313:   
 314:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 315:                  {
 316:                      list = (from s in db.Service2s where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.PstnService select s).Include(s => s.Access).ToList();
 317:                  }
 318:   
 319:                  return list.ToList();
 320:              }
 321:          }
 322:   
 323:          ////////////////////////////////////////////////////////////////////////////
 324:   
 325:          /// <summary>
 326:          /// 
 327:          /// </summary>
 328:          public static Dictionary<string, int> ServiceIdToPortDictionary
 329:          {
 330:              get
 331:              {
 332:                  Dictionary<string, int> dictionary;
 333:   
 334:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 335:                  {
 336:                      dictionary = (from s in db.Service2s
 337:                                    where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Access != null
 338:                                    select new { s.Id, s.Port }).ToDictionary(m => m.Id, m => m.Port);
 339:                  }
 340:   
 341:                  return dictionary;
 342:              }
 343:          }
 344:   
 345:          ////////////////////////////////////////////////////////////////////////////
 346:   
 347:          /// <summary>
 348:          ///
 349:          /// </summary>
 350:          public static Ia.Ngn.Cl.Model.Access ReadAccess(string id)
 351:          {
 352:              Ia.Ngn.Cl.Model.Access access;
 353:   
 354:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 355:              {
 356:                  access = (from s in db.Service2s
 357:                            where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Id == id
 358:                            select s.Access).SingleOrDefault();
 359:              }
 360:   
 361:              return access;
 362:          }
 363:   
 364:          ////////////////////////////////////////////////////////////////////////////
 365:   
 366:          /// <summary>
 367:          ///
 368:          /// </summary>
 369:          public static Dictionary<string, int> ServicePortDictionary
 370:          {
 371:              get
 372:              {
 373:                  Dictionary<string, int> dictionary;
 374:   
 375:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 376:                  {
 377:                      dictionary = (from s in db.Service2s
 378:                                    where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Port > -1
 379:                                    select new { s.Service, s.Port }).ToDictionary(m => m.Service, m => m.Port);
 380:                  }
 381:   
 382:                  return dictionary;
 383:              }
 384:          }
 385:   
 386:          ////////////////////////////////////////////////////////////////////////////
 387:   
 388:          /// <summary>
 389:          ///
 390:          /// </summary>
 391:          public static Ia.Ngn.Cl.Model.Access ReadAccess(Ia.Ngn.Cl.Model.Ngn db, string id)
 392:          {
 393:              Ia.Ngn.Cl.Model.Access access;
 394:   
 395:              access = (from s in db.Service2s
 396:                        where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Id == id
 397:                        select s.Access).SingleOrDefault();
 398:   
 399:              return access;
 400:          }
 401:   
 402:          ////////////////////////////////////////////////////////////////////////////
 403:   
 404:          /// <summary>
 405:          ///
 406:          /// </summary>
 407:          public static bool UpdatePort(Ia.Ngn.Cl.Model.Service2 service, int port, out string result)
 408:          {
 409:              bool b;
 410:   
 411:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 412:              {
 413:                  service = (from s in db.Service2s
 414:                             where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Id == service.Id
 415:                             select s).SingleOrDefault();
 416:   
 417:                  if (service.Port != port)
 418:                  {
 419:                      service.Port = port;
 420:   
 421:                      db.Service2s.Attach(service);
 422:                      db.Entry(service).Property(x => x.Port).IsModified = true;
 423:   
 424:                      db.SaveChanges();
 425:   
 426:                      result = "Success: Service Port updated. ";
 427:                      b = true;
 428:                  }
 429:                  else
 430:                  {
 431:                      result = "Warning: Service Port value was not updated because its the same. ";
 432:   
 433:                      b = false;
 434:                  }
 435:              }
 436:   
 437:              return b;
 438:          }
 439:   
 440:          ////////////////////////////////////////////////////////////////////////////
 441:   
 442:          /// <summary>
 443:          ///
 444:          /// </summary>
 445:          public static List<Ia.Ngn.Cl.Model.Service2> ServiceWithNullAccessList
 446:          {
 447:              get
 448:              {
 449:                  List<Ia.Ngn.Cl.Model.Service2> serviceList;
 450:   
 451:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 452:                  {
 453:                      serviceList = (from s in db.Service2s
 454:                                     where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Access == null
 455:                                     select s).ToList();
 456:                  }
 457:   
 458:                  return serviceList;
 459:              }
 460:          }
 461:   
 462:          ////////////////////////////////////////////////////////////////////////////
 463:   
 464:          /// <summary>
 465:          /// Services within a SIP designated OLT
 466:          /// </summary>
 467:          public static List<string> ServiceIdWithinSipOltList()
 468:          {
 469:              List<int> sipOltIdList;
 470:              List<string> list, list2;
 471:   
 472:              sipOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.SipOltIdList;
 473:   
 474:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 475:              {
 476:                  // services with access
 477:                  list = (from s in db.Service2s
 478:                          where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Access != null && sipOltIdList.Contains(s.Access.Olt)
 479:                          select s.Id).ToList();
 480:   
 481:                  // services without access might be newly installed
 482:                  list2 = (from s in db.Service2s
 483:                           join srs in db.ServiceRequestServices on s.Service equals srs.Service
 484:                           where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Access == null && srs.Access != null && srs.Provisioned == true && sipOltIdList.Contains(srs.Access.Olt)
 485:                           select s.Id).ToList();
 486:              }
 487:   
 488:              return list.Union(list2).Distinct().ToList();
 489:          }
 490:   
 491:          ////////////////////////////////////////////////////////////////////////////
 492:   
 493:          /// <summary>
 494:          /// Services within a SIP allowed to be provisioned or migrated OLT
 495:          /// </summary>
 496:          public static List<string> ServiceIdWithinAllowedSipOltToBeProvisionedOrMigratedList()
 497:          {
 498:              List<int> sipOltIdList;
 499:              List<string> list, list2;
 500:   
 501:              sipOltIdList = Ia.Ngn.Cl.Model.Data.Service.AllowedToBeProvisionedSipOltIdList.Union(Ia.Ngn.Cl.Model.Data.Service.AllowedToBeMigratedSipOltIdList).ToList();
 502:   
 503:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 504:              {
 505:                  // services with access
 506:                  list = (from s in db.Service2s where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Access != null && sipOltIdList.Contains(s.Access.Olt) select s.Id).ToList();
 507:   
 508:                  // services without access might be newly installed
 509:                  list2 = (from s in db.Service2s
 510:                           join srs in db.ServiceRequestServices on s.Service equals srs.Service
 511:                           where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Access == null && srs.Access != null && srs.Provisioned == true && sipOltIdList.Contains(srs.Access.Olt)
 512:                           select s.Id).ToList();
 513:              }
 514:   
 515:              return list.Union(list2).Distinct().ToList();
 516:          }
 517:   
 518:          ////////////////////////////////////////////////////////////////////////////
 519:   
 520:          /// <summary>
 521:          /// ServiceOnts within a SIP allowed to be provisioned or migrated OLT
 522:          /// </summary>
 523:          public static List<Ia.Ngn.Cl.Model.Business.ServiceOnt> ServiceOntWithinAllowedSipOltToBeProvisionedOrMigratedList
 524:          {
 525:              get
 526:              {
 527:                  List<int> oltIdList;
 528:                  List<Ia.Ngn.Cl.Model.Business.ServiceOnt> list1, list2, list;
 529:   
 530:                  oltIdList = Ia.Ngn.Cl.Model.Data.Service.AllowedToBeProvisionedSipOltIdList.Union(Ia.Ngn.Cl.Model.Data.Service.AllowedToBeMigratedSipOltIdList).ToList();
 531:   
 532:                  var ontAccessIdToOntForOltIdListDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntForOltIdListDictionary(oltIdList);
 533:   
 534:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 535:                  {
 536:                      // services with access
 537:                      list1 = (from s in db.Service2s
 538:                               where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Access != null && oltIdList.Contains(s.Access.Olt)
 539:                               select new Ia.Ngn.Cl.Model.Business.ServiceOnt { ServiceId = s.Id, Service = s.Service, AccessId = s.Access.Id, CreatedDateTime = s.Created }).ToList();
 540:   
 541:                      // services without access might be newly installed
 542:                      list2 = (from s in db.Service2s
 543:                               join srs in db.ServiceRequestServices on s.Service equals srs.Service
 544:                               where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Access == null && srs.Access != null && srs.Provisioned == true && oltIdList.Contains(srs.Access.Olt)
 545:                               select new Ia.Ngn.Cl.Model.Business.ServiceOnt { ServiceId = s.Id, Service = s.Service, AccessId = srs.Access.Id, CreatedDateTime = s.Created }).ToList();
 546:                  }
 547:   
 548:                  list = list1.Concat(list2).ToList();
 549:   
 550:                  foreach (var l in list)
 551:                  {
 552:                      l.Ont = ontAccessIdToOntForOltIdListDictionary.ContainsKey(l.AccessId) ? ontAccessIdToOntForOltIdListDictionary[l.AccessId] : null;
 553:                  }
 554:   
 555:                  return list;
 556:              }
 557:          }
 558:   
 559:          ////////////////////////////////////////////////////////////////////////////
 560:   
 561:          /// <summary>
 562:          /// Services within Huawei switch domain list
 563:          /// </summary>
 564:          public static List<string> ServiceIdWithinHuaweiSwitchDomainList()
 565:          {
 566:              List<int> huaweiSwitchDomainList;
 567:              List<string> list;
 568:   
 569:              huaweiSwitchDomainList = Ia.Ngn.Cl.Model.Data.Service.HuaweiSwitchDomainList;
 570:   
 571:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 572:              {
 573:                  list = (from s in db.Service2s
 574:                          where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && huaweiSwitchDomainList.Any(u => s.Service.StartsWith(u.ToString()))
 575:                          select s.Id).ToList();
 576:              }
 577:   
 578:              return list.ToList();
 579:          }
 580:   
 581:          ////////////////////////////////////////////////////////////////////////////
 582:   
 583:          /// <summary>
 584:          /// Services within Nokia switch domain list
 585:          /// </summary>
 586:          public static List<string> ServiceIdWithinNokiaSwitchDomainList()
 587:          {
 588:              List<int> nokiaSwitchDomainList;
 589:              List<string> list;
 590:   
 591:              nokiaSwitchDomainList = Ia.Ngn.Cl.Model.Data.Service.NokiaSwitchDomainList;
 592:   
 593:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 594:              {
 595:                  list = (from s in db.Service2s
 596:                          where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && nokiaSwitchDomainList.Any(u => s.Service.StartsWith(u.ToString()))
 597:                          select s.Id).ToList();
 598:              }
 599:   
 600:              return list.ToList();
 601:          }
 602:   
 603:          ////////////////////////////////////////////////////////////////////////////
 604:   
 605:          /// <summary>
 606:          ///
 607:          /// </summary>
 608:          public static List<string> ServiceIdWithNullAccessList()
 609:          {
 610:              List<string> list;
 611:   
 612:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 613:              {
 614:                  list = (from s in db.Service2s
 615:                          where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Access == null
 616:                          select s.Id).ToList();
 617:              }
 618:   
 619:              return list;
 620:          }
 621:   
 622:          ////////////////////////////////////////////////////////////////////////////
 623:   
 624:          /// <summary>
 625:          ///
 626:          /// </summary>
 627:          public static List<Ia.Ngn.Cl.Model.Service2> ServiceSuspensionIsTrueList
 628:          {
 629:              get
 630:              {
 631:                  List<Ia.Ngn.Cl.Model.Service2> serviceList;
 632:   
 633:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 634:                  {
 635:                      serviceList = (from s in db.Service2s
 636:                                     where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.ServiceSuspension == true
 637:                                     select s).ToList();
 638:                  }
 639:   
 640:                  return serviceList;
 641:              }
 642:          }
 643:   
 644:          ////////////////////////////////////////////////////////////////////////////
 645:   
 646:          /// <summary>
 647:          ///
 648:          /// </summary>
 649:          public static int ServiceSuspensionIsTrueListCount
 650:          {
 651:              get
 652:              {
 653:                  int c;
 654:   
 655:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 656:                  {
 657:                      c = (from s in db.Service2s
 658:                           where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.ServiceSuspension == true
 659:                           select s).Count();
 660:                  }
 661:   
 662:                  return c;
 663:              }
 664:          }
 665:   
 666:          ////////////////////////////////////////////////////////////////////////////
 667:   
 668:          /// <summary>
 669:          ///
 670:          /// </summary>
 671:          public static List<Ia.Ngn.Cl.Model.Service2> ServiceSuspensionIsFalseList
 672:          {
 673:              get
 674:              {
 675:                  List<Ia.Ngn.Cl.Model.Service2> serviceList;
 676:   
 677:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 678:                  {
 679:                      serviceList = (from s in db.Service2s
 680:                                     where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.ServiceSuspension == false
 681:                                     select s).ToList();
 682:                  }
 683:   
 684:                  return serviceList;
 685:              }
 686:          }
 687:   
 688:          ////////////////////////////////////////////////////////////////////////////
 689:   
 690:          /// <summary>
 691:          ///
 692:          /// </summary>
 693:          public static List<string> ServiceSuspensionIsTrueStringNumberList
 694:          {
 695:              get
 696:              {
 697:                  List<string> serviceNumberStringList;
 698:                  List<Ia.Ngn.Cl.Model.Service2> serviceList;
 699:   
 700:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 701:                  {
 702:                      // below:                
 703:                      serviceList = ServiceSuspensionIsTrueList;
 704:   
 705:                      if (serviceList.Count > 0)
 706:                      {
 707:                          serviceNumberStringList = new List<string>(serviceList.Count);
 708:   
 709:                          foreach (Ia.Ngn.Cl.Model.Service2 srs in serviceList)
 710:                          {
 711:                              serviceNumberStringList.Add(srs.Service);
 712:                          }
 713:                      }
 714:                      else
 715:                      {
 716:                          // below: not null
 717:                          serviceNumberStringList = new List<string>(1);
 718:                      }
 719:                  }
 720:   
 721:                  return serviceNumberStringList;
 722:              }
 723:          }
 724:   
 725:          ////////////////////////////////////////////////////////////////////////////
 726:   
 727:          /// <summary>
 728:          ///
 729:          /// </summary>
 730:          public static List<string> ServiceSuspensionIsFalseStringNumberList
 731:          {
 732:              get
 733:              {
 734:                  List<string> serviceNumberStringList;
 735:                  List<Ia.Ngn.Cl.Model.Service2> serviceList;
 736:   
 737:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 738:                  {
 739:                      // below:                
 740:                      serviceList = ServiceSuspensionIsFalseList;
 741:   
 742:                      if (serviceList.Count > 0)
 743:                      {
 744:                          serviceNumberStringList = new List<string>(serviceList.Count);
 745:   
 746:                          foreach (Ia.Ngn.Cl.Model.Service2 srs in serviceList)
 747:                          {
 748:                              serviceNumberStringList.Add(srs.Service);
 749:                          }
 750:                      }
 751:                      else
 752:                      {
 753:                          // below: not null
 754:                          serviceNumberStringList = new List<string>(1);
 755:                      }
 756:                  }
 757:   
 758:                  return serviceNumberStringList;
 759:              }
 760:          }
 761:   
 762:          ////////////////////////////////////////////////////////////////////////////
 763:   
 764:          /// <summary>
 765:          ///
 766:          /// </summary>
 767:          public static Dictionary<string, string> ServiceIdToAccessIdDictionary
 768:          {
 769:              get
 770:              {
 771:                  Dictionary<string, string> dictionary, nullAccessDictionary;
 772:   
 773:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 774:                  {
 775:                      dictionary = (from s in db.Service2s
 776:                                    where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Access != null
 777:                                    select new { s.Id, s.Access }).ToDictionary(u => u.Id, u => u.Access.Id);
 778:   
 779:                      nullAccessDictionary = (from s in db.Service2s
 780:                                              where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Access == null
 781:                                              select new { s.Id, s.Access }).ToDictionary(u => u.Id, u => string.Empty);
 782:                  }
 783:   
 784:                  return dictionary.Union(nullAccessDictionary).ToDictionary(u => u.Key, u => u.Value);
 785:              }
 786:          }
 787:   
 788:          ////////////////////////////////////////////////////////////////////////////
 789:   
 790:          /// <summary>
 791:          ///
 792:          /// </summary>
 793:          public static Dictionary<string, string> PstnServiceIdToAccessIdDictionary
 794:          {
 795:              get
 796:              {
 797:                  Dictionary<string, string> dictionary, nullAccessDictionary;
 798:   
 799:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 800:                  {
 801:                      dictionary = (from s in db.Service2s
 802:                                    where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.PstnService && s.Access != null
 803:                                    select new { s.Id, s.Access }).ToDictionary(u => u.Id, u => u.Access.Id);
 804:   
 805:                      nullAccessDictionary = (from s in db.Service2s
 806:                                              where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.PstnService && s.Access == null
 807:                                              select new { s.Id, s.Access }).ToDictionary(u => u.Id, u => string.Empty);
 808:                  }
 809:   
 810:                  return dictionary.Union(nullAccessDictionary).ToDictionary(u => u.Key, u => u.Value);
 811:              }
 812:          }
 813:   
 814:          ////////////////////////////////////////////////////////////////////////////
 815:   
 816:          /// <summary>
 817:          ///
 818:          /// </summary>
 819:          public static Dictionary<string, string> MigratedServiceIdToAccessIdDictionary
 820:          {
 821:              get
 822:              {
 823:                  Dictionary<string, string> dictionary, nullAccessDictionary;
 824:   
 825:                  var migrationDomainList = Ia.Ngn.Cl.Model.Data.Service.MigrationDomainList;
 826:                  var migrationDomainStringList = migrationDomainList.ConvertAll<string>(delegate (int i) { return i.ToString(); });
 827:   
 828:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 829:                  {
 830:                      dictionary = (from s in db.Service2s
 831:                                    where s.Access != null && migrationDomainStringList.Any(u => s.Service.StartsWith(u))
 832:                                    select new { s.Id, s.Access }).ToDictionary(u => u.Id, u => u.Access.Id);
 833:   
 834:                      nullAccessDictionary = (from s in db.Service2s
 835:                                              where s.Access == null && migrationDomainStringList.Any(u => s.Service.StartsWith(u))
 836:                                              select new { s.Id, s.Access }).ToDictionary(u => u.Id, u => string.Empty);
 837:                  }
 838:   
 839:                  return dictionary.Union(nullAccessDictionary).ToDictionary(u => u.Key, u => u.Value);
 840:              }
 841:          }
 842:   
 843:          ////////////////////////////////////////////////////////////////////////////
 844:   
 845:          /// <summary>
 846:          ///
 847:          /// </summary>
 848:          public static Dictionary<string, string> MigratedServiceIdToAccessIdInAllowedToBeMigratedOltDictionary
 849:          {
 850:              get
 851:              {
 852:                  Dictionary<string, string> dictionary;
 853:   
 854:                  var allowedToBeMigratedOltIdList = Ia.Ngn.Cl.Model.Data.Service.AllowedToBeMigratedOltIdList;
 855:   
 856:                  var migrationDomainList = Ia.Ngn.Cl.Model.Data.Service.MigrationDomainList;
 857:                  var migrationDomainStringList = migrationDomainList.ConvertAll<string>(delegate (int i) { return i.ToString(); });
 858:   
 859:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 860:                  {
 861:                      dictionary = (from s in db.Service2s
 862:                                    where s.Access != null && migrationDomainStringList.Any(u => s.Service.StartsWith(u)) && allowedToBeMigratedOltIdList.Contains(s.Access.Olt) && s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService
 863:                                    select new { s.Id, s.Access }).ToDictionary(u => u.Id, u => u.Access.Id);
 864:                  }
 865:   
 866:                  return dictionary.ToDictionary(u => u.Key, u => u.Value);
 867:              }
 868:          }
 869:   
 870:          ////////////////////////////////////////////////////////////////////////////
 871:   
 872:          /// <summary>
 873:          ///
 874:          /// </summary>
 875:          public static Dictionary<string, string> GponServiceToAccessIdInAllowedToBeMigratedOltDictionary
 876:          {
 877:              get
 878:              {
 879:                  Dictionary<string, string> dictionary;
 880:   
 881:                  var allowedToBeMigratedOltIdList = Ia.Ngn.Cl.Model.Data.Service.AllowedToBeMigratedOltIdList;
 882:   
 883:                  var migrationDomainList = Ia.Ngn.Cl.Model.Data.Service.MigrationDomainList;
 884:                  var migrationDomainStringList = migrationDomainList.ConvertAll<string>(delegate (int i) { return i.ToString(); });
 885:   
 886:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 887:                  {
 888:                      dictionary = (from s in db.Service2s
 889:                                    where s.Access != null && migrationDomainStringList.Any(u => s.Service.StartsWith(u)) && allowedToBeMigratedOltIdList.Contains(s.Access.Olt) && s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService
 890:                                    select new { s.Service, s.Access }).ToDictionary(u => u.Service, u => u.Access.Id);
 891:                  }
 892:   
 893:                  return dictionary.ToDictionary(u => u.Key, u => u.Value);
 894:              }
 895:          }
 896:   
 897:          ////////////////////////////////////////////////////////////////////////////
 898:   
 899:          /// <summary>
 900:          ///
 901:          /// </summary>
 902:          public static Dictionary<string, string> ServiceToAccessIdDictionary
 903:          {
 904:              get
 905:              {
 906:                  string key;
 907:                  Dictionary<string, string> serviceToAccessIdDictionary, serviceIdToAccessIdDictionary;
 908:   
 909:                  serviceIdToAccessIdDictionary = ServiceIdToAccessIdDictionary;
 910:   
 911:                  serviceToAccessIdDictionary = new Dictionary<string, string>(serviceIdToAccessIdDictionary.Count);
 912:   
 913:                  foreach (KeyValuePair<string, string> kvp in serviceIdToAccessIdDictionary)
 914:                  {
 915:                      key = Ia.Ngn.Cl.Model.Business.Service.ServiceIdToService(kvp.Key);
 916:   
 917:                      serviceToAccessIdDictionary[key] = kvp.Value;
 918:                  }
 919:   
 920:                  return serviceToAccessIdDictionary;
 921:              }
 922:          }
 923:   
 924:          ////////////////////////////////////////////////////////////////////////////
 925:   
 926:          /// <summary>
 927:          ///
 928:          /// </summary>
 929:          public static Dictionary<string, string> ServiceIdToAccessNameDictionary
 930:          {
 931:              get
 932:              {
 933:                  Dictionary<string, string> dictionary, nullAccessDictionary;
 934:   
 935:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 936:                  {
 937:                      dictionary = (from s in db.Service2s
 938:                                    where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Access != null
 939:                                    select new { s.Id, s.Access }).ToDictionary(u => u.Id, u => u.Access.Name);
 940:   
 941:                      nullAccessDictionary = (from s in db.Service2s
 942:                                              where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Access == null
 943:                                              select s.Id).ToDictionary(u => u, null);
 944:                  }
 945:   
 946:                  return dictionary.Union(nullAccessDictionary).ToDictionary(u => u.Key, u => u.Value);
 947:              }
 948:          }
 949:   
 950:          ////////////////////////////////////////////////////////////////////////////
 951:   
 952:          /// <summary>
 953:          ///
 954:          /// </summary>
 955:          public static Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont> ServiceToNddOntDictionary
 956:          {
 957:              get
 958:              {
 959:                  string key;
 960:                  Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont> dictionary;
 961:   
 962:                  var serviceIdToAccessIdDictionary = Ia.Ngn.Cl.Model.Data.Service2.ServiceIdToAccessIdDictionary;
 963:                  var ontAccessIdToOntDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntDictionary;
 964:   
 965:                  dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont>(serviceIdToAccessIdDictionary.Count);
 966:   
 967:                  foreach (KeyValuePair<string, string> kvp in serviceIdToAccessIdDictionary)
 968:                  {
 969:                      key = Ia.Ngn.Cl.Model.Business.Service.ServiceIdToService(kvp.Key);
 970:   
 971:                      if (!string.IsNullOrEmpty(kvp.Value)) dictionary[key] = ontAccessIdToOntDictionary[kvp.Value];
 972:                      else dictionary[key] = null;
 973:                  }
 974:   
 975:                  return dictionary;
 976:              }
 977:          }
 978:   
 979:          ////////////////////////////////////////////////////////////////////////////
 980:   
 981:          /// <summary>
 982:          ///
 983:          /// </summary>
 984:          public static Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont> PstnServiceToNddOntDictionary
 985:          {
 986:              get
 987:              {
 988:                  string key;
 989:                  Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont> dictionary;
 990:   
 991:                  var pstnServiceIdToAccessIdDictionary = Ia.Ngn.Cl.Model.Data.Service2.PstnServiceIdToAccessIdDictionary;
 992:                  var ontAccessIdToOntDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntDictionary;
 993:   
 994:                  dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont>(pstnServiceIdToAccessIdDictionary.Count);
 995:   
 996:                  foreach (KeyValuePair<string, string> kvp in pstnServiceIdToAccessIdDictionary)
 997:                  {
 998:                      key = Ia.Ngn.Cl.Model.Business.Service.ServiceIdToService(kvp.Key);
 999:   
1000:                      if (!string.IsNullOrEmpty(kvp.Value)) dictionary[key] = ontAccessIdToOntDictionary[kvp.Value];
1001:                      //else dictionary[key] = null;
1002:                  }
1003:   
1004:                  return dictionary;
1005:              }
1006:          }
1007:   
1008:          ////////////////////////////////////////////////////////////////////////////
1009:   
1010:          /// <summary>
1011:          ///
1012:          /// </summary>
1013:          public static Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor> MigratedServiceToNddOntRouterVendorDictionary
1014:          {
1015:              get
1016:              {
1017:                  string key;
1018:                  Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor> dictionary;
1019:   
1020:                  var migratedServiceIdToAccessIdDictionary = Ia.Ngn.Cl.Model.Data.Service2.MigratedServiceIdToAccessIdDictionary;
1021:                  var ontAccessIdToOntDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntDictionary;
1022:   
1023:                  dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor>(migratedServiceIdToAccessIdDictionary.Count);
1024:   
1025:                  foreach (KeyValuePair<string, string> kvp in migratedServiceIdToAccessIdDictionary)
1026:                  {
1027:                      key = Ia.Ngn.Cl.Model.Business.Service.ServiceIdToService(kvp.Key);
1028:   
1029:                      //if (!string.IsNullOrEmpty(kvp.Value)) dictionary[key] = ontAccessIdToOntDictionary[kvp.Value];
1030:                      //else dictionary[key] = null;
1031:                  }
1032:   
1033:                  return dictionary;
1034:              }
1035:          }
1036:   
1037:          ////////////////////////////////////////////////////////////////////////////
1038:   
1039:          /// <summary>
1040:          ///
1041:          /// </summary>
1042:          public static Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site> ServiceToSiteDictionary
1043:          {
1044:              get
1045:              {
1046:                  int fourLetterServiceDomain, fiveLetterServiceDomain;
1047:                  string service;
1048:                  Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site> dictionary;
1049:   
1050:                  var serviceIdList = Ia.Ngn.Cl.Model.Data.Service2.ServiceIdList;
1051:                  var routerDomainToSiteDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.RouterDomainToSiteDictionary;
1052:   
1053:                  dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site>(serviceIdList.Count);
1054:   
1055:                  foreach (string s in serviceIdList)
1056:                  {
1057:                      service = Ia.Ngn.Cl.Model.Business.Service.ServiceIdToService(s);
1058:   
1059:                      if (service.Length >= 5)
1060:                      {
1061:                          fourLetterServiceDomain = int.Parse(service.Substring(0, 4));
1062:                          fiveLetterServiceDomain = int.Parse(service.Substring(0, 5));
1063:   
1064:                          if (routerDomainToSiteDictionary.ContainsKey(fiveLetterServiceDomain)) dictionary[service] = routerDomainToSiteDictionary[fiveLetterServiceDomain];
1065:                          else if (routerDomainToSiteDictionary.ContainsKey(fourLetterServiceDomain)) dictionary[service] = routerDomainToSiteDictionary[fourLetterServiceDomain];
1066:                          //else throw new System.ArgumentOutOfRangeException("Service number " + service + " is out of range");
1067:                      }
1068:                      //else throw new System.ArgumentOutOfRangeException("Service number " + service + " is out of range");
1069:                  }
1070:   
1071:                  return dictionary;
1072:              }
1073:          }
1074:   
1075:          ////////////////////////////////////////////////////////////////////////////
1076:   
1077:          /// <summary>
1078:          ///
1079:          /// </summary>
1080:          public static Dictionary<string, string> ServiceNotInServiceRequestServiceToSiteDictionary
1081:          {
1082:              get
1083:              {
1084:                  string service, siteName;
1085:                  Dictionary<string, string> dictionary;
1086:   
1087:                  var serviceToSiteNameDictionary = Ia.Ngn.Cl.Model.Data.Service2.ServiceToSiteDictionary;
1088:                  var serviceRequestServiceServiceToSiteNameDictionary = Ia.Ngn.Cl.Model.Data.ServiceRequestService.ServiceToSiteDictionary;
1089:   
1090:                  dictionary = new Dictionary<string, string>();
1091:   
1092:                  foreach (var kvp in serviceToSiteNameDictionary)
1093:                  {
1094:                      service = kvp.Key;
1095:                      siteName = kvp.Value.Name;
1096:   
1097:                      if (!serviceRequestServiceServiceToSiteNameDictionary.ContainsKey(service)) dictionary.Add(service, siteName);
1098:                  }
1099:   
1100:                  return dictionary;
1101:              }
1102:          }
1103:   
1104:          ////////////////////////////////////////////////////////////////////////////
1105:   
1106:          /// <summary>
1107:          ///
1108:          /// </summary>
1109:          public static Dictionary<string, string> ServiceNotInProvisionedServiceRequestServiceToSiteDictionary
1110:          {
1111:              get
1112:              {
1113:                  string service, siteName;
1114:                  Dictionary<string, string> dictionary;
1115:   
1116:                  var serviceToSiteNameDictionary = Ia.Ngn.Cl.Model.Data.Service2.ServiceToSiteDictionary;
1117:                  var serviceRequestServiceProvisionedServiceToSiteNameDictionary = Ia.Ngn.Cl.Model.Data.ServiceRequestService.ProvisionedServiceToSiteDictionary;
1118:   
1119:                  dictionary = new Dictionary<string, string>();
1120:   
1121:                  foreach (var kvp in serviceToSiteNameDictionary)
1122:                  {
1123:                      service = kvp.Key;
1124:                      siteName = kvp.Value.Name;
1125:   
1126:                      if (!serviceRequestServiceProvisionedServiceToSiteNameDictionary.ContainsKey(service)) dictionary.Add(service, siteName);
1127:                  }
1128:   
1129:                  return dictionary;
1130:              }
1131:          }
1132:   
1133:          ////////////////////////////////////////////////////////////////////////////
1134:   
1135:          /// <summary>
1136:          ///
1137:          /// </summary>
1138:          public static void UpdatePstnServiceAccess(string service, string newAccessId, Guid userId, out Ia.Cl.Model.Result result)
1139:          {
1140:              int serviceType;
1141:              string service2Id;
1142:              Ia.Ngn.Cl.Model.Service2 service2;
1143:   
1144:              result = new Ia.Cl.Model.Result();
1145:   
1146:              serviceType = Ia.Ngn.Cl.Model.Business.Service.ServiceType.PstnService; // PSTN
1147:              service2Id = Ia.Ngn.Cl.Model.Business.Service2.ServiceId(service, serviceType);
1148:   
1149:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
1150:              {
1151:                  service2 = (from s in db.Service2s where s.Id == service2Id select s).SingleOrDefault();
1152:   
1153:                  if (service2 != null)
1154:                  {
1155:                      if (!string.IsNullOrEmpty(newAccessId))
1156:                      {
1157:                          if (service2.Access == null || service2.Access != null && service2.Access.Id != newAccessId)
1158:                          {
1159:                              service2.Access = (from a in db.Accesses where a.Id == newAccessId select a).SingleOrDefault();
1160:                              service2.UserId = userId;
1161:   
1162:                              db.Service2s.Attach(service2);
1163:                              db.Entry(service2).State = System.Data.Entity.EntityState.Modified;
1164:   
1165:                              db.SaveChanges();
1166:   
1167:                              result.AddSuccess("Service " + service + " was updated with access " + service2.Access.Name + " (تم تحديث ربط الجهاز بالرقم). ");
1168:                          }
1169:                          else
1170:                          {
1171:                              result.AddWarning("Service access value was not updated because submitted data is the same as current data and because assess is not null (لم يتم تغيير الجهاز المربوط بالرقم لأن المعلومات المعطاة هي ذاتها لم تتغير ولأن الجهاز معرف). ");
1172:                          }
1173:                      }
1174:                      else //if(string.IsNullOrEmpty(updatedAccessId))
1175:                      {
1176:                          if (service2.Access != null)
1177:                          {
1178:                              service2.Access = (from a in db.Accesses where a.Id == string.Empty select a).SingleOrDefault();
1179:                              service2.Port = Ia.Ngn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown;
1180:                              service2.UserId = userId;
1181:   
1182:                              db.Service2s.Attach(service2);
1183:                              db.Entry(service2).State = System.Data.Entity.EntityState.Modified;
1184:   
1185:                              db.SaveChanges();
1186:   
1187:                              result.AddSuccess("Service " + service + " was updated with null access and " + Ia.Ngn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown + " port (تم مسح ربط الجهاز بالرقم ومسح المنفذ). ");
1188:                          }
1189:                          else
1190:                          {
1191:                              result.AddWarning("Service access and port values were not resetted because submitted data (access null and port " + Ia.Ngn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown + ") is the same as current data (لم يتم تغيير الجهاز المربوط بالرقم أو المنفذ لأن المعلومات المعطاة هي ذاتها لم تتغير). ");
1192:                          }
1193:                      }
1194:                  }
1195:                  else
1196:                  {
1197:                      result.AddWarning("Service " + service + " does not exist (رقم الخدمة غير موجود). ");
1198:                  }
1199:              }
1200:          }
1201:   
1202:          ////////////////////////////////////////////////////////////////////////////
1203:          ////////////////////////////////////////////////////////////////////////////
1204:      }
1205:   
1206:      ////////////////////////////////////////////////////////////////////////////
1207:      ////////////////////////////////////////////////////////////////////////////
1208:  }