)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Home » Code Library » ServiceRequestService (Ia.Ftn.Cl.Models.Data)

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

Service Request Service support class for Fixed Telecommunications Network (FTN) data model.

    1: using Microsoft.EntityFrameworkCore;
    2: using System;
    3: using System.Collections.Generic;
    4: using System.Data;
    5: using System.Linq;
    6:  
    7: namespace Ia.Ftn.Cl.Models.Data
    8: {
    9:     ////////////////////////////////////////////////////////////////////////////
   10:  
   11:     /// <summary publish="true">
   12:     /// Service Request Service support class for Fixed Telecommunications Network (FTN) data model.
   13:     /// </summary>
   14:     /// 
   15:     /// <remarks> 
   16:     /// Copyright © 2006-2022 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   17:     /// </remarks> 
   18:     public class ServiceRequestService
   19:     {
   20:         /// <summary/>
   21:         public ServiceRequestService() { }
   22:  
   23:         ////////////////////////////////////////////////////////////////////////////
   24:  
   25:         /// <summary>
   26:         /// Read service
   27:         /// </summary>
   28:         public static Ia.Ftn.Cl.Models.ServiceRequestService Read(string service)
   29:         {
   30:             Ia.Ftn.Cl.Models.ServiceRequestService serviceRequestService;
   31:  
   32:             using (var db = new Ia.Ftn.Cl.Db())
   33:             {
   34:                 serviceRequestService = (from srs in db.ServiceRequestServices
   35:                                          where srs.Service == service
   36:                                          select srs).SingleOrDefault();
   37:             }
   38:  
   39:             return serviceRequestService;
   40:         }
   41:  
   42:         ////////////////////////////////////////////////////////////////////////////
   43:  
   44:         /// <summary>
   45:         /// Read service
   46:         /// </summary>
   47:         public static Ia.Ftn.Cl.Models.ServiceRequestService ReadIncludeServiceRequests(string service)
   48:         {
   49:             Ia.Ftn.Cl.Models.ServiceRequestService serviceRequestService;
   50:  
   51:             using (var db = new Ia.Ftn.Cl.Db())
   52:             {
   53:                 serviceRequestService = (from srs in db.ServiceRequestServices.Include(a => a.ServiceRequests) where srs.Service == service select srs).SingleOrDefault();
   54:             }
   55:  
   56:             return serviceRequestService;
   57:         }
   58:  
   59:         ////////////////////////////////////////////////////////////////////////////
   60:  
   61:         /// <summary>
   62:         /// Read service using id
   63:         /// </summary>
   64:         public static Ia.Ftn.Cl.Models.ServiceRequestService ReadById(string id)
   65:         {
   66:             Ia.Ftn.Cl.Models.ServiceRequestService serviceRequestService;
   67:  
   68:             using (var db = new Ia.Ftn.Cl.Db())
   69:             {
   70:                 serviceRequestService = (from srs in db.ServiceRequestServices where srs.Id == id select srs).SingleOrDefault();
   71:             }
   72:  
   73:             return serviceRequestService;
   74:         }
   75:  
   76:         ////////////////////////////////////////////////////////////////////////////
   77:  
   78:         /// <summary>
   79:         /// Service request services within a SIP designated OLT
   80:         /// </summary>
   81:         public static List<Ia.Ftn.Cl.Models.ServiceRequestService> WithinSipOltList()
   82:         {
   83:             List<Ia.Ftn.Cl.Models.ServiceRequestService> list;
   84:  
   85:             var sipOltIdList = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.SipOltIdList;
   86:  
   87:             using (var db = new Ia.Ftn.Cl.Db())
   88:             {
   89:                 list = (from srs in db.ServiceRequestServices
   90:                         where srs.Access != null && sipOltIdList.Contains(srs.Access.Olt)
   91:                         select srs).Include(u => u.Access).ToList();
   92:             }
   93:  
   94:             return list;
   95:         }
   96:  
   97:         ////////////////////////////////////////////////////////////////////////////
   98:  
   99:         /// <summary>
  100:         /// Service request services within a designated OLT
  101:         /// </summary>
  102:         public static List<Ia.Ftn.Cl.Models.ServiceRequestService> WithinOltList(int oltId)
  103:         {
  104:             List<Ia.Ftn.Cl.Models.ServiceRequestService> list;
  105:  
  106:             if (oltId > 0)
  107:             {
  108:                 using (var db = new Ia.Ftn.Cl.Db())
  109:                 {
  110:                     list = (from srs in db.ServiceRequestServices.Include(a => a.Access)
  111:                             where srs.Access != null && srs.Access.Olt == oltId
  112:                             select srs).Include(u => u.Access).ToList();
  113:                 }
  114:             }
  115:             else list = new List<Ia.Ftn.Cl.Models.ServiceRequestService>();
  116:  
  117:             return list;
  118:         }
  119:  
  120:         ////////////////////////////////////////////////////////////////////////////
  121:  
  122:         /// <summary>
  123:         /// Services within a SIP designated OLT
  124:         /// </summary>
  125:         public static List<string> ServiceWithinSipOltList()
  126:         {
  127:             List<string> list;
  128:  
  129:             var sipOltIdList = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.SipOltIdList;
  130:  
  131:             using (var db = new Ia.Ftn.Cl.Db())
  132:             {
  133:                 list = (from srs in db.ServiceRequestServices
  134:                         where srs.Access != null && sipOltIdList.Contains(srs.Access.Olt)
  135:                         select srs.Service).ToList();
  136:             }
  137:  
  138:             return list;
  139:         }
  140:  
  141:         ////////////////////////////////////////////////////////////////////////////
  142:  
  143:         /// <summary>
  144:         /// Read service using id
  145:         /// </summary>
  146:         public static Ia.Ftn.Cl.Models.ServiceRequestService ReadIncludeAccess(string id)
  147:         {
  148:             Ia.Ftn.Cl.Models.ServiceRequestService serviceRequestService;
  149:  
  150:             using (var db = new Ia.Ftn.Cl.Db())
  151:             {
  152:                 serviceRequestService = (from srs in db.ServiceRequestServices.Include(a => a.Access)
  153:                                          where srs.Id == id
  154:                                          select srs).AsNoTracking().SingleOrDefault();
  155:             }
  156:  
  157:             return serviceRequestService;
  158:         }
  159:  
  160:         ////////////////////////////////////////////////////////////////////////////
  161:  
  162:         /// <summary>
  163:         /// Read service of a number
  164:         /// </summary>
  165:         public static Ia.Ftn.Cl.Models.ServiceRequestService Read(long number)
  166:         {
  167:             Ia.Ftn.Cl.Models.ServiceRequestService serviceRequestService;
  168:  
  169:             using (var db = new Ia.Ftn.Cl.Db())
  170:             {
  171:                 serviceRequestService = (from srs in db.ServiceRequestServices where srs.Service == number.ToString() select srs).SingleOrDefault();
  172:             }
  173:  
  174:             return serviceRequestService;
  175:         }
  176:  
  177:         /*
  178:         ////////////////////////////////////////////////////////////////////////////
  179: 
  180:         /// <summary>
  181:         /// Read all services for a number list
  182:         /// </summary>
  183:         public static List<Ia.Ftn.Cl.Model.ServiceRequestService> ReadList(ArrayList numberList)
  184:         {
  185:             long i;
  186:             long[] sp;
  187:             List<Ia.Ftn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
  188: 
  189:             i = 0;
  190:             sp = new long[numberList.Count];
  191: 
  192:             foreach (long l in numberList) sp[i++] = l;
  193: 
  194:             using (var db = new Ia.Ftn.Cl.Model.Ftn())
  195:             {
  196:                 //serviceList = (from q in db.Services where dnList.Contains(q.DN) select q).ToList();
  197: 
  198:                 // var pages = context.Pages.Where(x => keys.Any(key => x.Title.Contains(key)));
  199:                 serviceRequestServiceList = db.ServiceRequestServices.Where(q => sp.Any(v => q.Service == v.ToString())).ToList();
  200:             }
  201: 
  202:             return serviceRequestServiceList;
  203:         }
  204:         */
  205:  
  206:         ////////////////////////////////////////////////////////////////////////////
  207:  
  208:         /// <summary>
  209:         /// Update the service request service table with a list using a service list as referece 
  210:         /// </summary>
  211:         public static void UpdateWithServiceList(List<string> serviceList, List<Ia.Ftn.Cl.Models.ServiceRequestService> newServiceRequestServiceList, out string result)
  212:         {
  213:             int readItemCount, existingItemCount, insertedItemCount, updatedItemCount, deletedItemCount;
  214:             Ia.Ftn.Cl.Models.ServiceRequestService serviceRequestService, newServiceRequestService;
  215:  
  216:             readItemCount = existingItemCount = insertedItemCount = updatedItemCount = deletedItemCount = 0;
  217:             result = string.Empty;
  218:  
  219:             readItemCount = newServiceRequestServiceList.Count;
  220:  
  221:             using (var db = new Ia.Ftn.Cl.Db())
  222:             {
  223:                 // Create SRS from newServiceRequestServiceList
  224:                 foreach (Ia.Ftn.Cl.Models.ServiceRequestService srs in newServiceRequestServiceList)
  225:                 {
  226:                     if (Ia.Ftn.Cl.Models.Business.Service.ServiceHasEightDigitsAndIsWithinAllowedDomainList(srs.Service))
  227:                     {
  228:                         newServiceRequestService = new Ia.Ftn.Cl.Models.ServiceRequestService();
  229:  
  230:                         newServiceRequestService.Copy(srs);
  231:  
  232:                         // important: ServiceRequestService.Update() will only update stored.Access if it is null, or (stored.userId == string.Empty && update.Id > stored.Id)
  233:                         if (srs.Access != null) newServiceRequestService.Access = (from a in db.Accesses
  234:                                                                                    where a.Id == srs.Access.Id
  235:                                                                                    select a).SingleOrDefault();
  236:                         else newServiceRequestService.Access = null;
  237:  
  238:                         serviceRequestService = (from srs2 in db.ServiceRequestServices
  239:                                                  where srs2.Id == srs.Id
  240:                                                  select srs2).Include(u => u.Access).SingleOrDefault();
  241:  
  242:                         if (serviceRequestService != null) existingItemCount++;
  243:  
  244:                         if (serviceRequestService == null)
  245:                         {
  246:                             newServiceRequestService.Created = newServiceRequestService.Updated = DateTime.UtcNow.AddHours(3);
  247:  
  248:                             db.ServiceRequestServices.Add(newServiceRequestService);
  249:  
  250:                             //Ia.Ftn.Cl.Model.Data.MessageQueue.ServiceQueue.Enqueue(newServiceRequestService.Service);
  251:                             //if (newServiceRequestService.Access != null) Ia.Ftn.Cl.Model.Data.MessageQueue.AccessNameQueue.Enqueue(newServiceRequestService.Access.Name);
  252:  
  253:                             insertedItemCount++;
  254:                         }
  255:                         else
  256:                         {
  257:                             // below: copy values from newServiceRequestService to serviceRequestService
  258:  
  259:                             if (serviceRequestService.Update(newServiceRequestService))
  260:                             {
  261:                                 db.ServiceRequestServices.Attach(serviceRequestService);
  262:                                 db.Entry(serviceRequestService).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
  263:  
  264:                                 //Ia.Ftn.Cl.Model.Data.MessageQueue.ServiceQueue.Enqueue(serviceRequestService.Service);
  265:                                 //if (serviceRequestService.Access != null) Ia.Ftn.Cl.Model.Data.MessageQueue.AccessNameQueue.Enqueue(serviceRequestService.Access.Name);
  266:  
  267:                                 updatedItemCount++;
  268:                             }
  269:  
  270:                         }
  271:                     }
  272:                     else
  273:                     {
  274:                         throw new System.ArgumentOutOfRangeException("Service " + srs.Service + " string format is not legal");
  275:                     }
  276:                 }
  277:  
  278:                 /*
  279:                 // remove SRS that were not present in newServiceRequestServiceList
  280:                 foreach (string service in serviceList)
  281:                 {
  282:                     newServiceRequestService = (from srs in newServiceRequestServiceList where srs.Service == service select srs).SingleOrDefault();
  283: 
  284:                     if (newServiceRequestService == null)
  285:                     {
  286:                         serviceRequestService = (from srs in db.ServiceRequestServices where srs.Service == service select srs).SingleOrDefault();
  287: 
  288:                         if (serviceRequestService != null)
  289:                         {
  290:                             // below: will set all references to this SRS from all SR to null
  291: 
  292:                             serviceRequestList = (from sr in db.ServiceRequests where sr.ServiceRequestService != null && sr.ServiceRequestService.Id == serviceRequestService.Id select sr).ToList();
  293: 
  294:                             foreach (Ia.Ftn.Cl.Model.ServiceRequest sr in serviceRequestList)
  295:                             {
  296:                                 //sr.ServiceRequestService = null;
  297:                             }
  298: 
  299:                             Ia.Ftn.Cl.Model.Data.MessageQueue.ServiceQueue.Enqueue(serviceRequestService.Service);
  300:                             if (serviceRequestService.Access != null) Ia.Ftn.Cl.Model.Data.MessageQueue.AccessNameQueue.Enqueue(serviceRequestService.Access.Name);
  301: 
  302:                             db.ServiceRequestServices.Remove(serviceRequestService); // I will not delete any SRS record
  303: 
  304:                             deletedItemCount++;
  305:                         }
  306:                     }
  307:                 }
  308:                 */
  309:  
  310:                 db.SaveChanges();
  311:  
  312:                 result = "(" + readItemCount + "/" + existingItemCount + "/" + insertedItemCount + "," + updatedItemCount + "," + deletedItemCount + ") ";
  313:             }
  314:         }
  315:  
  316:         /*
  317:         ////////////////////////////////////////////////////////////////////////////
  318: 
  319:         /// <summary>
  320:         /// Update the ServiceRequestService table's ServiceSuspension and ServiceSuspensionTypeId to the specified state for a number list
  321:         /// </summary>
  322:         public static bool UpdateServiceSuspensionAndServiceSuspensionTypeIdToSpecifiedSuspensionStateForAServiceStringList(List<string> serviceList, bool state, string userId)
  323:         {
  324:             bool b;
  325:             Ia.Ftn.Cl.Model.ServiceRequestService serviceRequestService;
  326: 
  327:             b = false;
  328: 
  329:             if (serviceList.Count > 0)
  330:             {
  331:                 using (var db = new Ia.Ftn.Cl.Model.Ftn())
  332:                 {
  333:                     // below:
  334:                     foreach (string service in serviceList)
  335:                     {
  336:                         serviceRequestService = (from q in db.ServiceRequestServices where q.Service == service select q).SingleOrDefault();
  337: 
  338:                         if (serviceRequestService != null)
  339:                         {
  340:                             if (serviceRequestService.ServiceSuspension != state)
  341:                             {
  342:                                 serviceRequestService.ServiceSuspension = state;
  343:                                 serviceRequestService.Updated = DateTime.UtcNow.AddHours(3);
  344:                                 serviceRequestService.StaffIdentityUser.Id = userId;
  345: 
  346:                                 db.ServiceRequestServices.Attach(serviceRequestService);
  347:                                 db.Entry(serviceRequestService).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
  348: 
  349:                                 b = true;
  350:                             }
  351:                         }
  352:                     }
  353: 
  354:                     db.SaveChanges();
  355:                 }
  356:             }
  357:             else
  358:             {
  359:             }
  360: 
  361:             return b;
  362:         }
  363:         */
  364:  
  365:         ////////////////////////////////////////////////////////////////////////////
  366:  
  367:         /// <summary>
  368:         ///
  369:         /// </summary>
  370:         public static List<Ia.Ftn.Cl.Models.ServiceRequestService> ReadSingleAsList(string id)
  371:         {
  372:             List<Ia.Ftn.Cl.Models.ServiceRequestService> serviceRequestServiceList;
  373:  
  374:             using (var db = new Ia.Ftn.Cl.Db())
  375:             {
  376:                 serviceRequestServiceList = (from srs in db.ServiceRequestServices where srs.Id == id select srs).ToList();
  377:             }
  378:  
  379:             return serviceRequestServiceList;
  380:         }
  381:  
  382:         ////////////////////////////////////////////////////////////////////////////
  383:  
  384:         /// <summary>
  385:         ///
  386:         /// </summary>
  387:         public static List<string> ServiceList()
  388:         {
  389:             List<string> list;
  390:  
  391:             using (var db = new Ia.Ftn.Cl.Db())
  392:             {
  393:                 list = (from srs in db.ServiceRequestServices select srs.Service).ToList();
  394:             }
  395:  
  396:             return list;
  397:         }
  398:  
  399:         ////////////////////////////////////////////////////////////////////////////
  400:  
  401:         /// <summary>
  402:         ///
  403:         /// </summary>
  404:         public static Dictionary<string, string> ServiceDictionary()
  405:         {
  406:             Dictionary<string, string> dictionary;
  407:  
  408:             using (var db = new Ia.Ftn.Cl.Db())
  409:             {
  410:                 dictionary = (from srs in db.ServiceRequestServices
  411:                               select new { srs.Service }).AsNoTracking().ToDictionary(u => u.Service, u => u.Service);
  412:             }
  413:  
  414:             return dictionary.ToDictionary(u => u.Key, u => u.Value);
  415:         }
  416:  
  417:         ////////////////////////////////////////////////////////////////////////////
  418:  
  419:         /// <summary>
  420:         ///
  421:         /// </summary>
  422:         public static List<string> ServiceIdList
  423:         {
  424:             get
  425:             {
  426:                 List<string> list;
  427:  
  428:                 using (var db = new Ia.Ftn.Cl.Db())
  429:                 {
  430:                     list = (from srs in db.ServiceRequestServices select srs.Id).ToList();
  431:                 }
  432:  
  433:                 return list;
  434:             }
  435:         }
  436:  
  437:         ////////////////////////////////////////////////////////////////////////////
  438:  
  439:         /// <summary>
  440:         ///
  441:         /// </summary>
  442:         public static List<Ia.Ftn.Cl.Models.ServiceRequestService> List()
  443:         {
  444:             List<Ia.Ftn.Cl.Models.ServiceRequestService> serviceRequestServiceList;
  445:  
  446:             using (var db = new Ia.Ftn.Cl.Db())
  447:             {
  448:                 serviceRequestServiceList = (from srs in db.ServiceRequestServices select srs).ToList();
  449:             }
  450:  
  451:             return serviceRequestServiceList;
  452:         }
  453:  
  454:         ////////////////////////////////////////////////////////////////////////////
  455:  
  456:         /// <summary>
  457:         ///
  458:         /// </summary>
  459:         public static List<Ia.Ftn.Cl.Models.ServiceRequestService> List(string service)
  460:         {
  461:             List<Ia.Ftn.Cl.Models.ServiceRequestService> serviceRequestServiceList;
  462:  
  463:             if (!string.IsNullOrEmpty(service))
  464:             {
  465:                 using (var db = new Ia.Ftn.Cl.Db())
  466:                 {
  467:                     serviceRequestServiceList = (from srs in db.ServiceRequestServices where srs.Service == service select srs).ToList();
  468:                 }
  469:             }
  470:             else serviceRequestServiceList = new List<Models.ServiceRequestService>();
  471:  
  472:             return serviceRequestServiceList;
  473:         }
  474:  
  475:         ////////////////////////////////////////////////////////////////////////////
  476:  
  477:         /// <summary>
  478:         ///
  479:         /// </summary>
  480:         public static List<Ia.Ftn.Cl.Models.ServiceRequestService> ListIncludeAccess()
  481:         {
  482:             List<Ia.Ftn.Cl.Models.ServiceRequestService> serviceRequestServiceList;
  483:  
  484:             using (var db = new Ia.Ftn.Cl.Db())
  485:             {
  486:                 serviceRequestServiceList = (from srs in db.ServiceRequestServices select srs).Include(u => u.Access).ToList();
  487:             }
  488:  
  489:             return serviceRequestServiceList;
  490:         }
  491:  
  492:         ////////////////////////////////////////////////////////////////////////////
  493:  
  494:         /// <summary>
  495:         /// 
  496:         /// </summary>
  497:         public static List<Ia.Ftn.Cl.Models.Ui.ServiceRequestService> UiServiceRequestServiceList()
  498:         {
  499:             List<Ia.Ftn.Cl.Models.ServiceRequestService> srsList;
  500:             List<Ia.Ftn.Cl.Models.Ui.ServiceRequestService> list;
  501:  
  502:             using (var db = new Ia.Ftn.Cl.Db())
  503:             {
  504:                 srsList = (from srs in db.ServiceRequestServices select srs).ToList();
  505:  
  506:                 list = (from srs in srsList
  507:                         select new Ia.Ftn.Cl.Models.Ui.ServiceRequestService()
  508:                         {
  509:                             Id = srs.Id,
  510:                             AbbriviatedCalling = srs.AbbriviatedCalling,
  511:                             Access = srs.Access,
  512:                             AlarmCall = srs.AlarmCall,
  513:                             CallBarring = srs.CallBarring,
  514:                             CallerId = srs.CallerId,
  515:                             CallForwarding = srs.CallForwarding,
  516:                             CallWaiting = srs.CallWaiting,
  517:                             ConferenceCall = srs.ConferenceCall,
  518:                             Created = srs.Created,
  519:                             InternationalCalling = srs.InternationalCalling,
  520:                             InternationalCallingUserControlled = srs.InternationalCallingUserControlled,
  521:                             LastRequestDateTime = srs.LastRequestDateTime,
  522:                             Provisioned = srs.Provisioned,
  523:                             Service = srs.Service,
  524:                             Serial = srs.Serial,
  525:                             ServiceType = srs.ServiceType,
  526:                             //ServiceSuspension = srs.ServiceSuspension,
  527:                             Type = srs.Type,
  528:                             Updated = srs.Updated
  529:                         }).ToList();
  530:  
  531:                 return list.Distinct().ToList();
  532:             }
  533:         }
  534:  
  535:         ////////////////////////////////////////////////////////////////////////////
  536:  
  537:         /// <summary>
  538:         /// 
  539:         /// </summary>
  540:         public static List<Ia.Ftn.Cl.Models.Ui.ServiceRequestService> UiServiceRequestServiceList(string service)
  541:         {
  542:             List<Ia.Ftn.Cl.Models.ServiceRequestService> srsList;
  543:             List<Ia.Ftn.Cl.Models.Ui.ServiceRequestService> list;
  544:  
  545:             if (!string.IsNullOrEmpty(service))
  546:             {
  547:                 using (var db = new Ia.Ftn.Cl.Db())
  548:                 {
  549:                     srsList = (from srs in db.ServiceRequestServices where srs.Service == service select srs).Include(u => u.Access).ToList();
  550:  
  551:                     list = (from srs in srsList
  552:                             select new Ia.Ftn.Cl.Models.Ui.ServiceRequestService()
  553:                             {
  554:                                 Id = srs.Id,
  555:                                 AbbriviatedCalling = srs.AbbriviatedCalling,
  556:                                 Access = srs.Access,
  557:                                 AlarmCall = srs.AlarmCall,
  558:                                 CallBarring = srs.CallBarring,
  559:                                 CallerId = srs.CallerId,
  560:                                 CallForwarding = srs.CallForwarding,
  561:                                 CallWaiting = srs.CallWaiting,
  562:                                 ConferenceCall = srs.ConferenceCall,
  563:                                 Created = srs.Created,
  564:                                 InternationalCalling = srs.InternationalCalling,
  565:                                 InternationalCallingUserControlled = srs.InternationalCallingUserControlled,
  566:                                 LastRequestDateTime = srs.LastRequestDateTime,
  567:                                 Provisioned = srs.Provisioned,
  568:                                 Service = srs.Service,
  569:                                 Serial = srs.Serial,
  570:                                 ServiceType = srs.ServiceType,
  571:                                 //ServiceSuspension = srs.ServiceSuspension,
  572:                                 Type = srs.Type,
  573:                                 Updated = srs.Updated
  574:                             }).ToList();
  575:                 }
  576:             }
  577:             else list = new List<Ia.Ftn.Cl.Models.Ui.ServiceRequestService>();
  578:  
  579:             return list.Distinct().ToList();
  580:         }
  581:  
  582:         ////////////////////////////////////////////////////////////////////////////
  583:  
  584:         /// <summary>
  585:         /// 
  586:         /// </summary>
  587:         public static List<Ia.Ftn.Cl.Models.Business.ServiceSerialRequestService> ServiceSerialRequestServiceList()
  588:         {
  589:             List<Ia.Ftn.Cl.Models.ServiceRequestService> srsList;
  590:             List<Ia.Ftn.Cl.Models.Business.ServiceSerialRequestService> list;
  591:  
  592:             using (var db = new Ia.Ftn.Cl.Db())
  593:             {
  594:                 srsList = (from srs in db.ServiceRequestServices select srs).ToList();
  595:  
  596:                 list = (from srs in srsList
  597:                         select new Ia.Ftn.Cl.Models.Business.ServiceSerialRequestService()
  598:                         {
  599:                             Id = srs.Service + ":" + srs.Serial,
  600:                             AbbriviatedCalling = srs.AbbriviatedCalling,
  601:                             //Access = srs.Access,
  602:                             AlarmCall = srs.AlarmCall,
  603:                             WakeupCall = srs.WakeupCall,
  604:                             CallBarring = srs.CallBarring,
  605:                             CallerId = srs.CallerId,
  606:                             CallForwarding = srs.CallForwarding,
  607:                             CallWaiting = srs.CallWaiting,
  608:                             ConferenceCall = srs.ConferenceCall,
  609:                             InternationalCalling = srs.InternationalCalling,
  610:                             InternationalCallingUserControlled = srs.InternationalCallingUserControlled,
  611:                             Provisioned = srs.Provisioned,
  612:                             Service = srs.Service,
  613:                             Serial = srs.Serial,
  614:                         }).ToList();
  615:  
  616:                 return list.Distinct().ToList();
  617:             }
  618:         }
  619:  
  620:         ////////////////////////////////////////////////////////////////////////////
  621:  
  622:         /// <summary>
  623:         /// 
  624:         /// </summary>
  625:         public static List<Ia.Ftn.Cl.Models.Business.ServiceSerialRequestService> ServiceSerialRequestServiceList(string service)
  626:         {
  627:             List<Ia.Ftn.Cl.Models.ServiceRequestService> srsList;
  628:             List<Ia.Ftn.Cl.Models.Business.ServiceSerialRequestService> list;
  629:  
  630:             if (!string.IsNullOrEmpty(service))
  631:             {
  632:                 using (var db = new Ia.Ftn.Cl.Db())
  633:                 {
  634:                     srsList = (from srs in db.ServiceRequestServices where srs.Service == service select srs).ToList();
  635:  
  636:                     list = (from srs in srsList
  637:                             select new Ia.Ftn.Cl.Models.Business.ServiceSerialRequestService()
  638:                             {
  639:                                 Id = srs.Service + ":" + srs.Serial,
  640:                                 AbbriviatedCalling = srs.AbbriviatedCalling,
  641:                                 //Access = srs.Access,
  642:                                 AlarmCall = srs.AlarmCall,
  643:                                 WakeupCall = srs.WakeupCall,
  644:                                 CallBarring = srs.CallBarring,
  645:                                 CallerId = srs.CallerId,
  646:                                 CallForwarding = srs.CallForwarding,
  647:                                 CallWaiting = srs.CallWaiting,
  648:                                 ConferenceCall = srs.ConferenceCall,
  649:                                 InternationalCalling = srs.InternationalCalling,
  650:                                 InternationalCallingUserControlled = srs.InternationalCallingUserControlled,
  651:                                 Provisioned = srs.Provisioned,
  652:                                 Service = srs.Service,
  653:                                 Serial = srs.Serial,
  654:                             }).ToList();
  655:                 }
  656:             }
  657:             else list = new List<Ia.Ftn.Cl.Models.Business.ServiceSerialRequestService>();
  658:  
  659:             return list.Distinct().ToList();
  660:         }
  661:  
  662:         ////////////////////////////////////////////////////////////////////////////
  663:         ////////////////////////////////////////////////////////////////////////////
  664:  
  665:         /// <summary>
  666:         ///
  667:         /// </summary>
  668:         public static Dictionary<string, string> ServiceIdToAccessIdDictionary
  669:         {
  670:             get
  671:             {
  672:                 Dictionary<string, string> dictionary, nullAccessDictionary;
  673:  
  674:                 using (var db = new Ia.Ftn.Cl.Db())
  675:                 {
  676:                     dictionary = (from srs in db.ServiceRequestServices where srs.Access != null select new { srs.Id, srs.Access }).ToDictionary(u => u.Id, u => u.Access.Id);
  677:                     nullAccessDictionary = (from s in db.ServiceRequestServices where s.Access == null select new { s.Id, s.Access }).ToDictionary(u => u.Id, u => string.Empty);
  678:                 }
  679:  
  680:                 return dictionary.Union(nullAccessDictionary).ToDictionary(u => u.Key, u => u.Value);
  681:             }
  682:         }
  683:  
  684:         ////////////////////////////////////////////////////////////////////////////
  685:  
  686:         /// <summary>
  687:         ///
  688:         /// </summary>
  689:         public static Dictionary<string, string> ServiceToAccessIdDictionary
  690:         {
  691:             get
  692:             {
  693:                 string key;
  694:                 Dictionary<string, string> serviceToAccessIdDictionary, serviceIdToAccessIdDictionary;
  695:  
  696:                 serviceIdToAccessIdDictionary = Ia.Ftn.Cl.Models.Data.ServiceRequestService.ServiceIdToAccessIdDictionary;
  697:  
  698:                 serviceToAccessIdDictionary = new Dictionary<string, string>(serviceIdToAccessIdDictionary.Count);
  699:  
  700:                 foreach (KeyValuePair<string, string> kvp in serviceIdToAccessIdDictionary)
  701:                 {
  702:                     key = Ia.Ftn.Cl.Models.Business.ServiceRequestService.ServiceIdToService(kvp.Key);
  703:  
  704:                     serviceToAccessIdDictionary[key] = kvp.Value;
  705:                 }
  706:  
  707:                 return serviceToAccessIdDictionary;
  708:             }
  709:         }
  710:  
  711:         ////////////////////////////////////////////////////////////////////////////
  712:  
  713:         /// <summary>
  714:         ///
  715:         /// </summary>
  716:         public static List<string> ProvisionedServiceIdList
  717:         {
  718:             get
  719:             {
  720:                 List<string> serviceRequestServiceList;
  721:  
  722:                 using (var db = new Ia.Ftn.Cl.Db())
  723:                 {
  724:                     serviceRequestServiceList = (from srs in db.ServiceRequestServices
  725:                                                  where srs.Provisioned == true
  726:                                                  select srs.Id).ToList();
  727:                 }
  728:  
  729:                 return serviceRequestServiceList;
  730:             }
  731:         }
  732:  
  733:         ////////////////////////////////////////////////////////////////////////////
  734:  
  735:         /// <summary>
  736:         ///
  737:         /// </summary>
  738:         public static List<string> ProvisionedWithCallBarringServiceList()
  739:         {
  740:             List<string> serviceRequestServiceList;
  741:  
  742:             using (var db = new Ia.Ftn.Cl.Db())
  743:             {
  744:                 serviceRequestServiceList = (from srs in db.ServiceRequestServices
  745:                                              where srs.Provisioned == true && srs.CallBarring == true
  746:                                              select srs.Service).ToList();
  747:             }
  748:  
  749:             return serviceRequestServiceList;
  750:         }
  751:  
  752:         ////////////////////////////////////////////////////////////////////////////
  753:  
  754:         /// <summary>
  755:         ///
  756:         /// </summary>
  757:         public static Dictionary<string, string> ProvisionedServiceIdToAccessIdDictionary
  758:         {
  759:             get
  760:             {
  761:                 Dictionary<string, string> dictionary, nullAccessDictionary;
  762:  
  763:                 using (var db = new Ia.Ftn.Cl.Db())
  764:                 {
  765:                     dictionary = (from srs in db.ServiceRequestServices
  766:                                   where srs.Provisioned == true && srs.Access != null
  767:                                   select new { srs.Id, srs.Access }).AsNoTracking().ToDictionary(u => u.Id, u => u.Access.Id);
  768:  
  769:                     nullAccessDictionary = (from s in db.ServiceRequestServices
  770:                                             where s.Provisioned == true && s.Access == null
  771:                                             select new { s.Id, s.Access }).AsNoTracking().ToDictionary(u => u.Id, u => string.Empty);
  772:                 }
  773:  
  774:                 return dictionary.Union(nullAccessDictionary).ToDictionary(u => u.Key, u => u.Value);
  775:             }
  776:         }
  777:  
  778:         ////////////////////////////////////////////////////////////////////////////
  779:  
  780:         /// <summary>
  781:         ///
  782:         /// </summary>
  783:         public static Dictionary<string, string> ProvisionedServiceToAccessIdDictionary
  784:         {
  785:             get
  786:             {
  787:                 string key;
  788:                 Dictionary<string, string> serviceToAccessIdDictionary, serviceIdToAccessIdDictionary;
  789:  
  790:                 serviceIdToAccessIdDictionary = Ia.Ftn.Cl.Models.Data.ServiceRequestService.ProvisionedServiceIdToAccessIdDictionary;
  791:  
  792:                 serviceToAccessIdDictionary = new Dictionary<string, string>(serviceIdToAccessIdDictionary.Count);
  793:  
  794:                 foreach (KeyValuePair<string, string> kvp in serviceIdToAccessIdDictionary)
  795:                 {
  796:                     key = Ia.Ftn.Cl.Models.Business.ServiceRequestService.ServiceIdToService(kvp.Key);
  797:  
  798:                     serviceToAccessIdDictionary[key] = kvp.Value;
  799:                 }
  800:  
  801:                 return serviceToAccessIdDictionary;
  802:             }
  803:         }
  804:  
  805:         ////////////////////////////////////////////////////////////////////////////
  806:         ////////////////////////////////////////////////////////////////////////////
  807:  
  808:         /// <summary>
  809:         /// 
  810:         /// </summary>
  811:         public static Dictionary<string, Ia.Ftn.Cl.Models.ServiceRequestService> ServiceToServiceRequestServiceDictionary(List<int> domainList)
  812:         {
  813:             string key;
  814:             List<string> stringDomainList;
  815:             List<Ia.Ftn.Cl.Models.ServiceRequestService> list;
  816:             Dictionary<string, Ia.Ftn.Cl.Models.ServiceRequestService> dictionary;
  817:  
  818:             stringDomainList = new List<string>();
  819:  
  820:             using (var db = new Ia.Ftn.Cl.Db())
  821:             {
  822:                 if (domainList.Count > 0)
  823:                 {
  824:                     foreach (int i in domainList) stringDomainList.Add(i.ToString());
  825:  
  826:                     list = (from srs in db.ServiceRequestServices.Include(a => a.ServiceRequests).ThenInclude(u => u.ServiceRequestTypes)
  827:                             where stringDomainList.Any(u => srs.Service.StartsWith(u.ToString()))
  828:                             select srs).ToList();
  829:  
  830:                     dictionary = new Dictionary<string, Ia.Ftn.Cl.Models.ServiceRequestService>(list.Count);
  831:  
  832:                     foreach (var srs in list)
  833:                     {
  834:                         key = srs.Service;
  835:  
  836:                         if (dictionary.ContainsKey(key))
  837:                         {
  838:                             dictionary[key] = srs;
  839:                         }
  840:                         else dictionary[key] = srs;
  841:                     }
  842:                 }
  843:                 else dictionary = new Dictionary<string, Ia.Ftn.Cl.Models.ServiceRequestService>();
  844:             }
  845:  
  846:             return dictionary;
  847:         }
  848:  
  849:         /*
  850:         ////////////////////////////////////////////////////////////////////////////
  851: 
  852:         /// <summary>
  853:         ///
  854:         /// </summary>
  855:         public static void UpdateServiceSuspension(string service, bool serviceSuspensionState, string userId, out Ia.Cl.Models.Result result)
  856:         {
  857:             string serviceRequestServiceId;
  858:             Ia.Ftn.Cl.Model.ServiceRequestService serviceRequestService;
  859: 
  860:             result = new Ia.Cl.Models.Result();
  861:             serviceRequestServiceId = Ia.Ftn.Cl.Model.Business.ServiceRequestService.ServiceRequestServiceId(service, Ia.Ftn.Cl.Model.Business.Service.ServiceType.ImsService);
  862: 
  863:             using (var db = new Ia.Ftn.Cl.Model.Ftn())
  864:             {
  865:                 serviceRequestService = (from srs in db.ServiceRequestServices
  866:                                          where srs.Id == serviceRequestServiceId
  867:                                          select srs).SingleOrDefault();
  868: 
  869:                 if (serviceRequestService != null)
  870:                 {
  871:                     if (serviceRequestService.ServiceSuspension != serviceSuspensionState)
  872:                     {
  873:                         serviceRequestService.ServiceSuspension = serviceSuspensionState;
  874:                         serviceRequestService.Updated = DateTime.UtcNow.AddHours(3);
  875:                         serviceRequestService.StaffIdentityUser.Id = userId;
  876: 
  877:                         db.ServiceRequestServices.Attach(serviceRequestService);
  878:                         db.Entry(serviceRequestService).Property(u => u.ServiceSuspension).IsModified = true;
  879: 
  880:                         db.SaveChanges();
  881: 
  882:                         result.AddSuccess("ServiceSuspension updated. ");
  883:                     }
  884:                     else
  885:                     {
  886:                         result.AddWarning("Warning: ServiceRequestService ServiceSuspension value was not updated because its the same. ");
  887:                     }
  888:                 }
  889:                 else
  890:                 {
  891:                     result.AddError("Error: serviceRequestService is null. ");
  892:                 }
  893:             }
  894:         }
  895:         */
  896:  
  897:         /*
  898:         ////////////////////////////////////////////////////////////////////////////
  899: 
  900:         /// <summary>
  901:         ///
  902:         /// </summary>
  903:         public static Dictionary<string, string> ReadServiceAndOntNameDictionaryWithFourDigitNumberDomain(int fourDigitNumberDomain)
  904:         {
  905:             string s;
  906:             Dictionary<string, string> dictionary;
  907: 
  908:             dictionary = new Dictionary<string, string>(10000);
  909: 
  910:             using (var db = new Ia.Ftn.Cl.Model.Ftn())
  911:             {
  912:                 var list = (from srs in db.ServiceRequestServices
  913:                             where SqlFunctions.PatIndex(fourDigitNumberDomain.ToString() + "%", srs.Service) > 0
  914:                             orderby srs.Service ascending
  915:                             select new
  916:                             {
  917:                                 Service = srs.Service,
  918:                                 Access = srs.Access
  919:                             }).ToList();
  920: 
  921:                 foreach (var v in list)
  922:                 {
  923:                     if (v.Access != null) s = v.Service + " (" + v.Access.Name + ")";
  924:                     else s = v.Service;
  925: 
  926:                     dictionary[v.Service] = s;
  927:                 }
  928:             }
  929: 
  930:             return dictionary;
  931:         }
  932:         */
  933:  
  934:         ////////////////////////////////////////////////////////////////////////////
  935:  
  936:         /// <summary>
  937:         ///
  938:         /// </summary>
  939:         public static List<Ia.Ftn.Cl.Models.ServiceRequestService> ReadListOfServiceRequestServicesWithSimilarServiceNumbers(List<Ia.Ftn.Cl.Models.ServiceRequest> serviceRequestList)
  940:         {
  941:             List<string> serviceList;
  942:             List<Ia.Ftn.Cl.Models.ServiceRequestService> list;
  943:  
  944:             if (serviceRequestList.Count > 0)
  945:             {
  946:                 serviceList = new List<string>();
  947:  
  948:                 foreach (Ia.Ftn.Cl.Models.ServiceRequest serviceRequest in serviceRequestList) serviceList.Add(serviceRequest.Number.ToString());
  949:  
  950:                 using (var db = new Ia.Ftn.Cl.Db())
  951:                 {
  952:                     list = (from srs in db.ServiceRequestServices where serviceList.Contains(srs.Service) select srs).ToList();
  953:                 }
  954:             }
  955:             else list = new List<Ia.Ftn.Cl.Models.ServiceRequestService>();
  956:  
  957:             return list;
  958:         }
  959:  
  960:         ////////////////////////////////////////////////////////////////////////////    
  961:  
  962:         /// <summary>
  963:         ///
  964:         /// </summary>
  965:         public static List<string> ServiceStringList()
  966:         {
  967:             List<string> serviceStringList;
  968:  
  969:             using (var db = new Ia.Ftn.Cl.Db())
  970:             {
  971:                 serviceStringList = (from srs in db.ServiceRequestServices
  972:                                      where srs.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService
  973:                                      orderby srs.Service ascending
  974:                                      select srs.Service).ToList();
  975:             }
  976:  
  977:             return serviceStringList;
  978:         }
  979:  
  980:         ////////////////////////////////////////////////////////////////////////////    
  981:  
  982:         /// <summary>
  983:         ///
  984:         /// </summary>
  985:         public static List<string> ServiceWithProvisionedTrueAndNonNullAccessList()
  986:         {
  987:             List<string> list;
  988:  
  989:             using (var db = new Ia.Ftn.Cl.Db())
  990:             {
  991:                 list = (from srs in db.ServiceRequestServices
  992:                         where srs.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && srs.Provisioned == true && srs.Access != null
  993:                         orderby srs.Service ascending
  994:                         select srs.Service).ToList();
  995:             }
  996:  
  997:             return list;
  998:         }
  999:  
 1000:         ////////////////////////////////////////////////////////////////////////////    
 1001:  
 1002:         /// <summary>
 1003:         ///
 1004:         /// </summary>
 1005:         public static List<string> ServiceWithProvisionedTrueAndNullAccessList()
 1006:         {
 1007:             List<string> list;
 1008:  
 1009:             using (var db = new Ia.Ftn.Cl.Db())
 1010:             {
 1011:                 list = (from srs in db.ServiceRequestServices
 1012:                         where srs.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && srs.Provisioned == true && srs.Access == null
 1013:                         orderby srs.Service ascending
 1014:                         select srs.Service).ToList();
 1015:             }
 1016:  
 1017:             return list;
 1018:         }
 1019:  
 1020:         ////////////////////////////////////////////////////////////////////////////
 1021:  
 1022:         /// <summary>
 1023:         ///
 1024:         /// </summary>
 1025:         public static List<Ia.Ftn.Cl.Models.ServiceRequestService> WithNullAccessList()
 1026:         {
 1027:             List<Ia.Ftn.Cl.Models.ServiceRequestService> serviceRequestServiceList;
 1028:  
 1029:             using (var db = new Ia.Ftn.Cl.Db())
 1030:             {
 1031:                 // below: Take(100) temp
 1032:                 serviceRequestServiceList = (from srs in db.ServiceRequestServices
 1033:                                              where srs.Access == null
 1034:                                              orderby srs.Service ascending
 1035:                                              select srs).Take(100).ToList();
 1036:             }
 1037:  
 1038:             return serviceRequestServiceList;
 1039:         }
 1040:  
 1041:         ////////////////////////////////////////////////////////////////////////////
 1042:  
 1043:         /// <summary>
 1044:         ///
 1045:         /// </summary>
 1046:         public static bool HasInternationalCalling(string service)
 1047:         {
 1048:             return InternationalCallingIsAssigned(service);
 1049:         }
 1050:  
 1051:         ////////////////////////////////////////////////////////////////////////////
 1052:  
 1053:         /// <summary>
 1054:         ///
 1055:         /// </summary>
 1056:         public static bool InternationalCallingIsAssigned(string service)
 1057:         {
 1058:             bool isAssigned;
 1059:  
 1060:             using (var db = new Ia.Ftn.Cl.Db())
 1061:             {
 1062:                 isAssigned = (from s in db.ServiceRequestServices
 1063:                               where s.Service == service && s.InternationalCalling == true
 1064:                               select s.Service).Any();
 1065:             }
 1066:  
 1067:             return isAssigned;
 1068:         }
 1069:  
 1070:         /*
 1071:         ////////////////////////////////////////////////////////////////////////////
 1072: 
 1073:         /// <summary>
 1074:         ///
 1075:         /// </summary>
 1076:         public static List<Ia.Ftn.Cl.Model.ServiceRequestService> ServiceSuspensionIsTrueAndProvisionedIsTrueList()
 1077:         {
 1078:             List<Ia.Ftn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 1079: 
 1080:             using (var db = new Ia.Ftn.Cl.Model.Ftn())
 1081:             {
 1082:                 serviceRequestServiceList = (from s in db.ServiceRequestServices where s.ServiceSuspension == true && s.Provisioned == true select s).ToList();
 1083:             }
 1084: 
 1085:             return serviceRequestServiceList;
 1086:         }
 1087: 
 1088:         ////////////////////////////////////////////////////////////////////////////
 1089: 
 1090:         /// <summary>
 1091:         ///
 1092:         /// </summary>
 1093:         public static List<Ia.Ftn.Cl.Model.ServiceRequestService> ServiceSuspensionIsFalseList()
 1094:         {
 1095:             List<Ia.Ftn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 1096: 
 1097:             using (var db = new Ia.Ftn.Cl.Model.Ftn())
 1098:             {
 1099:                 serviceRequestServiceList = (from s in db.ServiceRequestServices where s.ServiceSuspension == false select s).ToList();
 1100:             }
 1101: 
 1102:             return serviceRequestServiceList;
 1103:         }
 1104: 
 1105:         ////////////////////////////////////////////////////////////////////////////
 1106: 
 1107:         /// <summary>
 1108:         ///
 1109:         /// </summary>
 1110:         public static List<string> ServiceSuspensionIsTrueAndProvisionedIsTrueStringNumberList
 1111:         {
 1112:             get
 1113:             {
 1114:                 List<string> serviceRequestServiceNumberStringList;
 1115:                 List<Ia.Ftn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 1116: 
 1117:                 using (var db = new Ia.Ftn.Cl.Model.Ftn())
 1118:                 {
 1119:                     // below:                
 1120:                     serviceRequestServiceList = ServiceSuspensionIsTrueAndProvisionedIsTrueList();
 1121: 
 1122:                     if (serviceRequestServiceList.Count > 0)
 1123:                     {
 1124:                         serviceRequestServiceNumberStringList = new List<string>(serviceRequestServiceList.Count);
 1125: 
 1126:                         foreach (Ia.Ftn.Cl.Model.ServiceRequestService srs in serviceRequestServiceList)
 1127:                         {
 1128:                             serviceRequestServiceNumberStringList.Add(srs.Service);
 1129:                         }
 1130:                     }
 1131:                     else
 1132:                     {
 1133:                         // below: not null
 1134:                         serviceRequestServiceNumberStringList = new List<string>(1);
 1135:                     }
 1136:                 }
 1137: 
 1138:                 return serviceRequestServiceNumberStringList;
 1139:             }
 1140:         }
 1141: 
 1142:         ////////////////////////////////////////////////////////////////////////////
 1143: 
 1144:         /// <summary>
 1145:         ///
 1146:         /// </summary>
 1147:         public static List<string> ServiceSuspensionIsFalseStringNumberList
 1148:         {
 1149:             get
 1150:             {
 1151:                 List<string> serviceRequestServiceNumberStringList;
 1152:                 List<Ia.Ftn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 1153: 
 1154:                 using (var db = new Ia.Ftn.Cl.Model.Ftn())
 1155:                 {
 1156:                     // below:                
 1157:                     serviceRequestServiceList = ServiceSuspensionIsFalseList();
 1158: 
 1159:                     if (serviceRequestServiceList.Count > 0)
 1160:                     {
 1161:                         serviceRequestServiceNumberStringList = new List<string>(serviceRequestServiceList.Count);
 1162: 
 1163:                         foreach (Ia.Ftn.Cl.Model.ServiceRequestService srs in serviceRequestServiceList)
 1164:                         {
 1165:                             serviceRequestServiceNumberStringList.Add(srs.Service);
 1166:                         }
 1167:                     }
 1168:                     else
 1169:                     {
 1170:                         // below: not null
 1171:                         serviceRequestServiceNumberStringList = new List<string>(1);
 1172:                     }
 1173:                 }
 1174: 
 1175:                 return serviceRequestServiceNumberStringList;
 1176:             }
 1177:         }
 1178:         */
 1179:  
 1180:         ////////////////////////////////////////////////////////////////////////////
 1181:  
 1182:         /// <summary>
 1183:         ///
 1184:         /// </summary>
 1185:         public static List<Ia.Ftn.Cl.Models.ServiceRequestService> ServiceRequestServiceWithNullAccessList
 1186:         {
 1187:             get
 1188:             {
 1189:                 List<Ia.Ftn.Cl.Models.ServiceRequestService> serviceRequestServiceList;
 1190:  
 1191:                 using (var db = new Ia.Ftn.Cl.Db())
 1192:                 {
 1193:                     serviceRequestServiceList = (from srs in db.ServiceRequestServices where srs.Access == null select srs).ToList();
 1194:                 }
 1195:  
 1196:                 return serviceRequestServiceList;
 1197:             }
 1198:         }
 1199:  
 1200:         ////////////////////////////////////////////////////////////////////////////
 1201:  
 1202:         /// <summary>
 1203:         ///
 1204:         /// </summary>
 1205:         public static List<string> ServiceRequestServiceServiceIdWhereProvisionedIsTrueAndAccessIsNullList()
 1206:         {
 1207:             List<string> list;
 1208:  
 1209:             using (var db = new Ia.Ftn.Cl.Db())
 1210:             {
 1211:                 list = (from srs in db.ServiceRequestServices where srs.Provisioned == true && srs.Access == null select srs.Id).ToList();
 1212:             }
 1213:  
 1214:             return list;
 1215:         }
 1216:  
 1217:         ////////////////////////////////////////////////////////////////////////////
 1218:  
 1219:         /// <summary>
 1220:         ///
 1221:         /// </summary>
 1222:         public static List<Ia.Ftn.Cl.Models.ServiceRequestService> ProvisionedWithinSiteList(int siteId)
 1223:         {
 1224:             List<Ia.Ftn.Cl.Models.ServiceRequestService> list;
 1225:  
 1226:             var site = (from s in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.SiteList
 1227:                         where s.Id == siteId
 1228:                         select s).SingleOrDefault();
 1229:  
 1230:             if (site != null)
 1231:             {
 1232:                 var siteRouterDomainList = (from r in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.RouterList
 1233:                                             where r.Site.Id == site.Id
 1234:                                             select r).SelectMany(d => d.DomainList).ToList();
 1235:  
 1236:                 using (var db = new Ia.Ftn.Cl.Db())
 1237:                 {
 1238:                     var list0 = (from srs in db.ServiceRequestServices
 1239:                                  where srs.Provisioned == true
 1240:                                  select srs).Include(u => u.Access).ToList();
 1241:  
 1242:                     list = (from srs in list0
 1243:                             where siteRouterDomainList.Any(u => srs.Service.StartsWith(u.ToString()))
 1244:                             select srs).ToList();
 1245:                 }
 1246:             }
 1247:             else
 1248:             {
 1249:                 list = new List<Models.ServiceRequestService>();
 1250:             }
 1251:  
 1252:             return list;
 1253:         }
 1254:  
 1255:         ////////////////////////////////////////////////////////////////////////////
 1256:  
 1257:         /// <summary>
 1258:         ///
 1259:         /// </summary>
 1260:         public static bool NullifyAccessIdByAccessId(string accessId, out string result)
 1261:         {
 1262:             bool b;
 1263:             int numberOfRecordsWhereAccessIsNullified;
 1264:             Ia.Ftn.Cl.Models.ServiceRequestService serviceRequestService;
 1265:  
 1266:             b = false;
 1267:             numberOfRecordsWhereAccessIsNullified = 0;
 1268:  
 1269:             using (var db = new Ia.Ftn.Cl.Db())
 1270:             {
 1271:                 // --update ServiceRequestServices set Access_Id = null where Access_Id = '1040101010040004'
 1272:                 //var query = (from srs in db.ServiceRequestServices where srs.Access.Id == accessId select srs).ToList();
 1273:  
 1274:                 //foreach (var v in query)
 1275:                 //{
 1276:                 serviceRequestService = (from srs in db.ServiceRequestServices where srs.Access.Id == accessId select srs).Include(u => u.Access).FirstOrDefault(); //.SingleOrDefault();
 1277:  
 1278:                 if (serviceRequestService != null)
 1279:                 {
 1280:                     serviceRequestService.Access = null;
 1281:                     serviceRequestService.Updated = DateTime.UtcNow.AddHours(3);
 1282:  
 1283:                     db.ServiceRequestServices.Attach(serviceRequestService);
 1284:                     db.Entry(serviceRequestService).Property(u => u.Updated).IsModified = true;
 1285:  
 1286:                     db.SaveChanges();
 1287:  
 1288:                     numberOfRecordsWhereAccessIsNullified++;
 1289:                 }
 1290:                 //}
 1291:  
 1292:                 b = true;
 1293:             }
 1294:  
 1295:             result = "Number of records where access is nullified: " + numberOfRecordsWhereAccessIsNullified;
 1296:  
 1297:             return b;
 1298:         }
 1299:  
 1300:         ////////////////////////////////////////////////////////////////////////////
 1301:  
 1302:         /// <summary>
 1303:         ///
 1304:         /// </summary>
 1305:         public static void UpdateServiceRequestServiceAccess(string service, string updatedAccessId, string userId, out Ia.Cl.Models.Result result)
 1306:         {
 1307:             bool saveUpdate;
 1308:             string serviceRequestServiceId;
 1309:             Ia.Ftn.Cl.Models.ServiceRequestService serviceRequestService;
 1310:  
 1311:             saveUpdate = false;
 1312:             result = new Ia.Cl.Models.Result();
 1313:             serviceRequestServiceId = Ia.Ftn.Cl.Models.Business.ServiceRequestService.ServiceRequestServiceId(service, Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService);
 1314:  
 1315:             using (var db = new Ia.Ftn.Cl.Db())
 1316:             {
 1317:                 serviceRequestService = (from srs in db.ServiceRequestServices where srs.Id == serviceRequestServiceId select srs).Include(u => u.Access).SingleOrDefault();
 1318:  
 1319:                 if (serviceRequestService != null)
 1320:                 {
 1321:                     if (serviceRequestService.Access != null && serviceRequestService.Access.Id != updatedAccessId
 1322:                         || serviceRequestService.Access == null && !string.IsNullOrEmpty(updatedAccessId))
 1323:                     {
 1324:                         serviceRequestService.Access = (from a in db.Accesses where a.Id == updatedAccessId select a).SingleOrDefault();
 1325:                         serviceRequestService.StaffIdentityUser.Id = userId;
 1326:                         serviceRequestService.Updated = DateTime.UtcNow.AddHours(3);
 1327:                         saveUpdate = true;
 1328:                     }
 1329:                     else if (string.IsNullOrEmpty(updatedAccessId))
 1330:                     {
 1331:                         // nulling
 1332:                         serviceRequestService.Access = null;
 1333:                         serviceRequestService.StaffIdentityUser.Id = userId;
 1334:                         serviceRequestService.Updated = DateTime.UtcNow.AddHours(3);
 1335:                         saveUpdate = true;
 1336:                     }
 1337:  
 1338:                     if (saveUpdate)
 1339:                     {
 1340:                         db.ServiceRequestServices.Attach(serviceRequestService);
 1341:  
 1342:                         //db.Entry(serviceRequestService).Property(u => u.Access).IsModified = true;
 1343:                         db.Entry(serviceRequestService).Property(u => u.StaffIdentityUser.Id).IsModified = true;
 1344:                         db.Entry(serviceRequestService).Property(u => u.Updated).IsModified = true;
 1345:  
 1346:                         db.SaveChanges();
 1347:  
 1348:                         result.AddSuccess("Service " + service + " access reference updated (تم تحديث الربط بالرقم).");
 1349:                     }
 1350:                     else result.AddWarning("Reference access value was not updated (لم يتم تحديث الربط بالرقم).");
 1351:                 }
 1352:                 else result.AddWarning("ServiceRequestService is null (لا توجد حالة خدمة للرقم).");
 1353:             }
 1354:         }
 1355:  
 1356:         ////////////////////////////////////////////////////////////////////////////
 1357:  
 1358:         /// <summary>
 1359:         ///
 1360:         /// </summary>
 1361:         public static Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont> ProvisionedServiceToNddOntDictionary
 1362:         {
 1363:             get
 1364:             {
 1365:                 string key;
 1366:                 Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont> dictionary;
 1367:  
 1368:                 var serviceIdToAccessIdDictionary = Ia.Ftn.Cl.Models.Data.ServiceRequestService.ProvisionedServiceIdToAccessIdDictionary;
 1369:                 var ontAccessIdToOntDictionary = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntAccessIdToOntDictionary;
 1370:  
 1371:                 dictionary = new Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont>(serviceIdToAccessIdDictionary.Count);
 1372:  
 1373:                 foreach (KeyValuePair<string, string> kvp in serviceIdToAccessIdDictionary)
 1374:                 {
 1375:                     key = Ia.Ftn.Cl.Models.Business.ServiceRequestService.ServiceIdToService(kvp.Key);
 1376:  
 1377:                     if (!string.IsNullOrEmpty(kvp.Value)) dictionary[key] = ontAccessIdToOntDictionary[kvp.Value];
 1378:                     else dictionary[key] = null;
 1379:                 }
 1380:  
 1381:                 return dictionary;
 1382:             }
 1383:         }
 1384:  
 1385:         ////////////////////////////////////////////////////////////////////////////
 1386:  
 1387:         /// <summary>
 1388:         ///
 1389:         /// </summary>
 1390:         public static Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site> ServiceToSiteDictionary
 1391:         {
 1392:             get
 1393:             {
 1394:                 int fourLetterServiceDomain, fiveLetterServiceDomain;
 1395:                 string service;
 1396:                 Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site> dictionary;
 1397:  
 1398:                 var serviceIdList = Ia.Ftn.Cl.Models.Data.ServiceRequestService.ServiceIdList;
 1399:                 var routerDomainToSiteDictionary = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.RouterDomainToSiteDictionary;
 1400:  
 1401:                 dictionary = new Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site>(serviceIdList.Count);
 1402:  
 1403:                 foreach (string s in serviceIdList)
 1404:                 {
 1405:                     service = Ia.Ftn.Cl.Models.Business.Service.ServiceIdToService(s);
 1406:  
 1407:                     if (service.Length >= 5)
 1408:                     {
 1409:                         fourLetterServiceDomain = int.Parse(service.Substring(0, 4));
 1410:                         fiveLetterServiceDomain = int.Parse(service.Substring(0, 5));
 1411:  
 1412:                         if (routerDomainToSiteDictionary.ContainsKey(fiveLetterServiceDomain)) dictionary[service] = routerDomainToSiteDictionary[fiveLetterServiceDomain];
 1413:                         else if (routerDomainToSiteDictionary.ContainsKey(fourLetterServiceDomain)) dictionary[service] = routerDomainToSiteDictionary[fourLetterServiceDomain];
 1414:                         //else throw new System.ArgumentOutOfRangeException("Service number " + service + " is out of range");
 1415:                     }
 1416:                     //else throw new System.ArgumentOutOfRangeException("Service number " + service + " is out of range");
 1417:                 }
 1418:  
 1419:                 return dictionary;
 1420:             }
 1421:         }
 1422:  
 1423:         ////////////////////////////////////////////////////////////////////////////
 1424:  
 1425:         /// <summary>
 1426:         ///
 1427:         /// </summary>
 1428:         public static Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site> ProvisionedServiceToSiteDictionary
 1429:         {
 1430:             get
 1431:             {
 1432:                 int fourLetterServiceDomain, fiveLetterServiceDomain;
 1433:                 string service;
 1434:                 Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site> dictionary;
 1435:  
 1436:                 var serviceIdList = Ia.Ftn.Cl.Models.Data.ServiceRequestService.ProvisionedServiceIdList;
 1437:                 var routerDomainToSiteDictionary = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.RouterDomainToSiteDictionary;
 1438:  
 1439:                 dictionary = new Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site>(serviceIdList.Count);
 1440:  
 1441:                 foreach (string s in serviceIdList)
 1442:                 {
 1443:                     service = Ia.Ftn.Cl.Models.Business.Service.ServiceIdToService(s);
 1444:  
 1445:                     if (service.Length >= 5)
 1446:                     {
 1447:                         fourLetterServiceDomain = int.Parse(service.Substring(0, 4));
 1448:                         fiveLetterServiceDomain = int.Parse(service.Substring(0, 5));
 1449:  
 1450:                         if (routerDomainToSiteDictionary.ContainsKey(fiveLetterServiceDomain)) dictionary[service] = routerDomainToSiteDictionary[fiveLetterServiceDomain];
 1451:                         else if (routerDomainToSiteDictionary.ContainsKey(fourLetterServiceDomain)) dictionary[service] = routerDomainToSiteDictionary[fourLetterServiceDomain];
 1452:                         //else throw new System.ArgumentOutOfRangeException("Service number " + service + " is out of range");
 1453:                     }
 1454:                     //else throw new System.ArgumentOutOfRangeException("Service number " + service + " is out of range");
 1455:                 }
 1456:  
 1457:                 return dictionary;
 1458:             }
 1459:         }
 1460:  
 1461:         ////////////////////////////////////////////////////////////////////////////
 1462:  
 1463:         /// <summary>
 1464:         ///
 1465:         /// </summary>
 1466:         public static List<string> ServiceRequestServiceServicesThatDoNotExistInNeitherServiceRequestsNorServiceRequestHistoriesList()
 1467:         {
 1468:             List<string> list;
 1469:  
 1470:             using (var db = new Ia.Ftn.Cl.Db())
 1471:             {
 1472:                 /*
 1473: select top 1000 srs.Service from ServiceRequestServices srs
 1474: left outer join ServiceRequests sr on sr.Number = srs.Service
 1475: left outer join ServiceRequestHistories srh on srh.Number = srs.Service
 1476: where sr.Id is null and srh.Id is null
 1477:                  */
 1478:  
 1479:                 list = (from srs in db.ServiceRequestServices
 1480:                         join sr in db.ServiceRequests on srs.Service equals sr.Number.ToString() into sr2
 1481:                         from sr3 in sr2.DefaultIfEmpty()
 1482:                         join srh in db.ServiceRequestHistories on srs.Service equals srh.Number.ToString() into srh2
 1483:                         from srh3 in srh2.DefaultIfEmpty()
 1484:                         where sr3 == null && srh3 == null //&& srs.Provisioned == true
 1485:                         select srs.Service).ToList();
 1486:             }
 1487:  
 1488:             return list;
 1489:         }
 1490:  
 1491:         ////////////////////////////////////////////////////////////////////////////
 1492:         ////////////////////////////////////////////////////////////////////////////
 1493:     }
 1494:  
 1495:     ////////////////////////////////////////////////////////////////////////////
 1496:     ////////////////////////////////////////////////////////////////////////////
 1497: }