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

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