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

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