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 Dictionary<string, Ia.Ngn.Cl.Model.ServiceRequestService> ServiceToServiceRequestServiceDictionary(List<int> domainList)
 387:          {
 388:              string key;
 389:              List<string> stringDomainList;
 390:              List<Ia.Ngn.Cl.Model.ServiceRequestService> list;
 391:              Dictionary<string, Ia.Ngn.Cl.Model.ServiceRequestService> dictionary;
 392:   
 393:              stringDomainList = new List<string>();
 394:   
 395:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 396:              {
 397:                  if (domainList != null)
 398:                  {
 399:                      foreach (int i in domainList) stringDomainList.Add(i.ToString());
 400:   
 401:                      list = (from srs in db.ServiceRequestServices.Include(a => a.ServiceRequests).Include(x => x.ServiceRequests.Select(y => y.ServiceRequestTypes))
 402:                              where stringDomainList.Any(u => srs.Service.StartsWith(u.ToString()))
 403:                              select srs).ToList();
 404:   
 405:                      dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.ServiceRequestService>(list.Count);
 406:   
 407:                      foreach (var srs in list)
 408:                      {
 409:                          key = srs.Service;
 410:   
 411:                          if (dictionary.ContainsKey(key))
 412:                          {
 413:                              dictionary[key] = srs;
 414:                          }
 415:                          else dictionary[key] = srs;
 416:                      }
 417:                  }
 418:                  else
 419:                  {
 420:                      dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.ServiceRequestService>();
 421:                  }
 422:              }
 423:   
 424:              return dictionary;
 425:          }
 426:   
 427:          ////////////////////////////////////////////////////////////////////////////
 428:   
 429:          /// <summary>
 430:          ///
 431:          /// </summary>
 432:          public static void UpdateServiceSuspension(string service, bool serviceSuspensionState, Guid userId, out Ia.Cl.Model.Result result)
 433:          {
 434:              string serviceRequestServiceId;
 435:              Ia.Ngn.Cl.Model.ServiceRequestService serviceRequestService;
 436:   
 437:              result = new Ia.Cl.Model.Result();
 438:              serviceRequestServiceId = Ia.Ngn.Cl.Model.Business.ServiceRequestService.ServiceRequestServiceId(service, 1); // <type id="1" name="Dn"
 439:   
 440:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 441:              {
 442:                  serviceRequestService = (from srs in db.ServiceRequestServices where srs.Id == serviceRequestServiceId select srs).SingleOrDefault();
 443:   
 444:                  if (serviceRequestService != null)
 445:                  {
 446:                      if (serviceRequestService.ServiceSuspension != serviceSuspensionState)
 447:                      {
 448:                          serviceRequestService.ServiceSuspension = serviceSuspensionState;
 449:                          serviceRequestService.UserId = userId;
 450:   
 451:                          db.ServiceRequestServices.Attach(serviceRequestService);
 452:                          db.Entry(serviceRequestService).Property(x => x.ServiceSuspension).IsModified = true;
 453:   
 454:                          db.SaveChanges();
 455:   
 456:                          result.AddSuccess("ServiceSuspension updated. ");
 457:                      }
 458:                      else
 459:                      {
 460:                          result.AddWarning("Warning: ServiceRequestService ServiceSuspension value was not updated because its the same. ");
 461:                      }
 462:                  }
 463:                  else
 464:                  {
 465:                      result.AddError("Error: serviceRequestService is null. ");
 466:                  }
 467:              }
 468:          }
 469:   
 470:          ////////////////////////////////////////////////////////////////////////////
 471:   
 472:          /// <summary>
 473:          ///
 474:          /// </summary>
 475:          public static Dictionary<string, string> ReadServiceAndOntNameDictionaryWithFourDigitNumberDomain(int fourDigitNumberDomain)
 476:          {
 477:              string s;
 478:              Dictionary<string, string> dictionary;
 479:   
 480:              dictionary = new Dictionary<string, string>(10000);
 481:   
 482:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 483:              {
 484:                  var list = (from srs in db.ServiceRequestServices
 485:                              where SqlFunctions.PatIndex(fourDigitNumberDomain.ToString() + "%", srs.Service) > 0
 486:                              orderby srs.Service ascending
 487:                              select new
 488:                              {
 489:                                  Service = srs.Service,
 490:                                  Access = srs.Access
 491:                              }).ToList();
 492:   
 493:                  foreach (var v in list)
 494:                  {
 495:                      if (v.Access != null) s = v.Service + " (" + v.Access.Name + ")";
 496:                      else s = v.Service;
 497:   
 498:                      dictionary[v.Service] = s;
 499:                  }
 500:              }
 501:   
 502:              return dictionary;
 503:          }
 504:   
 505:          ////////////////////////////////////////////////////////////////////////////
 506:   
 507:          /// <summary>
 508:          ///
 509:          /// </summary>
 510:          public static List<Ia.Ngn.Cl.Model.ServiceRequestService> ReadListOfServiceRequestServicesWithSimilarServiceNumbers(List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList)
 511:          {
 512:              int i;
 513:              string[] sp;
 514:              List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 515:   
 516:              sp = new string[serviceRequestList.Count];
 517:   
 518:              i = 0;
 519:   
 520:              foreach (Ia.Ngn.Cl.Model.ServiceRequest serviceRequest in serviceRequestList) sp[i++] = serviceRequest.Number.ToString();
 521:   
 522:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 523:              {
 524:                  serviceRequestServiceList = (from srs in db.ServiceRequestServices where sp.Contains(srs.Service) select srs).ToList();
 525:              }
 526:   
 527:              return serviceRequestServiceList;
 528:          }
 529:   
 530:          ////////////////////////////////////////////////////////////////////////////    
 531:   
 532:          /// <summary>
 533:          ///
 534:          /// </summary>
 535:          public static List<string> ServiceStringList()
 536:          {
 537:              List<string> serviceStringList;
 538:   
 539:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 540:              {
 541:                  serviceStringList = (from srs in db.ServiceRequestServices where srs.ServiceType == 1 orderby srs.Service ascending select srs.Service).ToList();
 542:              }
 543:   
 544:              return serviceStringList;
 545:          }
 546:   
 547:          ////////////////////////////////////////////////////////////////////////////    
 548:   
 549:          /// <summary>
 550:          ///
 551:          /// </summary>
 552:          public static List<string> ServiceStringWithNonNullAccessList()
 553:          {
 554:              List<string> serviceStringList;
 555:   
 556:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 557:              {
 558:                  serviceStringList = (from srs in db.ServiceRequestServices where srs.ServiceType == 1 && srs.Access != null orderby srs.Service ascending select srs.Service).ToList();
 559:              }
 560:   
 561:              return serviceStringList;
 562:          }
 563:   
 564:          ////////////////////////////////////////////////////////////////////////////
 565:   
 566:          /// <summary>
 567:          ///
 568:          /// </summary>
 569:          public static List<Ia.Ngn.Cl.Model.ServiceRequestService> WithNullAccessList()
 570:          {
 571:              List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 572:   
 573:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 574:              {
 575:                  // below: Take(100) temp
 576:                  serviceRequestServiceList = (from srs in db.ServiceRequestServices where srs.Access == null orderby srs.Service ascending select srs).Take(100).ToList();
 577:              }
 578:   
 579:              return serviceRequestServiceList;
 580:          }
 581:   
 582:          ////////////////////////////////////////////////////////////////////////////
 583:   
 584:          /// <summary>
 585:          ///
 586:          /// </summary>
 587:          public static List<Ia.Ngn.Cl.Model.ServiceRequestService> ServiceSuspensionIsTrueAndProvisionedIsTrueList()
 588:          {
 589:              List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 590:   
 591:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 592:              {
 593:                  serviceRequestServiceList = (from s in db.ServiceRequestServices where s.ServiceSuspension == true && s.Provisioned == true select s).ToList();
 594:              }
 595:   
 596:              return serviceRequestServiceList;
 597:          }
 598:   
 599:          ////////////////////////////////////////////////////////////////////////////
 600:   
 601:          /// <summary>
 602:          ///
 603:          /// </summary>
 604:          public static List<Ia.Ngn.Cl.Model.ServiceRequestService> ServiceSuspensionIsFalseList()
 605:          {
 606:              List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 607:   
 608:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 609:              {
 610:                  serviceRequestServiceList = (from s in db.ServiceRequestServices where s.ServiceSuspension == false select s).ToList();
 611:              }
 612:   
 613:              return serviceRequestServiceList;
 614:          }
 615:   
 616:          ////////////////////////////////////////////////////////////////////////////
 617:   
 618:          /// <summary>
 619:          ///
 620:          /// </summary>
 621:          public static List<string> ServiceSuspensionIsTrueAndProvisionedIsTrueStringNumberList
 622:          {
 623:              get
 624:              {
 625:                  List<string> serviceRequestServiceNumberStringList;
 626:                  List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 627:   
 628:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 629:                  {
 630:                      // below:                
 631:                      serviceRequestServiceList = ServiceSuspensionIsTrueAndProvisionedIsTrueList();
 632:   
 633:                      if (serviceRequestServiceList.Count > 0)
 634:                      {
 635:                          serviceRequestServiceNumberStringList = new List<string>(serviceRequestServiceList.Count);
 636:   
 637:                          foreach (Ia.Ngn.Cl.Model.ServiceRequestService srs in serviceRequestServiceList)
 638:                          {
 639:                              serviceRequestServiceNumberStringList.Add(srs.Service);
 640:                          }
 641:                      }
 642:                      else
 643:                      {
 644:                          // below: not null
 645:                          serviceRequestServiceNumberStringList = new List<string>(1);
 646:                      }
 647:                  }
 648:   
 649:                  return serviceRequestServiceNumberStringList;
 650:              }
 651:          }
 652:   
 653:          ////////////////////////////////////////////////////////////////////////////
 654:   
 655:          /// <summary>
 656:          ///
 657:          /// </summary>
 658:          public static List<string> ServiceSuspensionIsFalseStringNumberList
 659:          {
 660:              get
 661:              {
 662:                  List<string> serviceRequestServiceNumberStringList;
 663:                  List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 664:   
 665:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 666:                  {
 667:                      // below:                
 668:                      serviceRequestServiceList = ServiceSuspensionIsFalseList();
 669:   
 670:                      if (serviceRequestServiceList.Count > 0)
 671:                      {
 672:                          serviceRequestServiceNumberStringList = new List<string>(serviceRequestServiceList.Count);
 673:   
 674:                          foreach (Ia.Ngn.Cl.Model.ServiceRequestService srs in serviceRequestServiceList)
 675:                          {
 676:                              serviceRequestServiceNumberStringList.Add(srs.Service);
 677:                          }
 678:                      }
 679:                      else
 680:                      {
 681:                          // below: not null
 682:                          serviceRequestServiceNumberStringList = new List<string>(1);
 683:                      }
 684:                  }
 685:   
 686:                  return serviceRequestServiceNumberStringList;
 687:              }
 688:          }
 689:   
 690:          ////////////////////////////////////////////////////////////////////////////
 691:   
 692:          /// <summary>
 693:          ///
 694:          /// </summary>
 695:          public static List<Ia.Ngn.Cl.Model.ServiceRequestService> ServiceRequestServiceWithNullAccessList
 696:          {
 697:              get
 698:              {
 699:                  List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 700:   
 701:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 702:                  {
 703:                      serviceRequestServiceList = (from srs in db.ServiceRequestServices where srs.Access == null select srs).ToList();
 704:                  }
 705:   
 706:                  return serviceRequestServiceList;
 707:              }
 708:          }
 709:   
 710:          ////////////////////////////////////////////////////////////////////////////
 711:   
 712:          /// <summary>
 713:          ///
 714:          /// </summary>
 715:          public static List<string> ServiceRequestServiceServiceIdWhereProvisionedIsTrueAndAccessIsNullList()
 716:          {
 717:              List<string> list;
 718:   
 719:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 720:              {
 721:                  list = (from srs in db.ServiceRequestServices where srs.Provisioned == true && srs.Access == null select srs.Id).ToList();
 722:              }
 723:   
 724:              return list;
 725:          }
 726:   
 727:          ////////////////////////////////////////////////////////////////////////////
 728:   
 729:          /// <summary>
 730:          ///
 731:          /// </summary>
 732:          public static List<Ia.Ngn.Cl.Model.ServiceRequestService> WithinSiteList(int siteId)
 733:          {
 734:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site site;
 735:              List<int> siteRouterDomainList;
 736:              List<Ia.Ngn.Cl.Model.ServiceRequestService> list;
 737:              //Dictionary<int, string> areaIdToSymbolDictionary;
 738:   
 739:              // areaIdToSymbolDictionary = Ia.Ngn.Cl.Model.Data.Service.AreaIdToSymbolDictionary;
 740:   
 741:              site = (from s in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.SiteList where s.Id == siteId select s).SingleOrDefault();
 742:   
 743:              if (site != null)
 744:              {
 745:                  siteRouterDomainList = (from r in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.RouterList where r.Site.Id == site.Id select r).SelectMany(d => d.DomainList).ToList();
 746:   
 747:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 748:                  {
 749:                      list = (from srs in db.ServiceRequestServices
 750:                              where srs.Provisioned == true && siteRouterDomainList.Any(u => srs.Service.StartsWith(u.ToString()))
 751:                              select srs).Include(u => u.Access).ToList();
 752:                  }
 753:              }
 754:              else
 755:              {
 756:                  list = new List<Model.ServiceRequestService>();
 757:              }
 758:   
 759:              return list;
 760:          }
 761:   
 762:          ////////////////////////////////////////////////////////////////////////////
 763:   
 764:          /// <summary>
 765:          ///
 766:          /// </summary>
 767:          public static void UpdateServiceRequestServiceAccess(string service, string updatedAccessId, Guid userId, out Ia.Cl.Model.Result result)
 768:          {
 769:              bool saveUpdate;
 770:              string serviceRequestServiceId;
 771:              Ia.Ngn.Cl.Model.ServiceRequestService serviceRequestService;
 772:   
 773:              saveUpdate = false;
 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.Access != null && serviceRequestService.Access.Id != updatedAccessId
 784:                          || serviceRequestService.Access == null && !string.IsNullOrEmpty(updatedAccessId))
 785:                      {
 786:                          serviceRequestService.Access = (from a in db.Accesses where a.Id == updatedAccessId select a).SingleOrDefault();
 787:                          serviceRequestService.UserId = userId;
 788:                          saveUpdate = true;
 789:                      }
 790:                      else if (string.IsNullOrEmpty(updatedAccessId))
 791:                      {
 792:                          // nulling
 793:                          serviceRequestService.Access = null;
 794:                          serviceRequestService.UserId = userId;
 795:                          saveUpdate = true;
 796:                      }
 797:   
 798:                      if (saveUpdate)
 799:                      {
 800:                          db.ServiceRequestServices.Attach(serviceRequestService);
 801:                          db.Entry(serviceRequestService).State = System.Data.Entity.EntityState.Modified;
 802:   
 803:                          db.SaveChanges();
 804:   
 805:                          result.AddSuccess("Access updated. ");
 806:                      }
 807:                      else
 808:                      {
 809:                          result.AddWarning("Warning: ServiceRequestService Access value was not updated. ");
 810:                      }
 811:                  }
 812:                  else
 813:                  {
 814:                      result.AddWarning("Warning: ServiceRequestService is null. ");
 815:                  }
 816:              }
 817:          }
 818:   
 819:          ////////////////////////////////////////////////////////////////////////////    
 820:          ////////////////////////////////////////////////////////////////////////////    
 821:      }
 822:   
 823:      ////////////////////////////////////////////////////////////////////////////
 824:      ////////////////////////////////////////////////////////////////////////////
 825:  }