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