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

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » ServiceRequestService

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

Service Request Service support class for Optical Fiber Network (OFN) data model.

   1:  using Ia.Ngn.Cl.Model.Business;
   2:  using Microsoft.EntityFrameworkCore;
   3:  using System;
   4:  using System.Collections.Generic;
   5:  using System.Data;
   6:  using System.Linq;
   7:   
   8:  namespace Ia.Ngn.Cl.Model.Data
   9:  {
  10:      ////////////////////////////////////////////////////////////////////////////
  11:   
  12:      /// <summary publish="true">
  13:      /// Service Request Service support class for Optical Fiber Network (OFN) data model.
  14:      /// </summary>
  15:      /// 
  16:      /// <remarks> 
  17:      /// Copyright © 2006-2022 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 class ServiceRequestService
  30:      {
  31:          /// <summary/>
  32:          public ServiceRequestService() { }
  33:   
  34:          ////////////////////////////////////////////////////////////////////////////
  35:   
  36:          /// <summary>
  37:          /// Read service
  38:          /// </summary>
  39:          public static Ia.Ngn.Cl.Model.ServiceRequestService Read(string service)
  40:          {
  41:              Ia.Ngn.Cl.Model.ServiceRequestService serviceRequestService;
  42:   
  43:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  44:              {
  45:                  serviceRequestService = (from srs in db.ServiceRequestServices
  46:                                           where srs.Service == service
  47:                                           select srs).SingleOrDefault();
  48:              }
  49:   
  50:              return serviceRequestService;
  51:          }
  52:   
  53:          ////////////////////////////////////////////////////////////////////////////
  54:   
  55:          /// <summary>
  56:          /// Read service
  57:          /// </summary>
  58:          public static Ia.Ngn.Cl.Model.ServiceRequestService ReadIncludeServiceRequests(string service)
  59:          {
  60:              Ia.Ngn.Cl.Model.ServiceRequestService serviceRequestService;
  61:   
  62:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  63:              {
  64:                  serviceRequestService = (from srs in db.ServiceRequestServices.Include(a => a.ServiceRequests) where srs.Service == service select srs).SingleOrDefault();
  65:              }
  66:   
  67:              return serviceRequestService;
  68:          }
  69:   
  70:          ////////////////////////////////////////////////////////////////////////////
  71:   
  72:          /// <summary>
  73:          /// Read service using id
  74:          /// </summary>
  75:          public static Ia.Ngn.Cl.Model.ServiceRequestService ReadById(string id)
  76:          {
  77:              Ia.Ngn.Cl.Model.ServiceRequestService serviceRequestService;
  78:   
  79:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  80:              {
  81:                  serviceRequestService = (from srs in db.ServiceRequestServices where srs.Id == id select srs).SingleOrDefault();
  82:              }
  83:   
  84:              return serviceRequestService;
  85:          }
  86:   
  87:          ////////////////////////////////////////////////////////////////////////////
  88:   
  89:          /// <summary>
  90:          /// Service request services within a SIP designated OLT
  91:          /// </summary>
  92:          public static List<Ia.Ngn.Cl.Model.ServiceRequestService> WithinSipOltList()
  93:          {
  94:              List<Ia.Ngn.Cl.Model.ServiceRequestService> list;
  95:   
  96:              var sipOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.SipOltIdList;
  97:   
  98:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  99:              {
 100:                  list = (from srs in db.ServiceRequestServices
 101:                          where srs.Access != null && sipOltIdList.Contains(srs.Access.Olt)
 102:                          select srs).Include(u => u.Access).ToList();
 103:              }
 104:   
 105:              return list;
 106:          }
 107:   
 108:          ////////////////////////////////////////////////////////////////////////////
 109:   
 110:          /// <summary>
 111:          /// Service request services within a designated OLT
 112:          /// </summary>
 113:          public static List<Ia.Ngn.Cl.Model.ServiceRequestService> WithinOltList(int oltId)
 114:          {
 115:              List<Ia.Ngn.Cl.Model.ServiceRequestService> list;
 116:   
 117:              if (oltId > 0)
 118:              {
 119:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 120:                  {
 121:                      list = (from srs in db.ServiceRequestServices.Include(a => a.Access)
 122:                              where srs.Access != null && srs.Access.Olt == oltId
 123:                              select srs).Include(u => u.Access).ToList();
 124:                  }
 125:              }
 126:              else list = new List<Ia.Ngn.Cl.Model.ServiceRequestService>();
 127:   
 128:              return list;
 129:          }
 130:   
 131:          ////////////////////////////////////////////////////////////////////////////
 132:   
 133:          /// <summary>
 134:          /// Services within a SIP designated OLT
 135:          /// </summary>
 136:          public static List<string> ServiceWithinSipOltList()
 137:          {
 138:              List<string> list;
 139:   
 140:              var sipOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.SipOltIdList;
 141:   
 142:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 143:              {
 144:                  list = (from srs in db.ServiceRequestServices
 145:                          where srs.Access != null && sipOltIdList.Contains(srs.Access.Olt)
 146:                          select srs.Service).ToList();
 147:              }
 148:   
 149:              return list;
 150:          }
 151:   
 152:          ////////////////////////////////////////////////////////////////////////////
 153:   
 154:          /// <summary>
 155:          /// Read service using id
 156:          /// </summary>
 157:          public static Ia.Ngn.Cl.Model.ServiceRequestService ReadIncludeAccess(string id)
 158:          {
 159:              Ia.Ngn.Cl.Model.ServiceRequestService serviceRequestService;
 160:   
 161:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 162:              {
 163:                  serviceRequestService = (from srs in db.ServiceRequestServices.Include(a => a.Access)
 164:                                           where srs.Id == id
 165:                                           select srs).AsNoTracking().SingleOrDefault();
 166:              }
 167:   
 168:              return serviceRequestService;
 169:          }
 170:   
 171:          ////////////////////////////////////////////////////////////////////////////
 172:   
 173:          /// <summary>
 174:          /// Read service of a number
 175:          /// </summary>
 176:          public static Ia.Ngn.Cl.Model.ServiceRequestService Read(long number)
 177:          {
 178:              Ia.Ngn.Cl.Model.ServiceRequestService serviceRequestService;
 179:   
 180:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 181:              {
 182:                  serviceRequestService = (from srs in db.ServiceRequestServices where srs.Service == number.ToString() select srs).SingleOrDefault();
 183:              }
 184:   
 185:              return serviceRequestService;
 186:          }
 187:   
 188:          /*
 189:          ////////////////////////////////////////////////////////////////////////////
 190:  
 191:          /// <summary>
 192:          /// Read all services for a number list
 193:          /// </summary>
 194:          public static List<Ia.Ngn.Cl.Model.ServiceRequestService> ReadList(ArrayList numberList)
 195:          {
 196:              long i;
 197:              long[] sp;
 198:              List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 199:  
 200:              i = 0;
 201:              sp = new long[numberList.Count];
 202:  
 203:              foreach (long l in numberList) sp[i++] = l;
 204:  
 205:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 206:              {
 207:                  //serviceList = (from q in db.Services where dnList.Contains(q.DN) select q).ToList();
 208:  
 209:                  // var pages = context.Pages.Where(x => keys.Any(key => x.Title.Contains(key)));
 210:                  serviceRequestServiceList = db.ServiceRequestServices.Where(q => sp.Any(v => q.Service == v.ToString())).ToList();
 211:              }
 212:  
 213:              return serviceRequestServiceList;
 214:          }
 215:          */
 216:   
 217:          ////////////////////////////////////////////////////////////////////////////
 218:   
 219:          /// <summary>
 220:          /// Update the service request service table with a list using a service list as referece 
 221:          /// </summary>
 222:          public static void UpdateWithServiceList(List<string> serviceList, List<Ia.Ngn.Cl.Model.ServiceRequestService> newServiceRequestServiceList, out string result)
 223:          {
 224:              int readItemCount, existingItemCount, insertedItemCount, updatedItemCount, deletedItemCount;
 225:              Ia.Ngn.Cl.Model.ServiceRequestService serviceRequestService, newServiceRequestService;
 226:   
 227:              readItemCount = existingItemCount = insertedItemCount = updatedItemCount = deletedItemCount = 0;
 228:              result = string.Empty;
 229:   
 230:              readItemCount = newServiceRequestServiceList.Count;
 231:   
 232:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 233:              {
 234:                  // Create SRS from newServiceRequestServiceList
 235:                  foreach (Ia.Ngn.Cl.Model.ServiceRequestService srs in newServiceRequestServiceList)
 236:                  {
 237:                      if (Ia.Ngn.Cl.Model.Business.Service.ServiceHasEightDigitsAndIsWithinAllowedDomainList(srs.Service))
 238:                      {
 239:                          newServiceRequestService = new Ia.Ngn.Cl.Model.ServiceRequestService();
 240:   
 241:                          newServiceRequestService.Copy(srs);
 242:   
 243:                          // important: ServiceRequestService.Update() will only update stored.Access if it is null, or (stored.userId == Guid.Empty && update.Id > stored.Id)
 244:                          if (srs.Access != null) newServiceRequestService.Access = (from a in db.Accesses
 245:                                                                                     where a.Id == srs.Access.Id
 246:                                                                                     select a).SingleOrDefault();
 247:                          else newServiceRequestService.Access = null;
 248:   
 249:                          serviceRequestService = (from srs2 in db.ServiceRequestServices
 250:                                                   where srs2.Id == srs.Id
 251:                                                   select srs2).Include(u => u.Access).SingleOrDefault();
 252:   
 253:                          if (serviceRequestService != null) existingItemCount++;
 254:   
 255:                          if (serviceRequestService == null)
 256:                          {
 257:                              newServiceRequestService.Created = newServiceRequestService.Updated = DateTime.UtcNow.AddHours(3);
 258:   
 259:                              db.ServiceRequestServices.Add(newServiceRequestService);
 260:   
 261:                              //Ia.Ngn.Cl.Model.Data.Msmq.ServiceQueue.Enqueue(newServiceRequestService.Service);
 262:                              //if (newServiceRequestService.Access != null) Ia.Ngn.Cl.Model.Data.Msmq.AccessNameQueue.Enqueue(newServiceRequestService.Access.Name);
 263:   
 264:                              insertedItemCount++;
 265:                          }
 266:                          else
 267:                          {
 268:                              // below: copy values from newServiceRequestService to serviceRequestService
 269:   
 270:                              if (serviceRequestService.Update(newServiceRequestService))
 271:                              {
 272:                                  db.ServiceRequestServices.Attach(serviceRequestService);
 273:                                  db.Entry(serviceRequestService).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
 274:   
 275:                                  //Ia.Ngn.Cl.Model.Data.Msmq.ServiceQueue.Enqueue(serviceRequestService.Service);
 276:                                  //if (serviceRequestService.Access != null) Ia.Ngn.Cl.Model.Data.Msmq.AccessNameQueue.Enqueue(serviceRequestService.Access.Name);
 277:   
 278:                                  updatedItemCount++;
 279:                              }
 280:   
 281:                          }
 282:                      }
 283:                      else
 284:                      {
 285:                          throw new System.ArgumentOutOfRangeException("Service " + srs.Service + " string format is not legal");
 286:                      }
 287:                  }
 288:   
 289:                  /*
 290:                  // remove SRS that were not present in newServiceRequestServiceList
 291:                  foreach (string service in serviceList)
 292:                  {
 293:                      newServiceRequestService = (from srs in newServiceRequestServiceList where srs.Service == service select srs).SingleOrDefault();
 294:  
 295:                      if (newServiceRequestService == null)
 296:                      {
 297:                          serviceRequestService = (from srs in db.ServiceRequestServices where srs.Service == service select srs).SingleOrDefault();
 298:  
 299:                          if (serviceRequestService != null)
 300:                          {
 301:                              // below: will set all references to this SRS from all SR to null
 302:  
 303:                              serviceRequestList = (from sr in db.ServiceRequests where sr.ServiceRequestService != null && sr.ServiceRequestService.Id == serviceRequestService.Id select sr).ToList();
 304:  
 305:                              foreach (Ia.Ngn.Cl.Model.ServiceRequest sr in serviceRequestList)
 306:                              {
 307:                                  //sr.ServiceRequestService = null;
 308:                              }
 309:  
 310:                              Ia.Ngn.Cl.Model.Data.Msmq.ServiceQueue.Enqueue(serviceRequestService.Service);
 311:                              if (serviceRequestService.Access != null) Ia.Ngn.Cl.Model.Data.Msmq.AccessNameQueue.Enqueue(serviceRequestService.Access.Name);
 312:  
 313:                              db.ServiceRequestServices.Remove(serviceRequestService); // I will not delete any SRS record
 314:  
 315:                              deletedItemCount++;
 316:                          }
 317:                      }
 318:                  }
 319:                  */
 320:   
 321:                  db.SaveChanges();
 322:   
 323:                  result = "(" + readItemCount + "/" + existingItemCount + "/" + insertedItemCount + "," + updatedItemCount + "," + deletedItemCount + ") ";
 324:              }
 325:          }
 326:   
 327:          /*
 328:          ////////////////////////////////////////////////////////////////////////////
 329:  
 330:          /// <summary>
 331:          /// Update the ServiceRequestService table's ServiceSuspension and ServiceSuspensionTypeId to the specified state for a number list
 332:          /// </summary>
 333:          public static bool UpdateServiceSuspensionAndServiceSuspensionTypeIdToSpecifiedSuspensionStateForAServiceStringList(List<string> serviceList, bool state, Guid userId)
 334:          {
 335:              bool b;
 336:              Ia.Ngn.Cl.Model.ServiceRequestService serviceRequestService;
 337:  
 338:              b = false;
 339:  
 340:              if (serviceList.Count > 0)
 341:              {
 342:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 343:                  {
 344:                      // below:
 345:                      foreach (string service in serviceList)
 346:                      {
 347:                          serviceRequestService = (from q in db.ServiceRequestServices where q.Service == service select q).SingleOrDefault();
 348:  
 349:                          if (serviceRequestService != null)
 350:                          {
 351:                              if (serviceRequestService.ServiceSuspension != state)
 352:                              {
 353:                                  serviceRequestService.ServiceSuspension = state;
 354:                                  serviceRequestService.Updated = DateTime.UtcNow.AddHours(3);
 355:                                  serviceRequestService.UserId = userId;
 356:  
 357:                                  db.ServiceRequestServices.Attach(serviceRequestService);
 358:                                  db.Entry(serviceRequestService).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
 359:  
 360:                                  b = true;
 361:                              }
 362:                          }
 363:                      }
 364:  
 365:                      db.SaveChanges();
 366:                  }
 367:              }
 368:              else
 369:              {
 370:              }
 371:  
 372:              return b;
 373:          }
 374:          */
 375:   
 376:          ////////////////////////////////////////////////////////////////////////////
 377:   
 378:          /// <summary>
 379:          ///
 380:          /// </summary>
 381:          public static List<Ia.Ngn.Cl.Model.ServiceRequestService> ReadSingleAsList(string id)
 382:          {
 383:              List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 384:   
 385:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 386:              {
 387:                  serviceRequestServiceList = (from srs in db.ServiceRequestServices where srs.Id == id select srs).ToList();
 388:              }
 389:   
 390:              return serviceRequestServiceList;
 391:          }
 392:   
 393:          ////////////////////////////////////////////////////////////////////////////
 394:   
 395:          /// <summary>
 396:          ///
 397:          /// </summary>
 398:          public static List<string> ServiceList()
 399:          {
 400:              List<string> list;
 401:   
 402:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 403:              {
 404:                  list = (from srs in db.ServiceRequestServices select srs.Service).ToList();
 405:              }
 406:   
 407:              return list;
 408:          }
 409:   
 410:          ////////////////////////////////////////////////////////////////////////////
 411:   
 412:          /// <summary>
 413:          ///
 414:          /// </summary>
 415:          public static Dictionary<string, string> ServiceDictionary()
 416:          {
 417:              Dictionary<string, string> dictionary;
 418:   
 419:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 420:              {
 421:                  dictionary = (from srs in db.ServiceRequestServices
 422:                                select new { srs.Service }).AsNoTracking().ToDictionary(u => u.Service, u => u.Service);
 423:              }
 424:   
 425:              return dictionary.ToDictionary(u => u.Key, u => u.Value);
 426:          }
 427:   
 428:          ////////////////////////////////////////////////////////////////////////////
 429:   
 430:          /// <summary>
 431:          ///
 432:          /// </summary>
 433:          public static List<string> ServiceIdList
 434:          {
 435:              get
 436:              {
 437:                  List<string> list;
 438:   
 439:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 440:                  {
 441:                      list = (from srs in db.ServiceRequestServices select srs.Id).ToList();
 442:                  }
 443:   
 444:                  return list;
 445:              }
 446:          }
 447:   
 448:          ////////////////////////////////////////////////////////////////////////////
 449:   
 450:          /// <summary>
 451:          ///
 452:          /// </summary>
 453:          public static List<Ia.Ngn.Cl.Model.ServiceRequestService> List()
 454:          {
 455:              List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 456:   
 457:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 458:              {
 459:                  serviceRequestServiceList = (from srs in db.ServiceRequestServices select srs).ToList();
 460:              }
 461:   
 462:              return serviceRequestServiceList;
 463:          }
 464:   
 465:          ////////////////////////////////////////////////////////////////////////////
 466:   
 467:          /// <summary>
 468:          ///
 469:          /// </summary>
 470:          public static List<Ia.Ngn.Cl.Model.ServiceRequestService> List(string service)
 471:          {
 472:              List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 473:   
 474:              if (!string.IsNullOrEmpty(service))
 475:              {
 476:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 477:                  {
 478:                      serviceRequestServiceList = (from srs in db.ServiceRequestServices where srs.Service == service select srs).ToList();
 479:                  }
 480:              }
 481:              else serviceRequestServiceList = new List<Model.ServiceRequestService>();
 482:   
 483:              return serviceRequestServiceList;
 484:          }
 485:   
 486:          ////////////////////////////////////////////////////////////////////////////
 487:   
 488:          /// <summary>
 489:          ///
 490:          /// </summary>
 491:          public static List<Ia.Ngn.Cl.Model.ServiceRequestService> ListIncludeAccess()
 492:          {
 493:              List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 494:   
 495:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 496:              {
 497:                  serviceRequestServiceList = (from srs in db.ServiceRequestServices select srs).Include(u => u.Access).ToList();
 498:              }
 499:   
 500:              return serviceRequestServiceList;
 501:          }
 502:   
 503:          ////////////////////////////////////////////////////////////////////////////
 504:   
 505:          /// <summary>
 506:          /// 
 507:          /// </summary>
 508:          public static List<Ia.Ngn.Cl.Model.Ui.ServiceRequestService> UiServiceRequestServiceList()
 509:          {
 510:              List<Ia.Ngn.Cl.Model.ServiceRequestService> srsList;
 511:              List<Ia.Ngn.Cl.Model.Ui.ServiceRequestService> list;
 512:   
 513:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 514:              {
 515:                  srsList = (from srs in db.ServiceRequestServices select srs).ToList();
 516:   
 517:                  list = (from srs in srsList
 518:                          select new Ia.Ngn.Cl.Model.Ui.ServiceRequestService()
 519:                          {
 520:                              Id = srs.Id,
 521:                              AbbriviatedCalling = srs.AbbriviatedCalling,
 522:                              Access = srs.Access,
 523:                              AlarmCall = srs.AlarmCall,
 524:                              CallBarring = srs.CallBarring,
 525:                              CallerId = srs.CallerId,
 526:                              CallForwarding = srs.CallForwarding,
 527:                              CallWaiting = srs.CallWaiting,
 528:                              ConferenceCall = srs.ConferenceCall,
 529:                              Created = srs.Created,
 530:                              InternationalCalling = srs.InternationalCalling,
 531:                              InternationalCallingUserControlled = srs.InternationalCallingUserControlled,
 532:                              LastRequestDateTime = srs.LastRequestDateTime,
 533:                              Provisioned = srs.Provisioned,
 534:                              Service = srs.Service,
 535:                              Serial = srs.Serial,
 536:                              ServiceType = srs.ServiceType,
 537:                              //ServiceSuspension = srs.ServiceSuspension,
 538:                              Type = srs.Type,
 539:                              Updated = srs.Updated
 540:                          }).ToList();
 541:   
 542:                  return list.Distinct().ToList();
 543:              }
 544:          }
 545:   
 546:          ////////////////////////////////////////////////////////////////////////////
 547:   
 548:          /// <summary>
 549:          /// 
 550:          /// </summary>
 551:          public static List<Ia.Ngn.Cl.Model.Ui.ServiceRequestService> UiServiceRequestServiceList(string service)
 552:          {
 553:              List<Ia.Ngn.Cl.Model.ServiceRequestService> srsList;
 554:              List<Ia.Ngn.Cl.Model.Ui.ServiceRequestService> list;
 555:   
 556:              if (!string.IsNullOrEmpty(service))
 557:              {
 558:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 559:                  {
 560:                      srsList = (from srs in db.ServiceRequestServices where srs.Service == service select srs).Include(u => u.Access).ToList();
 561:   
 562:                      list = (from srs in srsList
 563:                              select new Ia.Ngn.Cl.Model.Ui.ServiceRequestService()
 564:                              {
 565:                                  Id = srs.Id,
 566:                                  AbbriviatedCalling = srs.AbbriviatedCalling,
 567:                                  Access = srs.Access,
 568:                                  AlarmCall = srs.AlarmCall,
 569:                                  CallBarring = srs.CallBarring,
 570:                                  CallerId = srs.CallerId,
 571:                                  CallForwarding = srs.CallForwarding,
 572:                                  CallWaiting = srs.CallWaiting,
 573:                                  ConferenceCall = srs.ConferenceCall,
 574:                                  Created = srs.Created,
 575:                                  InternationalCalling = srs.InternationalCalling,
 576:                                  InternationalCallingUserControlled = srs.InternationalCallingUserControlled,
 577:                                  LastRequestDateTime = srs.LastRequestDateTime,
 578:                                  Provisioned = srs.Provisioned,
 579:                                  Service = srs.Service,
 580:                                  Serial = srs.Serial,
 581:                                  ServiceType = srs.ServiceType,
 582:                                  //ServiceSuspension = srs.ServiceSuspension,
 583:                                  Type = srs.Type,
 584:                                  Updated = srs.Updated
 585:                              }).ToList();
 586:                  }
 587:              }
 588:              else list = new List<Ia.Ngn.Cl.Model.Ui.ServiceRequestService>();
 589:   
 590:              return list.Distinct().ToList();
 591:          }
 592:   
 593:          ////////////////////////////////////////////////////////////////////////////
 594:   
 595:          /// <summary>
 596:          /// 
 597:          /// </summary>
 598:          public static List<Ia.Ngn.Cl.Model.Business.ServiceSerialRequestService> ServiceSerialRequestServiceList()
 599:          {
 600:              List<Ia.Ngn.Cl.Model.ServiceRequestService> srsList;
 601:              List<Ia.Ngn.Cl.Model.Business.ServiceSerialRequestService> list;
 602:   
 603:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 604:              {
 605:                  srsList = (from srs in db.ServiceRequestServices select srs).ToList();
 606:   
 607:                  list = (from srs in srsList
 608:                          select new Ia.Ngn.Cl.Model.Business.ServiceSerialRequestService()
 609:                          {
 610:                              Id = srs.Service + ":" + srs.Serial,
 611:                              AbbriviatedCalling = srs.AbbriviatedCalling,
 612:                              //Access = srs.Access,
 613:                              AlarmCall = srs.AlarmCall,
 614:                              WakeupCall = srs.WakeupCall,
 615:                              CallBarring = srs.CallBarring,
 616:                              CallerId = srs.CallerId,
 617:                              CallForwarding = srs.CallForwarding,
 618:                              CallWaiting = srs.CallWaiting,
 619:                              ConferenceCall = srs.ConferenceCall,
 620:                              InternationalCalling = srs.InternationalCalling,
 621:                              InternationalCallingUserControlled = srs.InternationalCallingUserControlled,
 622:                              Provisioned = srs.Provisioned,
 623:                              Service = srs.Service,
 624:                              Serial = srs.Serial,
 625:                          }).ToList();
 626:   
 627:                  return list.Distinct().ToList();
 628:              }
 629:          }
 630:   
 631:          ////////////////////////////////////////////////////////////////////////////
 632:   
 633:          /// <summary>
 634:          /// 
 635:          /// </summary>
 636:          public static List<Ia.Ngn.Cl.Model.Business.ServiceSerialRequestService> ServiceSerialRequestServiceList(string service)
 637:          {
 638:              List<Ia.Ngn.Cl.Model.ServiceRequestService> srsList;
 639:              List<Ia.Ngn.Cl.Model.Business.ServiceSerialRequestService> list;
 640:   
 641:              if (!string.IsNullOrEmpty(service))
 642:              {
 643:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 644:                  {
 645:                      srsList = (from srs in db.ServiceRequestServices where srs.Service == service select srs).ToList();
 646:   
 647:                      list = (from srs in srsList
 648:                              select new Ia.Ngn.Cl.Model.Business.ServiceSerialRequestService()
 649:                              {
 650:                                  Id = srs.Service + ":" + srs.Serial,
 651:                                  AbbriviatedCalling = srs.AbbriviatedCalling,
 652:                                  //Access = srs.Access,
 653:                                  AlarmCall = srs.AlarmCall,
 654:                                  WakeupCall = srs.WakeupCall,
 655:                                  CallBarring = srs.CallBarring,
 656:                                  CallerId = srs.CallerId,
 657:                                  CallForwarding = srs.CallForwarding,
 658:                                  CallWaiting = srs.CallWaiting,
 659:                                  ConferenceCall = srs.ConferenceCall,
 660:                                  InternationalCalling = srs.InternationalCalling,
 661:                                  InternationalCallingUserControlled = srs.InternationalCallingUserControlled,
 662:                                  Provisioned = srs.Provisioned,
 663:                                  Service = srs.Service,
 664:                                  Serial = srs.Serial,
 665:                              }).ToList();
 666:                  }
 667:              }
 668:              else list = new List<Ia.Ngn.Cl.Model.Business.ServiceSerialRequestService>();
 669:   
 670:              return list.Distinct().ToList();
 671:          }
 672:   
 673:          ////////////////////////////////////////////////////////////////////////////
 674:          ////////////////////////////////////////////////////////////////////////////
 675:   
 676:          /// <summary>
 677:          ///
 678:          /// </summary>
 679:          public static Dictionary<string, string> ServiceIdToAccessIdDictionary
 680:          {
 681:              get
 682:              {
 683:                  Dictionary<string, string> dictionary, nullAccessDictionary;
 684:   
 685:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 686:                  {
 687:                      dictionary = (from srs in db.ServiceRequestServices where srs.Access != null select new { srs.Id, srs.Access }).ToDictionary(u => u.Id, u => u.Access.Id);
 688:                      nullAccessDictionary = (from s in db.ServiceRequestServices where s.Access == null select new { s.Id, s.Access }).ToDictionary(u => u.Id, u => string.Empty);
 689:                  }
 690:   
 691:                  return dictionary.Union(nullAccessDictionary).ToDictionary(u => u.Key, u => u.Value);
 692:              }
 693:          }
 694:   
 695:          ////////////////////////////////////////////////////////////////////////////
 696:   
 697:          /// <summary>
 698:          ///
 699:          /// </summary>
 700:          public static Dictionary<string, string> ServiceToAccessIdDictionary
 701:          {
 702:              get
 703:              {
 704:                  string key;
 705:                  Dictionary<string, string> serviceToAccessIdDictionary, serviceIdToAccessIdDictionary;
 706:   
 707:                  serviceIdToAccessIdDictionary = Ia.Ngn.Cl.Model.Data.ServiceRequestService.ServiceIdToAccessIdDictionary;
 708:   
 709:                  serviceToAccessIdDictionary = new Dictionary<string, string>(serviceIdToAccessIdDictionary.Count);
 710:   
 711:                  foreach (KeyValuePair<string, string> kvp in serviceIdToAccessIdDictionary)
 712:                  {
 713:                      key = Ia.Ngn.Cl.Model.Business.ServiceRequestService.ServiceIdToService(kvp.Key);
 714:   
 715:                      serviceToAccessIdDictionary[key] = kvp.Value;
 716:                  }
 717:   
 718:                  return serviceToAccessIdDictionary;
 719:              }
 720:          }
 721:   
 722:          ////////////////////////////////////////////////////////////////////////////
 723:   
 724:          /// <summary>
 725:          ///
 726:          /// </summary>
 727:          public static List<string> ProvisionedServiceIdList
 728:          {
 729:              get
 730:              {
 731:                  List<string> serviceRequestServiceList;
 732:   
 733:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 734:                  {
 735:                      serviceRequestServiceList = (from srs in db.ServiceRequestServices
 736:                                                   where srs.Provisioned == true
 737:                                                   select srs.Id).ToList();
 738:                  }
 739:   
 740:                  return serviceRequestServiceList;
 741:              }
 742:          }
 743:   
 744:          ////////////////////////////////////////////////////////////////////////////
 745:   
 746:          /// <summary>
 747:          ///
 748:          /// </summary>
 749:          public static List<string> ProvisionedWithCallBarringServiceList()
 750:          {
 751:              List<string> serviceRequestServiceList;
 752:   
 753:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 754:              {
 755:                  serviceRequestServiceList = (from srs in db.ServiceRequestServices
 756:                                               where srs.Provisioned == true && srs.CallBarring == true
 757:                                               select srs.Service).ToList();
 758:              }
 759:   
 760:              return serviceRequestServiceList;
 761:          }
 762:   
 763:          ////////////////////////////////////////////////////////////////////////////
 764:   
 765:          /// <summary>
 766:          ///
 767:          /// </summary>
 768:          public static Dictionary<string, string> ProvisionedServiceIdToAccessIdDictionary
 769:          {
 770:              get
 771:              {
 772:                  Dictionary<string, string> dictionary, nullAccessDictionary;
 773:   
 774:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 775:                  {
 776:                      dictionary = (from srs in db.ServiceRequestServices
 777:                                    where srs.Provisioned == true && srs.Access != null
 778:                                    select new { srs.Id, srs.Access }).AsNoTracking().ToDictionary(u => u.Id, u => u.Access.Id);
 779:   
 780:                      nullAccessDictionary = (from s in db.ServiceRequestServices
 781:                                              where s.Provisioned == true && s.Access == null
 782:                                              select new { s.Id, s.Access }).AsNoTracking().ToDictionary(u => u.Id, u => string.Empty);
 783:                  }
 784:   
 785:                  return dictionary.Union(nullAccessDictionary).ToDictionary(u => u.Key, u => u.Value);
 786:              }
 787:          }
 788:   
 789:          ////////////////////////////////////////////////////////////////////////////
 790:   
 791:          /// <summary>
 792:          ///
 793:          /// </summary>
 794:          public static Dictionary<string, string> ProvisionedServiceToAccessIdDictionary
 795:          {
 796:              get
 797:              {
 798:                  string key;
 799:                  Dictionary<string, string> serviceToAccessIdDictionary, serviceIdToAccessIdDictionary;
 800:   
 801:                  serviceIdToAccessIdDictionary = Ia.Ngn.Cl.Model.Data.ServiceRequestService.ProvisionedServiceIdToAccessIdDictionary;
 802:   
 803:                  serviceToAccessIdDictionary = new Dictionary<string, string>(serviceIdToAccessIdDictionary.Count);
 804:   
 805:                  foreach (KeyValuePair<string, string> kvp in serviceIdToAccessIdDictionary)
 806:                  {
 807:                      key = Ia.Ngn.Cl.Model.Business.ServiceRequestService.ServiceIdToService(kvp.Key);
 808:   
 809:                      serviceToAccessIdDictionary[key] = kvp.Value;
 810:                  }
 811:   
 812:                  return serviceToAccessIdDictionary;
 813:              }
 814:          }
 815:   
 816:          ////////////////////////////////////////////////////////////////////////////
 817:          ////////////////////////////////////////////////////////////////////////////
 818:   
 819:          /// <summary>
 820:          /// 
 821:          /// </summary>
 822:          public static Dictionary<string, Ia.Ngn.Cl.Model.ServiceRequestService> ServiceToServiceRequestServiceDictionary(List<int> domainList)
 823:          {
 824:              string key;
 825:              List<string> stringDomainList;
 826:              List<Ia.Ngn.Cl.Model.ServiceRequestService> list;
 827:              Dictionary<string, Ia.Ngn.Cl.Model.ServiceRequestService> dictionary;
 828:   
 829:              stringDomainList = new List<string>();
 830:   
 831:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 832:              {
 833:                  if (domainList.Count > 0)
 834:                  {
 835:                      foreach (int i in domainList) stringDomainList.Add(i.ToString());
 836:   
 837:                      list = (from srs in db.ServiceRequestServices.Include(a => a.ServiceRequests).ThenInclude(u => u.ServiceRequestTypes)
 838:                              where stringDomainList.Any(u => srs.Service.StartsWith(u.ToString()))
 839:                              select srs).ToList();
 840:   
 841:                      dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.ServiceRequestService>(list.Count);
 842:   
 843:                      foreach (var srs in list)
 844:                      {
 845:                          key = srs.Service;
 846:   
 847:                          if (dictionary.ContainsKey(key))
 848:                          {
 849:                              dictionary[key] = srs;
 850:                          }
 851:                          else dictionary[key] = srs;
 852:                      }
 853:                  }
 854:                  else dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.ServiceRequestService>();
 855:              }
 856:   
 857:              return dictionary;
 858:          }
 859:   
 860:          /*
 861:          ////////////////////////////////////////////////////////////////////////////
 862:  
 863:          /// <summary>
 864:          ///
 865:          /// </summary>
 866:          public static void UpdateServiceSuspension(string service, bool serviceSuspensionState, Guid userId, out Ia.Cl.Model.Result result)
 867:          {
 868:              string serviceRequestServiceId;
 869:              Ia.Ngn.Cl.Model.ServiceRequestService serviceRequestService;
 870:  
 871:              result = new Ia.Cl.Model.Result();
 872:              serviceRequestServiceId = Ia.Ngn.Cl.Model.Business.ServiceRequestService.ServiceRequestServiceId(service, Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService);
 873:  
 874:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 875:              {
 876:                  serviceRequestService = (from srs in db.ServiceRequestServices
 877:                                           where srs.Id == serviceRequestServiceId
 878:                                           select srs).SingleOrDefault();
 879:  
 880:                  if (serviceRequestService != null)
 881:                  {
 882:                      if (serviceRequestService.ServiceSuspension != serviceSuspensionState)
 883:                      {
 884:                          serviceRequestService.ServiceSuspension = serviceSuspensionState;
 885:                          serviceRequestService.Updated = DateTime.UtcNow.AddHours(3);
 886:                          serviceRequestService.UserId = userId;
 887:  
 888:                          db.ServiceRequestServices.Attach(serviceRequestService);
 889:                          db.Entry(serviceRequestService).Property(u => u.ServiceSuspension).IsModified = true;
 890:  
 891:                          db.SaveChanges();
 892:  
 893:                          result.AddSuccess("ServiceSuspension updated. ");
 894:                      }
 895:                      else
 896:                      {
 897:                          result.AddWarning("Warning: ServiceRequestService ServiceSuspension value was not updated because its the same. ");
 898:                      }
 899:                  }
 900:                  else
 901:                  {
 902:                      result.AddError("Error: serviceRequestService is null. ");
 903:                  }
 904:              }
 905:          }
 906:          */
 907:   
 908:          /*
 909:          ////////////////////////////////////////////////////////////////////////////
 910:  
 911:          /// <summary>
 912:          ///
 913:          /// </summary>
 914:          public static Dictionary<string, string> ReadServiceAndOntNameDictionaryWithFourDigitNumberDomain(int fourDigitNumberDomain)
 915:          {
 916:              string s;
 917:              Dictionary<string, string> dictionary;
 918:  
 919:              dictionary = new Dictionary<string, string>(10000);
 920:  
 921:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 922:              {
 923:                  var list = (from srs in db.ServiceRequestServices
 924:                              where SqlFunctions.PatIndex(fourDigitNumberDomain.ToString() + "%", srs.Service) > 0
 925:                              orderby srs.Service ascending
 926:                              select new
 927:                              {
 928:                                  Service = srs.Service,
 929:                                  Access = srs.Access
 930:                              }).ToList();
 931:  
 932:                  foreach (var v in list)
 933:                  {
 934:                      if (v.Access != null) s = v.Service + " (" + v.Access.Name + ")";
 935:                      else s = v.Service;
 936:  
 937:                      dictionary[v.Service] = s;
 938:                  }
 939:              }
 940:  
 941:              return dictionary;
 942:          }
 943:          */
 944:   
 945:          ////////////////////////////////////////////////////////////////////////////
 946:   
 947:          /// <summary>
 948:          ///
 949:          /// </summary>
 950:          public static List<Ia.Ngn.Cl.Model.ServiceRequestService> ReadListOfServiceRequestServicesWithSimilarServiceNumbers(List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList)
 951:          {
 952:              List<string> serviceList;
 953:              List<Ia.Ngn.Cl.Model.ServiceRequestService> list;
 954:   
 955:              if (serviceRequestList.Count > 0)
 956:              {
 957:                  serviceList = new List<string>();
 958:   
 959:                  foreach (Ia.Ngn.Cl.Model.ServiceRequest serviceRequest in serviceRequestList) serviceList.Add(serviceRequest.Number.ToString());
 960:   
 961:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 962:                  {
 963:                      list = (from srs in db.ServiceRequestServices where serviceList.Contains(srs.Service) select srs).ToList();
 964:                  }
 965:              }
 966:              else list = new List<Ia.Ngn.Cl.Model.ServiceRequestService>();
 967:   
 968:              return list;
 969:          }
 970:   
 971:          ////////////////////////////////////////////////////////////////////////////    
 972:   
 973:          /// <summary>
 974:          ///
 975:          /// </summary>
 976:          public static List<string> ServiceStringList()
 977:          {
 978:              List<string> serviceStringList;
 979:   
 980:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 981:              {
 982:                  serviceStringList = (from srs in db.ServiceRequestServices
 983:                                       where srs.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService
 984:                                       orderby srs.Service ascending
 985:                                       select srs.Service).ToList();
 986:              }
 987:   
 988:              return serviceStringList;
 989:          }
 990:   
 991:          ////////////////////////////////////////////////////////////////////////////    
 992:   
 993:          /// <summary>
 994:          ///
 995:          /// </summary>
 996:          public static List<string> ServiceWithProvisionedTrueAndNonNullAccessList()
 997:          {
 998:              List<string> list;
 999:   
            using (var db = new Ia.Ngn.Cl.Model.Ngn())
            {
                list = (from srs in db.ServiceRequestServices
                        where srs.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && srs.Provisioned == true && srs.Access != null
                        orderby srs.Service ascending
                        select srs.Service).ToList();
            }
 
            return list;
        }
 
        ////////////////////////////////////////////////////////////////////////////    
 
        /// <summary>
        ///
        /// </summary>
        public static List<string> ServiceWithProvisionedTrueAndNullAccessList()
        {
            List<string> list;
 
            using (var db = new Ia.Ngn.Cl.Model.Ngn())
            {
                list = (from srs in db.ServiceRequestServices
                        where srs.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService && srs.Provisioned == true && srs.Access == null
                        orderby srs.Service ascending
                        select srs.Service).ToList();
            }
 
            return list;
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static List<Ia.Ngn.Cl.Model.ServiceRequestService> WithNullAccessList()
        {
            List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 
            using (var db = new Ia.Ngn.Cl.Model.Ngn())
            {
                // below: Take(100) temp
                serviceRequestServiceList = (from srs in db.ServiceRequestServices
                                             where srs.Access == null
                                             orderby srs.Service ascending
                                             select srs).Take(100).ToList();
            }
 
            return serviceRequestServiceList;
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static bool HasInternationalCalling(string service)
        {
            return InternationalCallingIsAssigned(service);
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static bool InternationalCallingIsAssigned(string service)
        {
            bool isAssigned;
 
            using (var db = new Ia.Ngn.Cl.Model.Ngn())
            {
                isAssigned = (from s in db.ServiceRequestServices
                              where s.Service == service && s.InternationalCalling == true
                              select s.Service).Any();
            }
 
            return isAssigned;
        }
 
        /*
        ////////////////////////////////////////////////////////////////////////////
        /// <summary>
        ///
        /// </summary>
        public static List<Ia.Ngn.Cl.Model.ServiceRequestService> ServiceSuspensionIsTrueAndProvisionedIsTrueList()
        {
            List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
            using (var db = new Ia.Ngn.Cl.Model.Ngn())
            {
                serviceRequestServiceList = (from s in db.ServiceRequestServices where s.ServiceSuspension == true && s.Provisioned == true select s).ToList();
            }
            return serviceRequestServiceList;
        }
        ////////////////////////////////////////////////////////////////////////////
        /// <summary>
        ///
        /// </summary>
        public static List<Ia.Ngn.Cl.Model.ServiceRequestService> ServiceSuspensionIsFalseList()
        {
            List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
            using (var db = new Ia.Ngn.Cl.Model.Ngn())
            {
                serviceRequestServiceList = (from s in db.ServiceRequestServices where s.ServiceSuspension == false select s).ToList();
            }
            return serviceRequestServiceList;
        }
        ////////////////////////////////////////////////////////////////////////////
        /// <summary>
        ///
        /// </summary>
        public static List<string> ServiceSuspensionIsTrueAndProvisionedIsTrueStringNumberList
        {
            get
            {
                List<string> serviceRequestServiceNumberStringList;
                List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
                using (var db = new Ia.Ngn.Cl.Model.Ngn())
                {
                    // below:                
                    serviceRequestServiceList = ServiceSuspensionIsTrueAndProvisionedIsTrueList();
                    if (serviceRequestServiceList.Count > 0)
                    {
                        serviceRequestServiceNumberStringList = new List<string>(serviceRequestServiceList.Count);
                        foreach (Ia.Ngn.Cl.Model.ServiceRequestService srs in serviceRequestServiceList)
                        {
                            serviceRequestServiceNumberStringList.Add(srs.Service);
                        }
                    }
                    else
                    {
                        // below: not null
                        serviceRequestServiceNumberStringList = new List<string>(1);
                    }
                }
                return serviceRequestServiceNumberStringList;
            }
        }
        ////////////////////////////////////////////////////////////////////////////
        /// <summary>
        ///
        /// </summary>
        public static List<string> ServiceSuspensionIsFalseStringNumberList
        {
            get
            {
                List<string> serviceRequestServiceNumberStringList;
                List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
                using (var db = new Ia.Ngn.Cl.Model.Ngn())
                {
                    // below:                
                    serviceRequestServiceList = ServiceSuspensionIsFalseList();
                    if (serviceRequestServiceList.Count > 0)
                    {
                        serviceRequestServiceNumberStringList = new List<string>(serviceRequestServiceList.Count);
                        foreach (Ia.Ngn.Cl.Model.ServiceRequestService srs in serviceRequestServiceList)
                        {
                            serviceRequestServiceNumberStringList.Add(srs.Service);
                        }
                    }
                    else
                    {
                        // below: not null
                        serviceRequestServiceNumberStringList = new List<string>(1);
                    }
                }
                return serviceRequestServiceNumberStringList;
            }
        }
        */
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static List<Ia.Ngn.Cl.Model.ServiceRequestService> ServiceRequestServiceWithNullAccessList
        {
            get
            {
                List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 
                using (var db = new Ia.Ngn.Cl.Model.Ngn())
                {
                    serviceRequestServiceList = (from srs in db.ServiceRequestServices where srs.Access == null select srs).ToList();
                }
 
                return serviceRequestServiceList;
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static List<string> ServiceRequestServiceServiceIdWhereProvisionedIsTrueAndAccessIsNullList()
        {
            List<string> list;
 
            using (var db = new Ia.Ngn.Cl.Model.Ngn())
            {
                list = (from srs in db.ServiceRequestServices where srs.Provisioned == true && srs.Access == null select srs.Id).ToList();
            }
 
            return list;
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static List<Ia.Ngn.Cl.Model.ServiceRequestService> ProvisionedWithinSiteList(int siteId)
        {
            List<Ia.Ngn.Cl.Model.ServiceRequestService> list;
 
            var site = (from s in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.SiteList
                        where s.Id == siteId
                        select s).SingleOrDefault();
 
            if (site != null)
            {
                var siteRouterDomainList = (from r in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.RouterList
                                            where r.Site.Id == site.Id
                                            select r).SelectMany(d => d.DomainList).ToList();
 
                using (var db = new Ia.Ngn.Cl.Model.Ngn())
                {
                    var list0 = (from srs in db.ServiceRequestServices
                                 where srs.Provisioned == true
                                 select srs).Include(u => u.Access).ToList();
 
                    list = (from srs in list0
                            where siteRouterDomainList.Any(u => srs.Service.StartsWith(u.ToString()))
                            select srs).ToList();
                }
            }
            else
            {
                list = new List<Model.ServiceRequestService>();
            }
 
            return list;
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static bool NullifyAccessIdByAccessId(string accessId, out string result)
        {
            bool b;
            int numberOfRecordsWhereAccessIsNullified;
            Ia.Ngn.Cl.Model.ServiceRequestService serviceRequestService;
 
            b = false;
            numberOfRecordsWhereAccessIsNullified = 0;
 
            using (var db = new Ia.Ngn.Cl.Model.Ngn())
            {
                // --update ServiceRequestServices set Access_Id = null where Access_Id = '1040101010040004'
                //var query = (from srs in db.ServiceRequestServices where srs.Access.Id == accessId select srs).ToList();
 
                //foreach (var v in query)
                //{
                serviceRequestService = (from srs in db.ServiceRequestServices where srs.Access.Id == accessId select srs).Include(u => u.Access).FirstOrDefault(); //.SingleOrDefault();
 
                if (serviceRequestService != null)
                {
                    serviceRequestService.Access = null;
                    serviceRequestService.Updated = DateTime.UtcNow.AddHours(3);
 
                    db.ServiceRequestServices.Attach(serviceRequestService);
                    db.Entry(serviceRequestService).Property(u => u.Updated).IsModified = true;
 
                    db.SaveChanges();
 
                    numberOfRecordsWhereAccessIsNullified++;
                }
                //}
 
                b = true;
            }
 
            result = "Number of records where access is nullified: " + numberOfRecordsWhereAccessIsNullified;
 
            return b;
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static void UpdateServiceRequestServiceAccess(string service, string updatedAccessId, Guid userId, out Ia.Cl.Model.Result result)
        {
            bool saveUpdate;
            string serviceRequestServiceId;
            Ia.Ngn.Cl.Model.ServiceRequestService serviceRequestService;
 
            saveUpdate = false;
            result = new Ia.Cl.Model.Result();
            serviceRequestServiceId = Ia.Ngn.Cl.Model.Business.ServiceRequestService.ServiceRequestServiceId(service, Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService);
 
            using (var db = new Ia.Ngn.Cl.Model.Ngn())
            {
                serviceRequestService = (from srs in db.ServiceRequestServices where srs.Id == serviceRequestServiceId select srs).Include(u => u.Access).SingleOrDefault();
 
                if (serviceRequestService != null)
                {
                    if (serviceRequestService.Access != null && serviceRequestService.Access.Id != updatedAccessId
                        || serviceRequestService.Access == null && !string.IsNullOrEmpty(updatedAccessId))
                    {
                        serviceRequestService.Access = (from a in db.Accesses where a.Id == updatedAccessId select a).SingleOrDefault();
                        serviceRequestService.UserId = userId;
                        serviceRequestService.Updated = DateTime.UtcNow.AddHours(3);
                        saveUpdate = true;
                    }
                    else if (string.IsNullOrEmpty(updatedAccessId))
                    {
                        // nulling
                        serviceRequestService.Access = null;
                        serviceRequestService.UserId = userId;
                        serviceRequestService.Updated = DateTime.UtcNow.AddHours(3);
                        saveUpdate = true;
                    }
 
                    if (saveUpdate)
                    {
                        db.ServiceRequestServices.Attach(serviceRequestService);
 
                        //db.Entry(serviceRequestService).Property(u => u.Access).IsModified = true;
                        db.Entry(serviceRequestService).Property(u => u.UserId).IsModified = true;
                        db.Entry(serviceRequestService).Property(u => u.Updated).IsModified = true;
 
                        db.SaveChanges();
 
                        result.AddSuccess("Service " + service + " access reference updated (تم تحديث الربط بالرقم).");
                    }
                    else result.AddWarning("Reference access value was not updated (لم يتم تحديث الربط بالرقم).");
                }
                else result.AddWarning("ServiceRequestService is null (لا توجد حالة خدمة للرقم).");
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont> ProvisionedServiceToNddOntDictionary
        {
            get
            {
                string key;
                Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont> dictionary;
 
                var serviceIdToAccessIdDictionary = Ia.Ngn.Cl.Model.Data.ServiceRequestService.ProvisionedServiceIdToAccessIdDictionary;
                var ontAccessIdToOntDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntDictionary;
 
                dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont>(serviceIdToAccessIdDictionary.Count);
 
                foreach (KeyValuePair<string, string> kvp in serviceIdToAccessIdDictionary)
                {
                    key = Ia.Ngn.Cl.Model.Business.ServiceRequestService.ServiceIdToService(kvp.Key);
 
                    if (!string.IsNullOrEmpty(kvp.Value)) dictionary[key] = ontAccessIdToOntDictionary[kvp.Value];
                    else dictionary[key] = null;
                }
 
                return dictionary;
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site> ServiceToSiteDictionary
        {
            get
            {
                int fourLetterServiceDomain, fiveLetterServiceDomain;
                string service;
                Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site> dictionary;
 
                var serviceIdList = Ia.Ngn.Cl.Model.Data.ServiceRequestService.ServiceIdList;
                var routerDomainToSiteDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.RouterDomainToSiteDictionary;
 
                dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site>(serviceIdList.Count);
 
                foreach (string s in serviceIdList)
                {
                    service = Ia.Ngn.Cl.Model.Business.Service.ServiceIdToService(s);
 
                    if (service.Length >= 5)
                    {
                        fourLetterServiceDomain = int.Parse(service.Substring(0, 4));
                        fiveLetterServiceDomain = int.Parse(service.Substring(0, 5));
 
                        if (routerDomainToSiteDictionary.ContainsKey(fiveLetterServiceDomain)) dictionary[service] = routerDomainToSiteDictionary[fiveLetterServiceDomain];
                        else if (routerDomainToSiteDictionary.ContainsKey(fourLetterServiceDomain)) dictionary[service] = routerDomainToSiteDictionary[fourLetterServiceDomain];
                        //else throw new System.ArgumentOutOfRangeException("Service number " + service + " is out of range");
                    }
                    //else throw new System.ArgumentOutOfRangeException("Service number " + service + " is out of range");
                }
 
                return dictionary;
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site> ProvisionedServiceToSiteDictionary
        {
            get
            {
                int fourLetterServiceDomain, fiveLetterServiceDomain;
                string service;
                Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site> dictionary;
 
                var serviceIdList = Ia.Ngn.Cl.Model.Data.ServiceRequestService.ProvisionedServiceIdList;
                var routerDomainToSiteDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.RouterDomainToSiteDictionary;
 
                dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site>(serviceIdList.Count);
 
                foreach (string s in serviceIdList)
                {
                    service = Ia.Ngn.Cl.Model.Business.Service.ServiceIdToService(s);
 
                    if (service.Length >= 5)
                    {
                        fourLetterServiceDomain = int.Parse(service.Substring(0, 4));
                        fiveLetterServiceDomain = int.Parse(service.Substring(0, 5));
 
                        if (routerDomainToSiteDictionary.ContainsKey(fiveLetterServiceDomain)) dictionary[service] = routerDomainToSiteDictionary[fiveLetterServiceDomain];
                        else if (routerDomainToSiteDictionary.ContainsKey(fourLetterServiceDomain)) dictionary[service] = routerDomainToSiteDictionary[fourLetterServiceDomain];
                        //else throw new System.ArgumentOutOfRangeException("Service number " + service + " is out of range");
                    }
                    //else throw new System.ArgumentOutOfRangeException("Service number " + service + " is out of range");
                }
 
                return dictionary;
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static List<string> ServiceRequestServiceServicesThatDoNotExistInNeitherServiceRequestsNorServiceRequestHistoriesList()
        {
            List<string> list;
 
            using (var db = new Ia.Ngn.Cl.Model.Ngn())
            {
                /*
select top 1000 srs.Service from ServiceRequestServices srs
left outer join ServiceRequests sr on sr.Number = srs.Service
left outer join ServiceRequestHistories srh on srh.Number = srs.Service
where sr.Id is null and srh.Id is null
                 */
 
                list = (from srs in db.ServiceRequestServices
                        join sr in db.ServiceRequests on srs.Service equals sr.Number.ToString() into sr2
                        from sr3 in sr2.DefaultIfEmpty()
                        join srh in db.ServiceRequestHistories on srs.Service equals srh.Number.ToString() into srh2
                        from srh3 in srh2.DefaultIfEmpty()
                        where sr3 == null && srh3 == null //&& srs.Provisioned == true
                        select srs.Service).ToList();
            }
 
            return list;
        }
 
        ////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////
    }
 
    ////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////
}