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

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » ServiceRequestService

Public general use code classes and xml files that we've compiled and used over the years:

Service Request Service support class for Next Generation Network (NGN) data model.

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