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

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