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

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