Professional Applications Programmers/Consultants برمجة واستشارات تطبيقات الإنترنت
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.Xml;
   5:  using System.Xml.Linq;
   6:  using System.Linq;
   7:  using System.Web;
   8:  using System.Web.Security;
   9:  using System.Reflection;
  10:  using System.IO;
  11:  using System.Globalization;
  12:  using System.Text.RegularExpressions;
  13:  using System.Data;
  14:  using System.Data.Entity;
  15:  using System.Data.Entity.SqlServer;
  16:   
  17:  namespace Ia.Ngn.Cl.Model.Data
  18:  {
  19:      ////////////////////////////////////////////////////////////////////////////
  20:   
  21:      /// <summary publish="true">
  22:      /// Service Request Service support class for Next Generation Network (NGN) data model.
  23:      /// </summary>
  24:      /// 
  25:      /// <remarks> 
  26:      /// Copyright © 2006-2017 Jasem Y. Al-Shamlan (info@ia.com.kw), Internet Applications - Kuwait. All Rights Reserved.
  27:      ///
  28:      /// 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
  29:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  30:      ///
  31:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  32:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  33:      /// 
  34:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  35:      /// 
  36:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  37:      /// </remarks> 
  38:      public partial class ServiceRequestService
  39:      {
  40:          /// <summary/>
  41:          public ServiceRequestService() { }
  42:   
  43:          ////////////////////////////////////////////////////////////////////////////
  44:   
  45:          /// <summary>
  46:          /// Read service using id
  47:          /// </summary>
  48:          public static Ia.Ngn.Cl.Model.ServiceRequestService Read(string id)
  49:          {
  50:              Ia.Ngn.Cl.Model.ServiceRequestService serviceRequestService;
  51:   
  52:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  53:              {
  54:                  serviceRequestService = (from srs in db.ServiceRequestServices where srs.Id == id select srs).SingleOrDefault();
  55:              }
  56:   
  57:              return serviceRequestService;
  58:          }
  59:   
  60:          ////////////////////////////////////////////////////////////////////////////
  61:   
  62:          /// <summary>
  63:          /// Service request services within a SIP designated OLT
  64:          /// </summary>
  65:          public static List<Ia.Ngn.Cl.Model.ServiceRequestService> WithinSipOltList()
  66:          {
  67:              List<int> sipOltIdList;
  68:              List<Ia.Ngn.Cl.Model.ServiceRequestService> list;
  69:   
  70:              sipOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.SipOltIdList;
  71:   
  72:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  73:              {
  74:                  list = (from srs in db.ServiceRequestServices where srs.Access != null && sipOltIdList.Contains(srs.Access.Olt) select srs).ToList();
  75:              }
  76:   
  77:              return list;
  78:          }
  79:   
  80:          ////////////////////////////////////////////////////////////////////////////
  81:   
  82:          /// <summary>
  83:          /// Services within a SIP designated OLT
  84:          /// </summary>
  85:          public static List<string> ServiceWithinSipOltList()
  86:          {
  87:              List<int> sipOltIdList;
  88:              List<string> list;
  89:   
  90:              sipOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.SipOltIdList;
  91:   
  92:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  93:              {
  94:                  list = (from srs in db.ServiceRequestServices where srs.Access != null && sipOltIdList.Contains(srs.Access.Olt) select srs.Service).ToList();
  95:              }
  96:   
  97:              return list;
  98:          }
  99:   
 100:          ////////////////////////////////////////////////////////////////////////////
 101:   
 102:          /// <summary>
 103:          /// Read service using id
 104:          /// </summary>
 105:          public static Ia.Ngn.Cl.Model.ServiceRequestService ReadIncludeAccess(string id)
 106:          {
 107:              Ia.Ngn.Cl.Model.ServiceRequestService serviceRequestService;
 108:   
 109:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 110:              {
 111:                  serviceRequestService = (from srs in db.ServiceRequestServices.Include(a => a.Access) where srs.Id == id select srs).SingleOrDefault();
 112:              }
 113:   
 114:              return serviceRequestService;
 115:          }
 116:   
 117:          ////////////////////////////////////////////////////////////////////////////
 118:   
 119:          /// <summary>
 120:          /// Read service of a number
 121:          /// </summary>
 122:          public static Ia.Ngn.Cl.Model.ServiceRequestService Read(long number)
 123:          {
 124:              Ia.Ngn.Cl.Model.ServiceRequestService serviceRequestService;
 125:   
 126:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 127:              {
 128:                  serviceRequestService = (from srs in db.ServiceRequestServices where srs.Service == number.ToString() select srs).SingleOrDefault();
 129:              }
 130:   
 131:              return serviceRequestService;
 132:          }
 133:   
 134:          ////////////////////////////////////////////////////////////////////////////
 135:   
 136:          /// <summary>
 137:          /// Read all services for a number list
 138:          /// </summary>
 139:          public static List<Ia.Ngn.Cl.Model.ServiceRequestService> ReadList(ArrayList numberList)
 140:          {
 141:              long i;
 142:              long[] sp;
 143:              List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 144:   
 145:              i = 0;
 146:              sp = new long[numberList.Count];
 147:   
 148:              foreach (long l in numberList) sp[i++] = l;
 149:   
 150:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 151:              {
 152:                  //serviceList = (from q in db.Services where dnList.Contains(q.DN) select q).ToList();
 153:   
 154:                  // var pages = context.Pages.Where(x => keys.Any(key => x.Title.Contains(key)));
 155:                  serviceRequestServiceList = db.ServiceRequestServices.Where(q => sp.Any(v => q.Service == v.ToString())).ToList();
 156:              }
 157:   
 158:              return serviceRequestServiceList;
 159:          }
 160:   
 161:          ////////////////////////////////////////////////////////////////////////////
 162:   
 163:          /// <summary>
 164:          /// Update the service request service table with a list using a service list as referece 
 165:          /// </summary>
 166:          public static void UpdateWithServiceList(List<string> serviceList, List<Ia.Ngn.Cl.Model.ServiceRequestService> newServiceRequestServiceList, out string result)
 167:          {
 168:              int readItemCount, existingItemCount, insertedItemCount, updatedItemCount, deletedItemCount;
 169:              Ia.Ngn.Cl.Model.ServiceRequestService serviceRequestService, newServiceRequestService;
 170:              //Ia.Ngn.Cl.Model.Access access;
 171:              List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList;
 172:   
 173:              readItemCount = existingItemCount = insertedItemCount = updatedItemCount = deletedItemCount = 0;
 174:              result = "";
 175:   
 176:              readItemCount = newServiceRequestServiceList.Count;
 177:   
 178:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 179:              {
 180:                  // Create SRS from newServiceRequestServiceList
 181:                  foreach (Ia.Ngn.Cl.Model.ServiceRequestService srs in newServiceRequestServiceList)
 182:                  {
 183:                      newServiceRequestService = new Ia.Ngn.Cl.Model.ServiceRequestService();
 184:   
 185:                      newServiceRequestService.Copy(srs);
 186:   
 187:                      // important: ServiceRequestService.Update() will only update stored.Access if it is null, or (stored.userId == Guid.Empty && update.Id > stored.Id)
 188:                      if (srs.Access != null) newServiceRequestService.Access = (from a in db.Accesses where a.Id == srs.Access.Id select a).SingleOrDefault();
 189:                      else newServiceRequestService.Access = null;
 190:   
 191:                      serviceRequestService = (from srs2 in db.ServiceRequestServices where srs2.Id == srs.Id select srs2).SingleOrDefault();
 192:   
 193:                      existingItemCount = (serviceRequestService != null) ? 1 : 0;
 194:   
 195:                      if (serviceRequestService == null)
 196:                      {
 197:                          newServiceRequestService.Created = newServiceRequestService.Updated = DateTime.UtcNow.AddHours(3);
 198:   
 199:                          db.ServiceRequestServices.Add(newServiceRequestService);
 200:   
 201:                          Ia.Ngn.Cl.Model.Data.Msmq.ServiceQueue.Enqueue(newServiceRequestService.Service);
 202:                          if (newServiceRequestService.Access != null) Ia.Ngn.Cl.Model.Data.Msmq.AccessNameQueue.Enqueue(newServiceRequestService.Access.Name);
 203:   
 204:                          insertedItemCount++;
 205:                      }
 206:                      else
 207:                      {
 208:                          // below: copy values from newServiceRequestService to serviceRequestService
 209:   
 210:                          if (serviceRequestService.Update(newServiceRequestService))
 211:                          {
 212:                              db.ServiceRequestServices.Attach(serviceRequestService);
 213:                              db.Entry(serviceRequestService).State = System.Data.Entity.EntityState.Modified;
 214:   
 215:                              Ia.Ngn.Cl.Model.Data.Msmq.ServiceQueue.Enqueue(serviceRequestService.Service);
 216:                              if (serviceRequestService.Access != null) Ia.Ngn.Cl.Model.Data.Msmq.AccessNameQueue.Enqueue(serviceRequestService.Access.Name);
 217:   
 218:                              updatedItemCount++;
 219:                          }
 220:                      }
 221:                  }
 222:   
 223:                  // remove SRS that were not present in newServiceRequestServiceList and not in serviceInitialStateList
 224:                  foreach (string service in serviceList)
 225:                  {
 226:                      newServiceRequestService = (from srs in newServiceRequestServiceList where srs.Service == service select srs).SingleOrDefault();
 227:   
 228:                      if (newServiceRequestService == null)
 229:                      {
 230:                          serviceRequestService = (from srs in db.ServiceRequestServices where srs.Service == service select srs).SingleOrDefault();
 231:   
 232:                          if (serviceRequestService != null)
 233:                          {
 234:                              // below: will set all references to this SRS from all SR to null
 235:   
 236:                              serviceRequestList = (from sr in db.ServiceRequests where sr.ServiceRequestService != null && sr.ServiceRequestService.Id == serviceRequestService.Id select sr).ToList();
 237:   
 238:                              foreach (Ia.Ngn.Cl.Model.ServiceRequest sr in serviceRequestList)
 239:                              {
 240:                                  //sr.ServiceRequestService = null;
 241:                              }
 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:                              db.ServiceRequestServices.Remove(serviceRequestService);
 247:   
 248:                              deletedItemCount++;
 249:                          }
 250:                      }
 251:                  }
 252:   
 253:                  db.SaveChanges();
 254:   
 255:                  result = "(" + readItemCount + "/" + existingItemCount + "/" + insertedItemCount + "," + updatedItemCount + "," + deletedItemCount + ") ";
 256:              }
 257:          }
 258:   
 259:          /*
 260:          ////////////////////////////////////////////////////////////////////////////
 261:  
 262:          /// <summary>
 263:          /// Update the ServiceRequestService table's ServiceSuspension and ServiceSuspensionTypeId to the specified state for a number list
 264:          /// </summary>
 265:          public static bool UpdateServiceSuspensionAndServiceSuspensionTypeIdToSpecifiedSuspensionStateForAServiceStringList(List<string> serviceList, bool state, Guid userId)
 266:          {
 267:              bool b;
 268:              Ia.Ngn.Cl.Model.ServiceRequestService serviceRequestService;
 269:  
 270:              b = false;
 271:  
 272:              if (serviceList.Count > 0)
 273:              {
 274:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 275:                  {
 276:                      // below:
 277:                      foreach (string service in serviceList)
 278:                      {
 279:                          serviceRequestService = (from q in db.ServiceRequestServices where q.Service == service select q).SingleOrDefault();
 280:  
 281:                          if (serviceRequestService != null)
 282:                          {
 283:                              if (serviceRequestService.ServiceSuspension != state)
 284:                              {
 285:                                  serviceRequestService.ServiceSuspension = state;
 286:                                  serviceRequestService.Updated = DateTime.UtcNow.AddHours(3);
 287:                                  serviceRequestService.UserId = userId;
 288:  
 289:                                  db.ServiceRequestServices.Attach(serviceRequestService);
 290:                                  db.Entry(serviceRequestService).State = System.Data.Entity.EntityState.Modified;
 291:  
 292:                                  b = true;
 293:                              }
 294:                          }
 295:                      }
 296:  
 297:                      db.SaveChanges();
 298:                  }
 299:              }
 300:              else
 301:              {
 302:              }
 303:  
 304:              return b;
 305:          }
 306:          */
 307:   
 308:          ////////////////////////////////////////////////////////////////////////////
 309:   
 310:          /// <summary>
 311:          ///
 312:          /// </summary>
 313:          public static List<Ia.Ngn.Cl.Model.ServiceRequestService> ReadSingleAsList(string id)
 314:          {
 315:              List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 316:   
 317:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 318:              {
 319:                  serviceRequestServiceList = (from srs in db.ServiceRequestServices where srs.Id == id select srs).ToList();
 320:              }
 321:   
 322:              return serviceRequestServiceList;
 323:          }
 324:   
 325:          ////////////////////////////////////////////////////////////////////////////
 326:   
 327:          /// <summary>
 328:          ///
 329:          /// </summary>
 330:          public static List<Ia.Ngn.Cl.Model.ServiceRequestService> List()
 331:          {
 332:              List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 333:   
 334:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 335:              {
 336:                  serviceRequestServiceList = (from s in db.ServiceRequestServices select s).ToList();
 337:              }
 338:   
 339:              return serviceRequestServiceList;
 340:          }
 341:   
 342:          ////////////////////////////////////////////////////////////////////////////
 343:   
 344:          /// <summary>
 345:          ///
 346:          /// </summary>
 347:          public static List<Ia.Ngn.Cl.Model.ServiceRequestService> ListIncludeAccess()
 348:          {
 349:              List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 350:   
 351:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 352:              {
 353:                  serviceRequestServiceList = (from s in db.ServiceRequestServices select s).Include(u => u.Access).ToList();
 354:              }
 355:   
 356:              return serviceRequestServiceList;
 357:          }
 358:   
 359:          ////////////////////////////////////////////////////////////////////////////
 360:   
 361:          /// <summary>
 362:          ///
 363:          /// </summary>
 364:          public static Dictionary<string, string> ServiceToAccessIdDictionary
 365:          {
 366:              get
 367:              {
 368:                  Dictionary<string, string> dictionary, nullAccessDictionary;
 369:   
 370:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 371:                  {
 372:                      dictionary = (from s in db.ServiceRequestServices where s.Provisioned == true && s.Access != null select new { s.Id, s.Access }).ToDictionary(u => u.Id, u => u.Access.Id);
 373:   
 374:                      nullAccessDictionary = (from s in db.ServiceRequestServices where s.Provisioned == true && s.Access == null select s.Id).ToDictionary(u => u, null);
 375:                  }
 376:   
 377:                  return dictionary.Union(nullAccessDictionary).ToDictionary(u => u.Key, u => u.Value);
 378:              }
 379:          }
 380:   
 381:          ////////////////////////////////////////////////////////////////////////////
 382:   
 383:          /// <summary>
 384:          ///
 385:          /// </summary>
 386:          public static void UpdateServiceSuspension(string service, bool serviceSuspensionState, Guid userId, out Ia.Cl.Model.Result result)
 387:          {
 388:              string serviceRequestServiceId;
 389:              Ia.Ngn.Cl.Model.ServiceRequestService serviceRequestService;
 390:   
 391:              result = new Ia.Cl.Model.Result();
 392:              serviceRequestServiceId = Ia.Ngn.Cl.Model.Business.ServiceRequestService.ServiceRequestServiceId(service, 1); // <type id="1" name="Dn"
 393:   
 394:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 395:              {
 396:                  serviceRequestService = (from srs in db.ServiceRequestServices where srs.Id == serviceRequestServiceId select srs).SingleOrDefault();
 397:   
 398:                  if (serviceRequestService != null)
 399:                  {
 400:                      if (serviceRequestService.ServiceSuspension != serviceSuspensionState)
 401:                      {
 402:                          serviceRequestService.ServiceSuspension = serviceSuspensionState;
 403:                          serviceRequestService.UserId = userId;
 404:   
 405:                          db.ServiceRequestServices.Attach(serviceRequestService);
 406:                          db.Entry(serviceRequestService).Property(x => x.ServiceSuspension).IsModified = true;
 407:   
 408:                          db.SaveChanges();
 409:   
 410:                          result.AddSuccess("ServiceSuspension updated. ");
 411:                      }
 412:                      else
 413:                      {
 414:                          result.AddWarning("Warning: ServiceRequestService ServiceSuspension value was not updated because its the same. ");
 415:                      }
 416:                  }
 417:                  else
 418:                  {
 419:                      result.AddError("Error: serviceRequestService is null. ");
 420:                  }
 421:              }
 422:          }
 423:   
 424:          ////////////////////////////////////////////////////////////////////////////
 425:   
 426:          /// <summary>
 427:          ///
 428:          /// </summary>
 429:          public static Dictionary<string, string> ReadServiceAndOntNameDictionaryWithFourDigitNumberDomain(int fourDigitNumberDomain)
 430:          {
 431:              string s;
 432:              Dictionary<string, string> dictionary;
 433:   
 434:              dictionary = new Dictionary<string, string>(10000);
 435:   
 436:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 437:              {
 438:                  var list = (from srs in db.ServiceRequestServices
 439:                              where SqlFunctions.PatIndex(fourDigitNumberDomain.ToString() + "%", srs.Service) > 0
 440:                              orderby srs.Service ascending
 441:                              select new
 442:                              {
 443:                                  Service = srs.Service,
 444:                                  Access = srs.Access
 445:                              }).ToList();
 446:   
 447:                  foreach (var v in list)
 448:                  {
 449:                      if (v.Access != null) s = v.Service + " (" + v.Access.Name + ")";
 450:                      else s = v.Service;
 451:   
 452:                      dictionary[v.Service] = s;
 453:                  }
 454:              }
 455:   
 456:              return dictionary;
 457:          }
 458:   
 459:          ////////////////////////////////////////////////////////////////////////////
 460:   
 461:          /// <summary>
 462:          ///
 463:          /// </summary>
 464:          public static List<Ia.Ngn.Cl.Model.ServiceRequestService> ReadListOfServiceRequestServicesWithSimilarServiceNumbers(List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList)
 465:          {
 466:              int i;
 467:              string[] sp;
 468:              List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 469:   
 470:              sp = new string[serviceRequestList.Count];
 471:   
 472:              i = 0;
 473:   
 474:              foreach (Ia.Ngn.Cl.Model.ServiceRequest serviceRequest in serviceRequestList) sp[i++] = serviceRequest.Number.ToString();
 475:   
 476:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 477:              {
 478:                  serviceRequestServiceList = (from srs in db.ServiceRequestServices where sp.Contains(srs.Service) select srs).ToList();
 479:              }
 480:   
 481:              return serviceRequestServiceList;
 482:          }
 483:   
 484:          ////////////////////////////////////////////////////////////////////////////    
 485:   
 486:          /// <summary>
 487:          ///
 488:          /// </summary>
 489:          public static List<string> ServiceStringList()
 490:          {
 491:              List<string> serviceStringList;
 492:   
 493:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 494:              {
 495:                  serviceStringList = (from srs in db.ServiceRequestServices where srs.ServiceType == 1 orderby srs.Service ascending select srs.Service).ToList();
 496:              }
 497:   
 498:              return serviceStringList;
 499:          }
 500:   
 501:          ////////////////////////////////////////////////////////////////////////////    
 502:   
 503:          /// <summary>
 504:          ///
 505:          /// </summary>
 506:          public static List<string> ServiceStringWithNonNullAccessList()
 507:          {
 508:              List<string> serviceStringList;
 509:   
 510:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 511:              {
 512:                  serviceStringList = (from srs in db.ServiceRequestServices where srs.ServiceType == 1 && srs.Access != null orderby srs.Service ascending select srs.Service).ToList();
 513:              }
 514:   
 515:              return serviceStringList;
 516:          }
 517:   
 518:          ////////////////////////////////////////////////////////////////////////////
 519:   
 520:          /// <summary>
 521:          ///
 522:          /// </summary>
 523:          public static List<Ia.Ngn.Cl.Model.ServiceRequestService> WithNullAccessList()
 524:          {
 525:              List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 526:   
 527:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 528:              {
 529:                  // below: Take(100) temp
 530:                  serviceRequestServiceList = (from srs in db.ServiceRequestServices where srs.Access == null orderby srs.Service ascending select srs).Take(100).ToList();
 531:              }
 532:   
 533:              return serviceRequestServiceList;
 534:          }
 535:   
 536:          ////////////////////////////////////////////////////////////////////////////
 537:   
 538:          /// <summary>
 539:          ///
 540:          /// </summary>
 541:          public static List<Ia.Ngn.Cl.Model.ServiceRequestService> ServiceSuspensionIsTrueAndProvisionedIsTrueList()
 542:          {
 543:              List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 544:   
 545:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 546:              {
 547:                  serviceRequestServiceList = (from s in db.ServiceRequestServices where s.ServiceSuspension == true && s.Provisioned == true select s).ToList();
 548:              }
 549:   
 550:              return serviceRequestServiceList;
 551:          }
 552:   
 553:          ////////////////////////////////////////////////////////////////////////////
 554:   
 555:          /// <summary>
 556:          ///
 557:          /// </summary>
 558:          public static List<Ia.Ngn.Cl.Model.ServiceRequestService> ServiceSuspensionIsFalseList()
 559:          {
 560:              List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 561:   
 562:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 563:              {
 564:                  serviceRequestServiceList = (from s in db.ServiceRequestServices where s.ServiceSuspension == false select s).ToList();
 565:              }
 566:   
 567:              return serviceRequestServiceList;
 568:          }
 569:   
 570:          ////////////////////////////////////////////////////////////////////////////
 571:   
 572:          /// <summary>
 573:          ///
 574:          /// </summary>
 575:          public static List<string> ServiceSuspensionIsTrueAndProvisionedIsTrueStringNumberList
 576:          {
 577:              get
 578:              {
 579:                  List<string> serviceRequestServiceNumberStringList;
 580:                  List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 581:   
 582:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 583:                  {
 584:                      // below:                
 585:                      serviceRequestServiceList = ServiceSuspensionIsTrueAndProvisionedIsTrueList();
 586:   
 587:                      if (serviceRequestServiceList.Count > 0)
 588:                      {
 589:                          serviceRequestServiceNumberStringList = new List<string>(serviceRequestServiceList.Count);
 590:   
 591:                          foreach (Ia.Ngn.Cl.Model.ServiceRequestService srs in serviceRequestServiceList)
 592:                          {
 593:                              serviceRequestServiceNumberStringList.Add(srs.Service);
 594:                          }
 595:                      }
 596:                      else
 597:                      {
 598:                          // below: not null
 599:                          serviceRequestServiceNumberStringList = new List<string>(1);
 600:                      }
 601:                  }
 602:   
 603:                  return serviceRequestServiceNumberStringList;
 604:              }
 605:          }
 606:   
 607:          ////////////////////////////////////////////////////////////////////////////
 608:   
 609:          /// <summary>
 610:          ///
 611:          /// </summary>
 612:          public static List<string> ServiceSuspensionIsFalseStringNumberList
 613:          {
 614:              get
 615:              {
 616:                  List<string> serviceRequestServiceNumberStringList;
 617:                  List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 618:   
 619:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 620:                  {
 621:                      // below:                
 622:                      serviceRequestServiceList = ServiceSuspensionIsFalseList();
 623:   
 624:                      if (serviceRequestServiceList.Count > 0)
 625:                      {
 626:                          serviceRequestServiceNumberStringList = new List<string>(serviceRequestServiceList.Count);
 627:   
 628:                          foreach (Ia.Ngn.Cl.Model.ServiceRequestService srs in serviceRequestServiceList)
 629:                          {
 630:                              serviceRequestServiceNumberStringList.Add(srs.Service);
 631:                          }
 632:                      }
 633:                      else
 634:                      {
 635:                          // below: not null
 636:                          serviceRequestServiceNumberStringList = new List<string>(1);
 637:                      }
 638:                  }
 639:   
 640:                  return serviceRequestServiceNumberStringList;
 641:              }
 642:          }
 643:   
 644:          ////////////////////////////////////////////////////////////////////////////
 645:   
 646:          /// <summary>
 647:          ///
 648:          /// </summary>
 649:          public static List<Ia.Ngn.Cl.Model.ServiceRequestService> ServiceRequestServiceWithNullAccessList
 650:          {
 651:              get
 652:              {
 653:                  List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 654:   
 655:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 656:                  {
 657:                      serviceRequestServiceList = (from srs in db.ServiceRequestServices where srs.Access == null select srs).ToList();
 658:                  }
 659:   
 660:                  return serviceRequestServiceList;
 661:              }
 662:          }
 663:   
 664:          ////////////////////////////////////////////////////////////////////////////
 665:   
 666:          /// <summary>
 667:          ///
 668:          /// </summary>
 669:          public static List<string> ServiceRequestServiceServiceIdWhereProvisionedIsTrueAndAccessIsNullList()
 670:          {
 671:              List<string> list;
 672:   
 673:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 674:              {
 675:                  list = (from srs in db.ServiceRequestServices where srs.Provisioned == true && srs.Access == null select srs.Id).ToList();
 676:              }
 677:   
 678:              return list;
 679:          }
 680:   
 681:          ////////////////////////////////////////////////////////////////////////////
 682:   
 683:          /// <summary>
 684:          ///
 685:          /// </summary>
 686:          public static List<Ia.Ngn.Cl.Model.ServiceRequestService> WithinSiteList(int siteId)
 687:          {
 688:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site site;
 689:              List<int> siteRouterDomainList;
 690:              List<Ia.Ngn.Cl.Model.ServiceRequestService> list;
 691:              //Dictionary<int, string> areaIdToSymbolDictionary;
 692:   
 693:              // areaIdToSymbolDictionary = Ia.Ngn.Cl.Model.Data.Service.AreaIdToSymbolDictionary;
 694:   
 695:              site = (from s in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.SiteList where s.Id == siteId select s).SingleOrDefault();
 696:   
 697:              if (site != null)
 698:              {
 699:                  siteRouterDomainList = (from r in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.RouterList where r.Site.Id == site.Id select r).SelectMany(d => d.DomainList).ToList();
 700:   
 701:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 702:                  {
 703:                      list = (from srs in db.ServiceRequestServices
 704:                              where srs.Provisioned == true && siteRouterDomainList.Any(u => srs.Service.StartsWith(u.ToString()))
 705:                              select srs).Include(u => u.Access).ToList();
 706:                  }
 707:              }
 708:              else
 709:              {
 710:                  list = new List<Model.ServiceRequestService>();
 711:              }
 712:   
 713:              return list;
 714:          }
 715:   
 716:          ////////////////////////////////////////////////////////////////////////////
 717:   
 718:          /// <summary>
 719:          ///
 720:          /// </summary>
 721:          public static void UpdateServiceRequestServiceAccess(string service, string updatedAccessId, Guid userId, out Ia.Cl.Model.Result result)
 722:          {
 723:              bool saveUpdate;
 724:              string serviceRequestServiceId;
 725:              Ia.Ngn.Cl.Model.ServiceRequestService serviceRequestService;
 726:   
 727:              saveUpdate = false;
 728:              result = new Ia.Cl.Model.Result();
 729:              serviceRequestServiceId = Ia.Ngn.Cl.Model.Business.ServiceRequestService.ServiceRequestServiceId(service, 1); // <type id="1" name="Dn"
 730:   
 731:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 732:              {
 733:                  serviceRequestService = (from srs in db.ServiceRequestServices where srs.Id == serviceRequestServiceId select srs).SingleOrDefault();
 734:   
 735:                  if (serviceRequestService != null)
 736:                  {
 737:                      if (serviceRequestService.Access != null && serviceRequestService.Access.Id != updatedAccessId
 738:                          || serviceRequestService.Access == null && !string.IsNullOrEmpty(updatedAccessId))
 739:                      {
 740:                          serviceRequestService.Access = (from a in db.Accesses where a.Id == updatedAccessId select a).SingleOrDefault();
 741:                          serviceRequestService.UserId = userId;
 742:                          saveUpdate = true;
 743:                      }
 744:                      else if (string.IsNullOrEmpty(updatedAccessId))
 745:                      {
 746:                          // nulling
 747:                          serviceRequestService.Access = null;
 748:                          serviceRequestService.UserId = userId;
 749:                          saveUpdate = true;
 750:                      }
 751:   
 752:                      if (saveUpdate)
 753:                      {
 754:                          db.ServiceRequestServices.Attach(serviceRequestService);
 755:                          db.Entry(serviceRequestService).State = System.Data.Entity.EntityState.Modified;
 756:   
 757:                          db.SaveChanges();
 758:   
 759:                          result.AddSuccess("Access updated. ");
 760:                      }
 761:                      else
 762:                      {
 763:                          result.AddWarning("Warning: ServiceRequestService Access value was not updated. ");
 764:                      }
 765:                  }
 766:                  else
 767:                  {
 768:                      result.AddWarning("Warning: ServiceRequestService is null. ");
 769:                  }
 770:              }
 771:          }
 772:   
 773:          ////////////////////////////////////////////////////////////////////////////    
 774:          ////////////////////////////////////////////////////////////////////////////    
 775:      }
 776:   
 777:      ////////////////////////////////////////////////////////////////////////////
 778:      ////////////////////////////////////////////////////////////////////////////
 779:  }