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