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

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 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.Data.Entity.SqlServer;
   7:  using System.Linq;
   8:  using System.Text.RegularExpressions;
   9:   
  10:  namespace Ia.Ngn.Cl.Model.Data
  11:  {
  12:      ////////////////////////////////////////////////////////////////////////////
  13:   
  14:      /// <summary publish="true">
  15:      /// Service Request Service support class for Next Generation Network (NGN) data model.
  16:      /// </summary>
  17:      /// 
  18:      /// <remarks> 
  19:      /// Copyright © 2006-2019 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
  20:      ///
  21:      /// 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
  22:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  23:      ///
  24:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  25:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  26:      /// 
  27:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  28:      /// 
  29:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  30:      /// </remarks> 
  31:      public partial class ServiceRequestService
  32:      {
  33:          /// <summary/>
  34:          public ServiceRequestService() { }
  35:   
  36:          ////////////////////////////////////////////////////////////////////////////
  37:   
  38:          /// <summary>
  39:          /// Read service
  40:          /// </summary>
  41:          public static Ia.Ngn.Cl.Model.ServiceRequestService Read(string service)
  42:          {
  43:              Ia.Ngn.Cl.Model.ServiceRequestService serviceRequestService;
  44:   
  45:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  46:              {
  47:                  serviceRequestService = (from srs in db.ServiceRequestServices where srs.Service == service 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<int> sipOltIdList;
  95:              List<Ia.Ngn.Cl.Model.ServiceRequestService> list;
  96:   
  97:              sipOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.SipOltIdList;
  98:   
  99:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 100:              {
 101:                  list = (from srs in db.ServiceRequestServices where srs.Access != null && sipOltIdList.Contains(srs.Access.Olt) select srs).ToList();
 102:              }
 103:   
 104:              return list;
 105:          }
 106:   
 107:          ////////////////////////////////////////////////////////////////////////////
 108:   
 109:          /// <summary>
 110:          /// Service request services within a designated OLT
 111:          /// </summary>
 112:          public static List<Ia.Ngn.Cl.Model.ServiceRequestService> WithinOltList(int oltId)
 113:          {
 114:              List<Ia.Ngn.Cl.Model.ServiceRequestService> list;
 115:   
 116:              if (oltId > 0)
 117:              {
 118:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 119:                  {
 120:                      list = (from srs in db.ServiceRequestServices.Include(a => a.Access) where srs.Access != null && srs.Access.Olt == oltId select srs).ToList();
 121:                  }
 122:              }
 123:              else list = new List<Ia.Ngn.Cl.Model.ServiceRequestService>();
 124:   
 125:              return list;
 126:          }
 127:   
 128:          ////////////////////////////////////////////////////////////////////////////
 129:   
 130:          /// <summary>
 131:          /// Services within a SIP designated OLT
 132:          /// </summary>
 133:          public static List<string> ServiceWithinSipOltList()
 134:          {
 135:              List<int> sipOltIdList;
 136:              List<string> list;
 137:   
 138:              sipOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.SipOltIdList;
 139:   
 140:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 141:              {
 142:                  list = (from srs in db.ServiceRequestServices where srs.Access != null && sipOltIdList.Contains(srs.Access.Olt) select srs.Service).ToList();
 143:              }
 144:   
 145:              return list;
 146:          }
 147:   
 148:          ////////////////////////////////////////////////////////////////////////////
 149:   
 150:          /// <summary>
 151:          /// Read service using id
 152:          /// </summary>
 153:          public static Ia.Ngn.Cl.Model.ServiceRequestService ReadIncludeAccess(string id)
 154:          {
 155:              Ia.Ngn.Cl.Model.ServiceRequestService serviceRequestService;
 156:   
 157:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 158:              {
 159:                  serviceRequestService = (from srs in db.ServiceRequestServices.Include(a => a.Access) where srs.Id == id select srs).SingleOrDefault();
 160:              }
 161:   
 162:              return serviceRequestService;
 163:          }
 164:   
 165:          ////////////////////////////////////////////////////////////////////////////
 166:   
 167:          /// <summary>
 168:          /// Read service of a number
 169:          /// </summary>
 170:          public static Ia.Ngn.Cl.Model.ServiceRequestService Read(long number)
 171:          {
 172:              Ia.Ngn.Cl.Model.ServiceRequestService serviceRequestService;
 173:   
 174:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 175:              {
 176:                  serviceRequestService = (from srs in db.ServiceRequestServices where srs.Service == number.ToString() select srs).SingleOrDefault();
 177:              }
 178:   
 179:              return serviceRequestService;
 180:          }
 181:   
 182:          ////////////////////////////////////////////////////////////////////////////
 183:   
 184:          /// <summary>
 185:          /// Read all services for a number list
 186:          /// </summary>
 187:          public static List<Ia.Ngn.Cl.Model.ServiceRequestService> ReadList(ArrayList numberList)
 188:          {
 189:              long i;
 190:              long[] sp;
 191:              List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 192:   
 193:              i = 0;
 194:              sp = new long[numberList.Count];
 195:   
 196:              foreach (long l in numberList) sp[i++] = l;
 197:   
 198:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 199:              {
 200:                  //serviceList = (from q in db.Services where dnList.Contains(q.DN) select q).ToList();
 201:   
 202:                  // var pages = context.Pages.Where(x => keys.Any(key => x.Title.Contains(key)));
 203:                  serviceRequestServiceList = db.ServiceRequestServices.Where(q => sp.Any(v => q.Service == v.ToString())).ToList();
 204:              }
 205:   
 206:              return serviceRequestServiceList;
 207:          }
 208:   
 209:          ////////////////////////////////////////////////////////////////////////////
 210:   
 211:          /// <summary>
 212:          /// Update the service request service table with a list using a service list as referece 
 213:          /// </summary>
 214:          public static void UpdateWithServiceList(List<string> serviceList, List<Ia.Ngn.Cl.Model.ServiceRequestService> newServiceRequestServiceList, out string result)
 215:          {
 216:              int readItemCount, existingItemCount, insertedItemCount, updatedItemCount, deletedItemCount;
 217:              Ia.Ngn.Cl.Model.ServiceRequestService serviceRequestService, newServiceRequestService;
 218:   
 219:              readItemCount = existingItemCount = insertedItemCount = updatedItemCount = deletedItemCount = 0;
 220:              result = string.Empty;
 221:   
 222:              readItemCount = newServiceRequestServiceList.Count;
 223:   
 224:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 225:              {
 226:                  // Create SRS from newServiceRequestServiceList
 227:                  foreach (Ia.Ngn.Cl.Model.ServiceRequestService srs in newServiceRequestServiceList)
 228:                  {
 229:                      if (Ia.Ngn.Cl.Model.Business.Service.ServiceStringFormatIsLegal(srs.Service))
 230:                      {
 231:                          newServiceRequestService = new Ia.Ngn.Cl.Model.ServiceRequestService();
 232:   
 233:                          newServiceRequestService.Copy(srs);
 234:   
 235:                          // important: ServiceRequestService.Update() will only update stored.Access if it is null, or (stored.userId == Guid.Empty && update.Id > stored.Id)
 236:                          if (srs.Access != null) newServiceRequestService.Access = (from a in db.Accesses where a.Id == srs.Access.Id select a).SingleOrDefault();
 237:                          else newServiceRequestService.Access = null;
 238:   
 239:                          serviceRequestService = (from srs2 in db.ServiceRequestServices where srs2.Id == srs.Id select srs2).SingleOrDefault();
 240:   
 241:                          existingItemCount = (serviceRequestService != null) ? 1 : 0;
 242:   
 243:                          if (serviceRequestService == null)
 244:                          {
 245:                              newServiceRequestService.Created = newServiceRequestService.Updated = DateTime.UtcNow.AddHours(3);
 246:   
 247:                              db.ServiceRequestServices.Add(newServiceRequestService);
 248:   
 249:                              //Ia.Ngn.Cl.Model.Data.Msmq.ServiceQueue.Enqueue(newServiceRequestService.Service);
 250:                              //if (newServiceRequestService.Access != null) Ia.Ngn.Cl.Model.Data.Msmq.AccessNameQueue.Enqueue(newServiceRequestService.Access.Name);
 251:   
 252:                              insertedItemCount++;
 253:                          }
 254:                          else
 255:                          {
 256:                              // below: copy values from newServiceRequestService to serviceRequestService
 257:   
 258:                              if (serviceRequestService.Update(newServiceRequestService))
 259:                              {
 260:                                  db.ServiceRequestServices.Attach(serviceRequestService);
 261:                                  db.Entry(serviceRequestService).State = System.Data.Entity.EntityState.Modified;
 262:   
 263:                                  //Ia.Ngn.Cl.Model.Data.Msmq.ServiceQueue.Enqueue(serviceRequestService.Service);
 264:                                  //if (serviceRequestService.Access != null) Ia.Ngn.Cl.Model.Data.Msmq.AccessNameQueue.Enqueue(serviceRequestService.Access.Name);
 265:   
 266:                                  updatedItemCount++;
 267:                              }
 268:   
 269:                          }
 270:                      }
 271:                      else
 272:                      {
 273:                          throw new System.ArgumentOutOfRangeException("Service " + srs.Service + " string format is not legal");
 274:                      }
 275:                  }
 276:   
 277:                  /*
 278:                  // remove SRS that were not present in newServiceRequestServiceList
 279:                  foreach (string service in serviceList)
 280:                  {
 281:                      newServiceRequestService = (from srs in newServiceRequestServiceList where srs.Service == service select srs).SingleOrDefault();
 282:  
 283:                      if (newServiceRequestService == null)
 284:                      {
 285:                          serviceRequestService = (from srs in db.ServiceRequestServices where srs.Service == service select srs).SingleOrDefault();
 286:  
 287:                          if (serviceRequestService != null)
 288:                          {
 289:                              // below: will set all references to this SRS from all SR to null
 290:  
 291:                              serviceRequestList = (from sr in db.ServiceRequests where sr.ServiceRequestService != null && sr.ServiceRequestService.Id == serviceRequestService.Id select sr).ToList();
 292:  
 293:                              foreach (Ia.Ngn.Cl.Model.ServiceRequest sr in serviceRequestList)
 294:                              {
 295:                                  //sr.ServiceRequestService = null;
 296:                              }
 297:  
 298:                              Ia.Ngn.Cl.Model.Data.Msmq.ServiceQueue.Enqueue(serviceRequestService.Service);
 299:                              if (serviceRequestService.Access != null) Ia.Ngn.Cl.Model.Data.Msmq.AccessNameQueue.Enqueue(serviceRequestService.Access.Name);
 300:  
 301:                              db.ServiceRequestServices.Remove(serviceRequestService); // I will not delete any SRS record
 302:  
 303:                              deletedItemCount++;
 304:                          }
 305:                      }
 306:                  }
 307:                  */
 308:   
 309:                  db.SaveChanges();
 310:   
 311:                  result = "(" + readItemCount + "/" + existingItemCount + "/" + insertedItemCount + "," + updatedItemCount + "," + deletedItemCount + ") ";
 312:              }
 313:          }
 314:   
 315:          /*
 316:          ////////////////////////////////////////////////////////////////////////////
 317:  
 318:          /// <summary>
 319:          /// Update the ServiceRequestService table's ServiceSuspension and ServiceSuspensionTypeId to the specified state for a number list
 320:          /// </summary>
 321:          public static bool UpdateServiceSuspensionAndServiceSuspensionTypeIdToSpecifiedSuspensionStateForAServiceStringList(List<string> serviceList, bool state, Guid userId)
 322:          {
 323:              bool b;
 324:              Ia.Ngn.Cl.Model.ServiceRequestService serviceRequestService;
 325:  
 326:              b = false;
 327:  
 328:              if (serviceList.Count > 0)
 329:              {
 330:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 331:                  {
 332:                      // below:
 333:                      foreach (string service in serviceList)
 334:                      {
 335:                          serviceRequestService = (from q in db.ServiceRequestServices where q.Service == service select q).SingleOrDefault();
 336:  
 337:                          if (serviceRequestService != null)
 338:                          {
 339:                              if (serviceRequestService.ServiceSuspension != state)
 340:                              {
 341:                                  serviceRequestService.ServiceSuspension = state;
 342:                                  serviceRequestService.Updated = DateTime.UtcNow.AddHours(3);
 343:                                  serviceRequestService.UserId = userId;
 344:  
 345:                                  db.ServiceRequestServices.Attach(serviceRequestService);
 346:                                  db.Entry(serviceRequestService).State = System.Data.Entity.EntityState.Modified;
 347:  
 348:                                  b = true;
 349:                              }
 350:                          }
 351:                      }
 352:  
 353:                      db.SaveChanges();
 354:                  }
 355:              }
 356:              else
 357:              {
 358:              }
 359:  
 360:              return b;
 361:          }
 362:          */
 363:   
 364:          ////////////////////////////////////////////////////////////////////////////
 365:   
 366:          /// <summary>
 367:          ///
 368:          /// </summary>
 369:          public static List<Ia.Ngn.Cl.Model.ServiceRequestService> ReadSingleAsList(string id)
 370:          {
 371:              List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 372:   
 373:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 374:              {
 375:                  serviceRequestServiceList = (from srs in db.ServiceRequestServices where srs.Id == id select srs).ToList();
 376:              }
 377:   
 378:              return serviceRequestServiceList;
 379:          }
 380:   
 381:          ////////////////////////////////////////////////////////////////////////////
 382:   
 383:          /// <summary>
 384:          ///
 385:          /// </summary>
 386:          public static List<string> ServiceList()
 387:          {
 388:              List<string> list;
 389:   
 390:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 391:              {
 392:                  list = (from srs in db.ServiceRequestServices select srs.Service).ToList();
 393:              }
 394:   
 395:              return list;
 396:          }
 397:   
 398:          ////////////////////////////////////////////////////////////////////////////
 399:   
 400:          /// <summary>
 401:          ///
 402:          /// </summary>
 403:          public static Dictionary<string, string> ServiceDictionary()
 404:          {
 405:              Dictionary<string, string> dictionary;
 406:   
 407:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 408:              {
 409:                  dictionary = (from srs in db.ServiceRequestServices select new { srs.Service }).ToDictionary(u => u.Service, u => u.Service);
 410:              }
 411:   
 412:              return dictionary.ToDictionary(u => u.Key, u => u.Value);
 413:          }
 414:   
 415:          ////////////////////////////////////////////////////////////////////////////
 416:   
 417:          /// <summary>
 418:          ///
 419:          /// </summary>
 420:          public static List<string> ServiceIdList
 421:          {
 422:              get
 423:              {
 424:                  List<string> list;
 425:   
 426:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 427:                  {
 428:                      list = (from srs in db.ServiceRequestServices select srs.Id).ToList();
 429:                  }
 430:   
 431:                  return list;
 432:              }
 433:          }
 434:   
 435:          ////////////////////////////////////////////////////////////////////////////
 436:   
 437:          /// <summary>
 438:          ///
 439:          /// </summary>
 440:          public static List<Ia.Ngn.Cl.Model.ServiceRequestService> List()
 441:          {
 442:              List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 443:   
 444:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 445:              {
 446:                  serviceRequestServiceList = (from srs in db.ServiceRequestServices select srs).ToList();
 447:              }
 448:   
 449:              return serviceRequestServiceList;
 450:          }
 451:   
 452:          ////////////////////////////////////////////////////////////////////////////
 453:   
 454:          /// <summary>
 455:          ///
 456:          /// </summary>
 457:          public static List<Ia.Ngn.Cl.Model.ServiceRequestService> List(string service)
 458:          {
 459:              List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 460:   
 461:              if (!string.IsNullOrEmpty(service))
 462:              {
 463:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 464:                  {
 465:                      serviceRequestServiceList = (from srs in db.ServiceRequestServices where srs.Service == service select srs).ToList();
 466:                  }
 467:              }
 468:              else serviceRequestServiceList = new List<Model.ServiceRequestService>();
 469:   
 470:              return serviceRequestServiceList;
 471:          }
 472:   
 473:          ////////////////////////////////////////////////////////////////////////////
 474:   
 475:          /// <summary>
 476:          ///
 477:          /// </summary>
 478:          public static List<Ia.Ngn.Cl.Model.ServiceRequestService> ListIncludeAccess()
 479:          {
 480:              List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 481:   
 482:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 483:              {
 484:                  serviceRequestServiceList = (from srs in db.ServiceRequestServices select srs).Include(u => u.Access).ToList();
 485:              }
 486:   
 487:              return serviceRequestServiceList;
 488:          }
 489:   
 490:          ////////////////////////////////////////////////////////////////////////////
 491:   
 492:          /// <summary>
 493:          /// 
 494:          /// </summary>
 495:          public static List<Ia.Ngn.Cl.Model.Ui.ServiceRequestService> UiServiceRequestServiceList()
 496:          {
 497:              List<Ia.Ngn.Cl.Model.ServiceRequestService> srsList;
 498:              List<Ia.Ngn.Cl.Model.Ui.ServiceRequestService> list;
 499:   
 500:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 501:              {
 502:                  srsList = (from srs in db.ServiceRequestServices select srs).ToList();
 503:   
 504:                  list = (from srs in srsList
 505:                          select new Ia.Ngn.Cl.Model.Ui.ServiceRequestService()
 506:                          {
 507:                              Id = srs.Id,
 508:                              AbbriviatedCalling = srs.AbbriviatedCalling,
 509:                              Access = srs.Access,
 510:                              AlarmCall = srs.AlarmCall,
 511:                              CallBarring = srs.CallBarring,
 512:                              CallerId = srs.CallerId,
 513:                              CallForwarding = srs.CallForwarding,
 514:                              CallWaiting = srs.CallWaiting,
 515:                              ConferenceCall = srs.ConferenceCall,
 516:                              Created = srs.Created,
 517:                              InternationalCalling = srs.InternationalCalling,
 518:                              InternationalCallingUserControlled = srs.InternationalCallingUserControlled,
 519:                              LastRequestDateTime = srs.LastRequestDateTime,
 520:                              Provisioned = srs.Provisioned,
 521:                              Service = srs.Service,
 522:                              Serial = srs.Serial,
 523:                              ServiceType = srs.ServiceType,
 524:                              ServiceSuspension = srs.ServiceSuspension,
 525:                              Type = srs.Type,
 526:                              Updated = srs.Updated
 527:                          }).ToList();
 528:   
 529:                  return list.Distinct().ToList();
 530:              }
 531:          }
 532:   
 533:          ////////////////////////////////////////////////////////////////////////////
 534:   
 535:          /// <summary>
 536:          /// 
 537:          /// </summary>
 538:          public static List<Ia.Ngn.Cl.Model.Ui.ServiceRequestService> UiServiceRequestServiceList(string service)
 539:          {
 540:              List<Ia.Ngn.Cl.Model.ServiceRequestService> srsList;
 541:              List<Ia.Ngn.Cl.Model.Ui.ServiceRequestService> list;
 542:   
 543:              if (!string.IsNullOrEmpty(service))
 544:              {
 545:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 546:                  {
 547:                      srsList = (from srs in db.ServiceRequestServices where srs.Service == service select srs).ToList();
 548:   
 549:                      list = (from srs in srsList
 550:                              select new Ia.Ngn.Cl.Model.Ui.ServiceRequestService()
 551:                              {
 552:                                  Id = srs.Id,
 553:                                  AbbriviatedCalling = srs.AbbriviatedCalling,
 554:                                  Access = srs.Access,
 555:                                  AlarmCall = srs.AlarmCall,
 556:                                  CallBarring = srs.CallBarring,
 557:                                  CallerId = srs.CallerId,
 558:                                  CallForwarding = srs.CallForwarding,
 559:                                  CallWaiting = srs.CallWaiting,
 560:                                  ConferenceCall = srs.ConferenceCall,
 561:                                  Created = srs.Created,
 562:                                  InternationalCalling = srs.InternationalCalling,
 563:                                  InternationalCallingUserControlled = srs.InternationalCallingUserControlled,
 564:                                  LastRequestDateTime = srs.LastRequestDateTime,
 565:                                  Provisioned = srs.Provisioned,
 566:                                  Service = srs.Service,
 567:                                  Serial = srs.Serial,
 568:                                  ServiceType = srs.ServiceType,
 569:                                  ServiceSuspension = srs.ServiceSuspension,
 570:                                  Type = srs.Type,
 571:                                  Updated = srs.Updated
 572:                              }).ToList();
 573:                  }
 574:              }
 575:              else list = new List<Ia.Ngn.Cl.Model.Ui.ServiceRequestService>();
 576:   
 577:              return list.Distinct().ToList();
 578:          }
 579:   
 580:          ////////////////////////////////////////////////////////////////////////////
 581:   
 582:          /// <summary>
 583:          /// 
 584:          /// </summary>
 585:          public static List<Ia.Ngn.Cl.Model.Business.ServiceSerialRequestService> ServiceSerialRequestServiceList()
 586:          {
 587:              List<Ia.Ngn.Cl.Model.ServiceRequestService> srsList;
 588:              List<Ia.Ngn.Cl.Model.Business.ServiceSerialRequestService> list;
 589:   
 590:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 591:              {
 592:                  srsList = (from srs in db.ServiceRequestServices select srs).ToList();
 593:   
 594:                  list = (from srs in srsList
 595:                          select new Ia.Ngn.Cl.Model.Business.ServiceSerialRequestService()
 596:                          {
 597:                              Id = srs.Service + ":" + srs.Serial,
 598:                              AbbriviatedCalling = srs.AbbriviatedCalling,
 599:                              //Access = srs.Access,
 600:                              AlarmCall = srs.AlarmCall,
 601:                              WakeupCall = srs.WakeupCall,
 602:                              CallBarring = srs.CallBarring,
 603:                              CallerId = srs.CallerId,
 604:                              CallForwarding = srs.CallForwarding,
 605:                              CallWaiting = srs.CallWaiting,
 606:                              ConferenceCall = srs.ConferenceCall,
 607:                              InternationalCalling = srs.InternationalCalling,
 608:                              InternationalCallingUserControlled = srs.InternationalCallingUserControlled,
 609:                              Provisioned = srs.Provisioned,
 610:                              Service = srs.Service,
 611:                              Serial = srs.Serial,
 612:                          }).ToList();
 613:   
 614:                  return list.Distinct().ToList();
 615:              }
 616:          }
 617:   
 618:          ////////////////////////////////////////////////////////////////////////////
 619:   
 620:          /// <summary>
 621:          /// 
 622:          /// </summary>
 623:          public static List<Ia.Ngn.Cl.Model.Business.ServiceSerialRequestService> ServiceSerialRequestServiceList(string service)
 624:          {
 625:              List<Ia.Ngn.Cl.Model.ServiceRequestService> srsList;
 626:              List<Ia.Ngn.Cl.Model.Business.ServiceSerialRequestService> list;
 627:   
 628:              if (!string.IsNullOrEmpty(service))
 629:              {
 630:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 631:                  {
 632:                      srsList = (from srs in db.ServiceRequestServices where srs.Service == service select srs).ToList();
 633:   
 634:                      list = (from srs in srsList
 635:                              select new Ia.Ngn.Cl.Model.Business.ServiceSerialRequestService()
 636:                              {
 637:                                  Id = srs.Service + ":" + srs.Serial,
 638:                                  AbbriviatedCalling = srs.AbbriviatedCalling,
 639:                                  //Access = srs.Access,
 640:                                  AlarmCall = srs.AlarmCall,
 641:                                  WakeupCall = srs.WakeupCall,
 642:                                  CallBarring = srs.CallBarring,
 643:                                  CallerId = srs.CallerId,
 644:                                  CallForwarding = srs.CallForwarding,
 645:                                  CallWaiting = srs.CallWaiting,
 646:                                  ConferenceCall = srs.ConferenceCall,
 647:                                  InternationalCalling = srs.InternationalCalling,
 648:                                  InternationalCallingUserControlled = srs.InternationalCallingUserControlled,
 649:                                  Provisioned = srs.Provisioned,
 650:                                  Service = srs.Service,
 651:                                  Serial = srs.Serial,
 652:                              }).ToList();
 653:                  }
 654:              }
 655:              else list = new List<Ia.Ngn.Cl.Model.Business.ServiceSerialRequestService>();
 656:   
 657:              return list.Distinct().ToList();
 658:          }
 659:   
 660:          ////////////////////////////////////////////////////////////////////////////
 661:          ////////////////////////////////////////////////////////////////////////////
 662:   
 663:          /// <summary>
 664:          ///
 665:          /// </summary>
 666:          public static Dictionary<string, string> ServiceIdToAccessIdDictionary
 667:          {
 668:              get
 669:              {
 670:                  Dictionary<string, string> dictionary, nullAccessDictionary;
 671:   
 672:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 673:                  {
 674:                      dictionary = (from srs in db.ServiceRequestServices where srs.Access != null select new { srs.Id, srs.Access }).ToDictionary(u => u.Id, u => u.Access.Id);
 675:                      nullAccessDictionary = (from s in db.ServiceRequestServices where s.Access == null select new { s.Id, s.Access }).ToDictionary(u => u.Id, u => string.Empty);
 676:                  }
 677:   
 678:                  return dictionary.Union(nullAccessDictionary).ToDictionary(u => u.Key, u => u.Value);
 679:              }
 680:          }
 681:   
 682:          ////////////////////////////////////////////////////////////////////////////
 683:   
 684:          /// <summary>
 685:          ///
 686:          /// </summary>
 687:          public static Dictionary<string, string> ServiceToAccessIdDictionary
 688:          {
 689:              get
 690:              {
 691:                  string key;
 692:                  Dictionary<string, string> serviceToAccessIdDictionary, serviceIdToAccessIdDictionary;
 693:   
 694:                  serviceIdToAccessIdDictionary = Ia.Ngn.Cl.Model.Data.ServiceRequestService.ServiceIdToAccessIdDictionary;
 695:   
 696:                  serviceToAccessIdDictionary = new Dictionary<string, string>(serviceIdToAccessIdDictionary.Count);
 697:   
 698:                  foreach (KeyValuePair<string, string> kvp in serviceIdToAccessIdDictionary)
 699:                  {
 700:                      key = Ia.Ngn.Cl.Model.Business.ServiceRequestService.ServiceIdToService(kvp.Key);
 701:   
 702:                      serviceToAccessIdDictionary[key] = kvp.Value;
 703:                  }
 704:   
 705:                  return serviceToAccessIdDictionary;
 706:              }
 707:          }
 708:   
 709:          ////////////////////////////////////////////////////////////////////////////
 710:   
 711:          /// <summary>
 712:          ///
 713:          /// </summary>
 714:          public static List<string> ProvisionedServiceIdList
 715:          {
 716:              get
 717:              {
 718:                  List<string> serviceRequestServiceList;
 719:   
 720:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 721:                  {
 722:                      serviceRequestServiceList = (from srs in db.ServiceRequestServices where srs.Provisioned == true select srs.Id).ToList();
 723:                  }
 724:   
 725:                  return serviceRequestServiceList;
 726:              }
 727:          }
 728:   
 729:          ////////////////////////////////////////////////////////////////////////////
 730:   
 731:          /// <summary>
 732:          ///
 733:          /// </summary>
 734:          public static Dictionary<string, string> ProvisionedServiceIdToAccessIdDictionary
 735:          {
 736:              get
 737:              {
 738:                  Dictionary<string, string> dictionary, nullAccessDictionary;
 739:   
 740:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 741:                  {
 742:                      dictionary = (from srs in db.ServiceRequestServices where srs.Provisioned == true && srs.Access != null select new { srs.Id, srs.Access }).ToDictionary(u => u.Id, u => u.Access.Id);
 743:                      nullAccessDictionary = (from s in db.ServiceRequestServices where s.Provisioned == true && s.Access == null select new { s.Id, s.Access }).ToDictionary(u => u.Id, u => string.Empty);
 744:                  }
 745:   
 746:                  return dictionary.Union(nullAccessDictionary).ToDictionary(u => u.Key, u => u.Value);
 747:              }
 748:          }
 749:   
 750:          ////////////////////////////////////////////////////////////////////////////
 751:   
 752:          /// <summary>
 753:          ///
 754:          /// </summary>
 755:          public static Dictionary<string, string> ProvisionedServiceToAccessIdDictionary
 756:          {
 757:              get
 758:              {
 759:                  string key;
 760:                  Dictionary<string, string> serviceToAccessIdDictionary, serviceIdToAccessIdDictionary;
 761:   
 762:                  serviceIdToAccessIdDictionary = Ia.Ngn.Cl.Model.Data.ServiceRequestService.ProvisionedServiceIdToAccessIdDictionary;
 763:   
 764:                  serviceToAccessIdDictionary = new Dictionary<string, string>(serviceIdToAccessIdDictionary.Count);
 765:   
 766:                  foreach (KeyValuePair<string, string> kvp in serviceIdToAccessIdDictionary)
 767:                  {
 768:                      key = Ia.Ngn.Cl.Model.Business.ServiceRequestService.ServiceIdToService(kvp.Key);
 769:   
 770:                      serviceToAccessIdDictionary[key] = kvp.Value;
 771:                  }
 772:   
 773:                  return serviceToAccessIdDictionary;
 774:              }
 775:          }
 776:   
 777:          ////////////////////////////////////////////////////////////////////////////
 778:          ////////////////////////////////////////////////////////////////////////////
 779:   
 780:          /// <summary>
 781:          /// 
 782:          /// </summary>
 783:          public static Dictionary<string, Ia.Ngn.Cl.Model.ServiceRequestService> ServiceToServiceRequestServiceDictionary(List<int> domainList)
 784:          {
 785:              string key;
 786:              List<string> stringDomainList;
 787:              List<Ia.Ngn.Cl.Model.ServiceRequestService> list;
 788:              Dictionary<string, Ia.Ngn.Cl.Model.ServiceRequestService> dictionary;
 789:   
 790:              stringDomainList = new List<string>();
 791:   
 792:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 793:              {
 794:                  if (domainList != null)
 795:                  {
 796:                      foreach (int i in domainList) stringDomainList.Add(i.ToString());
 797:   
 798:                      list = (from srs in db.ServiceRequestServices.Include(a => a.ServiceRequests).Include(x => x.ServiceRequests.Select(y => y.ServiceRequestTypes))
 799:                              where stringDomainList.Any(u => srs.Service.StartsWith(u.ToString()))
 800:                              select srs).ToList();
 801:   
 802:                      dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.ServiceRequestService>(list.Count);
 803:   
 804:                      foreach (var srs in list)
 805:                      {
 806:                          key = srs.Service;
 807:   
 808:                          if (dictionary.ContainsKey(key))
 809:                          {
 810:                              dictionary[key] = srs;
 811:                          }
 812:                          else dictionary[key] = srs;
 813:                      }
 814:                  }
 815:                  else
 816:                  {
 817:                      dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.ServiceRequestService>();
 818:                  }
 819:              }
 820:   
 821:              return dictionary;
 822:          }
 823:   
 824:          ////////////////////////////////////////////////////////////////////////////
 825:   
 826:          /// <summary>
 827:          ///
 828:          /// </summary>
 829:          public static void UpdateServiceSuspension(string service, bool serviceSuspensionState, Guid userId, out Ia.Cl.Model.Result result)
 830:          {
 831:              string serviceRequestServiceId;
 832:              Ia.Ngn.Cl.Model.ServiceRequestService serviceRequestService;
 833:   
 834:              result = new Ia.Cl.Model.Result();
 835:              serviceRequestServiceId = Ia.Ngn.Cl.Model.Business.ServiceRequestService.ServiceRequestServiceId(service, Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService);
 836:   
 837:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 838:              {
 839:                  serviceRequestService = (from srs in db.ServiceRequestServices where srs.Id == serviceRequestServiceId select srs).SingleOrDefault();
 840:   
 841:                  if (serviceRequestService != null)
 842:                  {
 843:                      if (serviceRequestService.ServiceSuspension != serviceSuspensionState)
 844:                      {
 845:                          serviceRequestService.ServiceSuspension = serviceSuspensionState;
 846:                          serviceRequestService.Updated = DateTime.UtcNow.AddHours(3);
 847:                          serviceRequestService.UserId = userId;
 848:   
 849:                          db.ServiceRequestServices.Attach(serviceRequestService);
 850:                          db.Entry(serviceRequestService).Property(x => x.ServiceSuspension).IsModified = true;
 851:   
 852:                          db.SaveChanges();
 853:   
 854:                          result.AddSuccess("ServiceSuspension updated. ");
 855:                      }
 856:                      else
 857:                      {
 858:                          result.AddWarning("Warning: ServiceRequestService ServiceSuspension value was not updated because its the same. ");
 859:                      }
 860:                  }
 861:                  else
 862:                  {
 863:                      result.AddError("Error: serviceRequestService is null. ");
 864:                  }
 865:              }
 866:          }
 867:   
 868:          ////////////////////////////////////////////////////////////////////////////
 869:   
 870:          /// <summary>
 871:          ///
 872:          /// </summary>
 873:          public static Dictionary<string, string> ReadServiceAndOntNameDictionaryWithFourDigitNumberDomain(int fourDigitNumberDomain)
 874:          {
 875:              string s;
 876:              Dictionary<string, string> dictionary;
 877:   
 878:              dictionary = new Dictionary<string, string>(10000);
 879:   
 880:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 881:              {
 882:                  var list = (from srs in db.ServiceRequestServices
 883:                              where SqlFunctions.PatIndex(fourDigitNumberDomain.ToString() + "%", srs.Service) > 0
 884:                              orderby srs.Service ascending
 885:                              select new
 886:                              {
 887:                                  Service = srs.Service,
 888:                                  Access = srs.Access
 889:                              }).ToList();
 890:   
 891:                  foreach (var v in list)
 892:                  {
 893:                      if (v.Access != null) s = v.Service + " (" + v.Access.Name + ")";
 894:                      else s = v.Service;
 895:   
 896:                      dictionary[v.Service] = s;
 897:                  }
 898:              }
 899:   
 900:              return dictionary;
 901:          }
 902:   
 903:          ////////////////////////////////////////////////////////////////////////////
 904:   
 905:          /// <summary>
 906:          ///
 907:          /// </summary>
 908:          public static List<Ia.Ngn.Cl.Model.ServiceRequestService> ReadListOfServiceRequestServicesWithSimilarServiceNumbers(List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList)
 909:          {
 910:              int i;
 911:              string[] sp;
 912:              List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 913:   
 914:              sp = new string[serviceRequestList.Count];
 915:   
 916:              i = 0;
 917:   
 918:              foreach (Ia.Ngn.Cl.Model.ServiceRequest serviceRequest in serviceRequestList) sp[i++] = serviceRequest.Number.ToString();
 919:   
 920:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 921:              {
 922:                  serviceRequestServiceList = (from srs in db.ServiceRequestServices where sp.Contains(srs.Service) select srs).ToList();
 923:              }
 924:   
 925:              return serviceRequestServiceList;
 926:          }
 927:   
 928:          ////////////////////////////////////////////////////////////////////////////    
 929:   
 930:          /// <summary>
 931:          ///
 932:          /// </summary>
 933:          public static List<string> ServiceStringList()
 934:          {
 935:              List<string> serviceStringList;
 936:   
 937:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 938:              {
 939:                  serviceStringList = (from srs in db.ServiceRequestServices 
 940:                                       where srs.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService 
 941:                                       orderby srs.Service ascending 
 942:                                       select srs.Service).ToList();
 943:              }
 944:   
 945:              return serviceStringList;
 946:          }
 947:   
 948:          ////////////////////////////////////////////////////////////////////////////    
 949:   
 950:          /// <summary>
 951:          ///
 952:          /// </summary>
 953:          public static List<string> ServiceStringWithNonNullAccessList()
 954:          {
 955:              List<string> serviceStringList;
 956:   
 957:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 958:              {
 959:                  serviceStringList = (from srs in db.ServiceRequestServices 
 960:                                       where srs.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && srs.Access != null 
 961:                                       orderby srs.Service ascending select srs.Service).ToList();
 962:              }
 963:   
 964:              return serviceStringList;
 965:          }
 966:   
 967:          ////////////////////////////////////////////////////////////////////////////
 968:   
 969:          /// <summary>
 970:          ///
 971:          /// </summary>
 972:          public static List<Ia.Ngn.Cl.Model.ServiceRequestService> WithNullAccessList()
 973:          {
 974:              List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 975:   
 976:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 977:              {
 978:                  // below: Take(100) temp
 979:                  serviceRequestServiceList = (from srs in db.ServiceRequestServices where srs.Access == null orderby srs.Service ascending select srs).Take(100).ToList();
 980:              }
 981:   
 982:              return serviceRequestServiceList;
 983:          }
 984:   
 985:          ////////////////////////////////////////////////////////////////////////////
 986:   
 987:          /// <summary>
 988:          ///
 989:          /// </summary>
 990:          public static List<Ia.Ngn.Cl.Model.ServiceRequestService> ServiceSuspensionIsTrueAndProvisionedIsTrueList()
 991:          {
 992:              List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 993:   
 994:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 995:              {
 996:                  serviceRequestServiceList = (from s in db.ServiceRequestServices where s.ServiceSuspension == true && s.Provisioned == true select s).ToList();
 997:              }
 998:   
 999:              return serviceRequestServiceList;
1000:          }
1001:   
1002:          ////////////////////////////////////////////////////////////////////////////
1003:   
1004:          /// <summary>
1005:          ///
1006:          /// </summary>
1007:          public static List<Ia.Ngn.Cl.Model.ServiceRequestService> ServiceSuspensionIsFalseList()
1008:          {
1009:              List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
1010:   
1011:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
1012:              {
1013:                  serviceRequestServiceList = (from s in db.ServiceRequestServices where s.ServiceSuspension == false select s).ToList();
1014:              }
1015:   
1016:              return serviceRequestServiceList;
1017:          }
1018:   
1019:          ////////////////////////////////////////////////////////////////////////////
1020:   
1021:          /// <summary>
1022:          ///
1023:          /// </summary>
1024:          public static List<string> ServiceSuspensionIsTrueAndProvisionedIsTrueStringNumberList
1025:          {
1026:              get
1027:              {
1028:                  List<string> serviceRequestServiceNumberStringList;
1029:                  List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
1030:   
1031:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
1032:                  {
1033:                      // below:                
1034:                      serviceRequestServiceList = ServiceSuspensionIsTrueAndProvisionedIsTrueList();
1035:   
1036:                      if (serviceRequestServiceList.Count > 0)
1037:                      {
1038:                          serviceRequestServiceNumberStringList = new List<string>(serviceRequestServiceList.Count);
1039:   
1040:                          foreach (Ia.Ngn.Cl.Model.ServiceRequestService srs in serviceRequestServiceList)
1041:                          {
1042:                              serviceRequestServiceNumberStringList.Add(srs.Service);
1043:                          }
1044:                      }
1045:                      else
1046:                      {
1047:                          // below: not null
1048:                          serviceRequestServiceNumberStringList = new List<string>(1);
1049:                      }
1050:                  }
1051:   
1052:                  return serviceRequestServiceNumberStringList;
1053:              }
1054:          }
1055:   
1056:          ////////////////////////////////////////////////////////////////////////////
1057:   
1058:          /// <summary>
1059:          ///
1060:          /// </summary>
1061:          public static List<string> ServiceSuspensionIsFalseStringNumberList
1062:          {
1063:              get
1064:              {
1065:                  List<string> serviceRequestServiceNumberStringList;
1066:                  List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
1067:   
1068:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
1069:                  {
1070:                      // below:                
1071:                      serviceRequestServiceList = ServiceSuspensionIsFalseList();
1072:   
1073:                      if (serviceRequestServiceList.Count > 0)
1074:                      {
1075:                          serviceRequestServiceNumberStringList = new List<string>(serviceRequestServiceList.Count);
1076:   
1077:                          foreach (Ia.Ngn.Cl.Model.ServiceRequestService srs in serviceRequestServiceList)
1078:                          {
1079:                              serviceRequestServiceNumberStringList.Add(srs.Service);
1080:                          }
1081:                      }
1082:                      else
1083:                      {
1084:                          // below: not null
1085:                          serviceRequestServiceNumberStringList = new List<string>(1);
1086:                      }
1087:                  }
1088:   
1089:                  return serviceRequestServiceNumberStringList;
1090:              }
1091:          }
1092:   
1093:          ////////////////////////////////////////////////////////////////////////////
1094:   
1095:          /// <summary>
1096:          ///
1097:          /// </summary>
1098:          public static List<Ia.Ngn.Cl.Model.ServiceRequestService> ServiceRequestServiceWithNullAccessList
1099:          {
1100:              get
1101:              {
1102:                  List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
1103:   
1104:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
1105:                  {
1106:                      serviceRequestServiceList = (from srs in db.ServiceRequestServices where srs.Access == null select srs).ToList();
1107:                  }
1108:   
1109:                  return serviceRequestServiceList;
1110:              }
1111:          }
1112:   
1113:          ////////////////////////////////////////////////////////////////////////////
1114:   
1115:          /// <summary>
1116:          ///
1117:          /// </summary>
1118:          public static List<string> ServiceRequestServiceServiceIdWhereProvisionedIsTrueAndAccessIsNullList()
1119:          {
1120:              List<string> list;
1121:   
1122:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
1123:              {
1124:                  list = (from srs in db.ServiceRequestServices where srs.Provisioned == true && srs.Access == null select srs.Id).ToList();
1125:              }
1126:   
1127:              return list;
1128:          }
1129:   
1130:          ////////////////////////////////////////////////////////////////////////////
1131:   
1132:          /// <summary>
1133:          ///
1134:          /// </summary>
1135:          public static List<Ia.Ngn.Cl.Model.ServiceRequestService> WithinSiteList(int siteId)
1136:          {
1137:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site site;
1138:              List<int> siteRouterDomainList;
1139:              List<Ia.Ngn.Cl.Model.ServiceRequestService> list;
1140:              //Dictionary<int, string> areaIdToSymbolDictionary;
1141:   
1142:              // areaIdToSymbolDictionary = Ia.Ngn.Cl.Model.Data.Service.AreaIdToSymbolDictionary;
1143:   
1144:              site = (from s in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.SiteList where s.Id == siteId select s).SingleOrDefault();
1145:   
1146:              if (site != null)
1147:              {
1148:                  siteRouterDomainList = (from r in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.RouterList where r.Site.Id == site.Id select r).SelectMany(d => d.DomainList).ToList();
1149:   
1150:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
1151:                  {
1152:                      list = (from srs in db.ServiceRequestServices
1153:                              where srs.Provisioned == true && siteRouterDomainList.Any(u => srs.Service.StartsWith(u.ToString()))
1154:                              select srs).Include(u => u.Access).ToList();
1155:                  }
1156:              }
1157:              else
1158:              {
1159:                  list = new List<Model.ServiceRequestService>();
1160:              }
1161:   
1162:              return list;
1163:          }
1164:   
1165:          ////////////////////////////////////////////////////////////////////////////
1166:   
1167:          /// <summary>
1168:          ///
1169:          /// </summary>
1170:          public static bool NullifyAccessIdByAccessId(string accessId, out string result)
1171:          {
1172:              bool b;
1173:              int numberOfRecordsWhereAccessIsNullified;
1174:              Ia.Ngn.Cl.Model.ServiceRequestService serviceRequestService;
1175:   
1176:              b = false;
1177:              numberOfRecordsWhereAccessIsNullified = 0;
1178:   
1179:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
1180:              {
1181:                  // --update ServiceRequestServices set Access_Id = null where Access_Id = '1040101010040004'
1182:                  //var query = (from srs in db.ServiceRequestServices where srs.Access.Id == accessId select srs).ToList();
1183:   
1184:                  //foreach (var v in query)
1185:                  //{
1186:                  serviceRequestService = (from srs in db.ServiceRequestServices where srs.Access.Id == accessId select srs).FirstOrDefault(); //.SingleOrDefault();
1187:   
1188:                  if (serviceRequestService != null)
1189:                  {
1190:                      serviceRequestService.Access = null;
1191:                      serviceRequestService.Updated = DateTime.UtcNow.AddHours(3);
1192:   
1193:                      db.ServiceRequestServices.Attach(serviceRequestService);
1194:                      db.Entry(serviceRequestService).Property(x => x.Updated).IsModified = true;
1195:   
1196:                      db.SaveChanges();
1197:   
1198:                      numberOfRecordsWhereAccessIsNullified++;
1199:                  }
1200:                  //}
1201:   
1202:                  b = true;
1203:              }
1204:   
1205:              result = "Number of records where access is nullified: " + numberOfRecordsWhereAccessIsNullified;
1206:   
1207:              return b;
1208:          }
1209:   
1210:          ////////////////////////////////////////////////////////////////////////////
1211:   
1212:          /// <summary>
1213:          ///
1214:          /// </summary>
1215:          public static void UpdateServiceRequestServiceAccess(string service, string updatedAccessId, Guid userId, out Ia.Cl.Model.Result result)
1216:          {
1217:              bool saveUpdate;
1218:              string serviceRequestServiceId;
1219:              Ia.Ngn.Cl.Model.ServiceRequestService serviceRequestService;
1220:   
1221:              saveUpdate = false;
1222:              result = new Ia.Cl.Model.Result();
1223:              serviceRequestServiceId = Ia.Ngn.Cl.Model.Business.ServiceRequestService.ServiceRequestServiceId(service, Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService);
1224:   
1225:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
1226:              {
1227:                  serviceRequestService = (from srs in db.ServiceRequestServices where srs.Id == serviceRequestServiceId select srs).SingleOrDefault();
1228:   
1229:                  if (serviceRequestService != null)
1230:                  {
1231:                      if (serviceRequestService.Access != null && serviceRequestService.Access.Id != updatedAccessId
1232:                          || serviceRequestService.Access == null && !string.IsNullOrEmpty(updatedAccessId))
1233:                      {
1234:                          serviceRequestService.Access = (from a in db.Accesses where a.Id == updatedAccessId select a).SingleOrDefault();
1235:                          serviceRequestService.UserId = userId;
1236:                          serviceRequestService.Updated = DateTime.UtcNow.AddHours(3);
1237:                          saveUpdate = true;
1238:                      }
1239:                      else if (string.IsNullOrEmpty(updatedAccessId))
1240:                      {
1241:                          // nulling
1242:                          serviceRequestService.Access = null;
1243:                          serviceRequestService.UserId = userId;
1244:                          serviceRequestService.Updated = DateTime.UtcNow.AddHours(3);
1245:                          saveUpdate = true;
1246:                      }
1247:   
1248:                      if (saveUpdate)
1249:                      {
1250:                          db.ServiceRequestServices.Attach(serviceRequestService);
1251:   
1252:                          //db.Entry(serviceRequestService).Property(x => x.Access).IsModified = true;
1253:                          db.Entry(serviceRequestService).Property(x => x.UserId).IsModified = true;
1254:                          db.Entry(serviceRequestService).Property(x => x.Updated).IsModified = true;
1255:   
1256:                          db.SaveChanges();
1257:   
1258:                          result.AddSuccess("Service " + service + " access updated. ");
1259:                      }
1260:                      else
1261:                      {
1262:                          result.AddWarning("Warning: ServiceRequestService Access value was not updated. ");
1263:                      }
1264:                  }
1265:                  else
1266:                  {
1267:                      result.AddWarning("Warning: ServiceRequestService is null. ");
1268:                  }
1269:              }
1270:          }
1271:   
1272:          ////////////////////////////////////////////////////////////////////////////
1273:   
1274:          /// <summary>
1275:          ///
1276:          /// </summary>
1277:          public static Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont> ProvisionedServiceToNddOntDictionary
1278:          {
1279:              get
1280:              {
1281:                  string key;
1282:                  Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont> dictionary;
1283:   
1284:                  var serviceIdToAccessIdDictionary = Ia.Ngn.Cl.Model.Data.ServiceRequestService.ProvisionedServiceIdToAccessIdDictionary;
1285:                  var ontAccessIdToOntDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntDictionary;
1286:   
1287:                  dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont>(serviceIdToAccessIdDictionary.Count);
1288:   
1289:                  foreach (KeyValuePair<string, string> kvp in serviceIdToAccessIdDictionary)
1290:                  {
1291:                      key = Ia.Ngn.Cl.Model.Business.ServiceRequestService.ServiceIdToService(kvp.Key);
1292:   
1293:                      if (!string.IsNullOrEmpty(kvp.Value)) dictionary[key] = ontAccessIdToOntDictionary[kvp.Value];
1294:                      else dictionary[key] = null;
1295:                  }
1296:   
1297:                  return dictionary;
1298:              }
1299:          }
1300:   
1301:          ////////////////////////////////////////////////////////////////////////////
1302:   
1303:          /// <summary>
1304:          ///
1305:          /// </summary>
1306:          public static Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site> ServiceToSiteDictionary
1307:          {
1308:              get
1309:              {
1310:                  int fourLetterServiceDomain, fiveLetterServiceDomain;
1311:                  string service;
1312:                  Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site> dictionary;
1313:   
1314:                  var serviceIdList = Ia.Ngn.Cl.Model.Data.ServiceRequestService.ServiceIdList;
1315:                  var routerDomainToSiteDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.RouterDomainToSiteDictionary;
1316:   
1317:                  dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site>(serviceIdList.Count);
1318:   
1319:                  foreach (string s in serviceIdList)
1320:                  {
1321:                      service = Ia.Ngn.Cl.Model.Business.Service.ServiceIdToService(s);
1322:   
1323:                      if (service.Length >= 5)
1324:                      {
1325:                          fourLetterServiceDomain = int.Parse(service.Substring(0, 4));
1326:                          fiveLetterServiceDomain = int.Parse(service.Substring(0, 5));
1327:   
1328:                          if (routerDomainToSiteDictionary.ContainsKey(fiveLetterServiceDomain)) dictionary[service] = routerDomainToSiteDictionary[fiveLetterServiceDomain];
1329:                          else if (routerDomainToSiteDictionary.ContainsKey(fourLetterServiceDomain)) dictionary[service] = routerDomainToSiteDictionary[fourLetterServiceDomain];
1330:                          //else throw new System.ArgumentOutOfRangeException("Service number " + service + " is out of range");
1331:                      }
1332:                      //else throw new System.ArgumentOutOfRangeException("Service number " + service + " is out of range");
1333:                  }
1334:   
1335:                  return dictionary;
1336:              }
1337:          }
1338:   
1339:          ////////////////////////////////////////////////////////////////////////////
1340:   
1341:          /// <summary>
1342:          ///
1343:          /// </summary>
1344:          public static Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site> ProvisionedServiceToSiteDictionary
1345:          {
1346:              get
1347:              {
1348:                  int fourLetterServiceDomain, fiveLetterServiceDomain;
1349:                  string service;
1350:                  Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site> dictionary;
1351:   
1352:                  var serviceIdList = Ia.Ngn.Cl.Model.Data.ServiceRequestService.ProvisionedServiceIdList;
1353:                  var routerDomainToSiteDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.RouterDomainToSiteDictionary;
1354:   
1355:                  dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site>(serviceIdList.Count);
1356:   
1357:                  foreach (string s in serviceIdList)
1358:                  {
1359:                      service = Ia.Ngn.Cl.Model.Business.Service.ServiceIdToService(s);
1360:   
1361:                      if (service.Length >= 5)
1362:                      {
1363:                          fourLetterServiceDomain = int.Parse(service.Substring(0, 4));
1364:                          fiveLetterServiceDomain = int.Parse(service.Substring(0, 5));
1365:   
1366:                          if (routerDomainToSiteDictionary.ContainsKey(fiveLetterServiceDomain)) dictionary[service] = routerDomainToSiteDictionary[fiveLetterServiceDomain];
1367:                          else if (routerDomainToSiteDictionary.ContainsKey(fourLetterServiceDomain)) dictionary[service] = routerDomainToSiteDictionary[fourLetterServiceDomain];
1368:                          //else throw new System.ArgumentOutOfRangeException("Service number " + service + " is out of range");
1369:                      }
1370:                      //else throw new System.ArgumentOutOfRangeException("Service number " + service + " is out of range");
1371:                  }
1372:   
1373:                  return dictionary;
1374:              }
1375:          }
1376:   
1377:          ////////////////////////////////////////////////////////////////////////////
1378:          ////////////////////////////////////////////////////////////////////////////
1379:      }
1380:   
1381:      ////////////////////////////////////////////////////////////////////////////
1382:      ////////////////////////////////////////////////////////////////////////////
1383:  }