1: using Microsoft.EntityFrameworkCore;
2: using System;
3: using System.Collections;
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 support class for Next Generation Network (NGN) data model.
14: /// </summary>
15: ///
16: /// <remarks>
17: /// Copyright © 2006-2020 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 partial class Service2
30: {
31: public Service2() { }
32:
33: ////////////////////////////////////////////////////////////////////////////
34:
35: /// <summary>
36: /// Read service2
37: /// </summary>
38: public static Ia.Ngn.Cl.Model.Service2 Read(string service)
39: {
40: Ia.Ngn.Cl.Model.Service2 service2;
41:
42: using (var db = new Ia.Ngn.Cl.Model.Ngn())
43: {
44: service2 = (from s in db.Service2
45: where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Service == service
46: select s).SingleOrDefault();
47: }
48:
49: return service2;
50: }
51:
52: ////////////////////////////////////////////////////////////////////////////
53:
54: /// <summary>
55: /// Read service2s for service list
56: /// </summary>
57: public static List<Ia.Ngn.Cl.Model.Service2> ReadList(List<string> serviceList)
58: {
59: List<Ia.Ngn.Cl.Model.Service2> service2List;
60:
61: using (var db = new Ia.Ngn.Cl.Model.Ngn())
62: {
63: service2List = (from s in db.Service2
64: where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && serviceList.Contains(s.Service)
65: select s).ToList();
66: }
67:
68: return service2List;
69: }
70:
71: ////////////////////////////////////////////////////////////////////////////
72:
73: /// <summary>
74: /// Read PSTN service2
75: /// </summary>
76: public static Ia.Ngn.Cl.Model.Service2 ReadPstn(string service)
77: {
78: Ia.Ngn.Cl.Model.Service2 service2;
79:
80: using (var db = new Ia.Ngn.Cl.Model.Ngn())
81: {
82: service2 = (from s in db.Service2
83: where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.PstnService && s.Service == service
84: select s).SingleOrDefault();
85: }
86:
87: return service2;
88: }
89:
90: ////////////////////////////////////////////////////////////////////////////
91:
92: /// <summary>
93: /// Read PSTN service2s for service list
94: /// </summary>
95: public static List<Ia.Ngn.Cl.Model.Service2> ReadPstnList(List<string> serviceList)
96: {
97: List<Ia.Ngn.Cl.Model.Service2> service2List;
98:
99: using (var db = new Ia.Ngn.Cl.Model.Ngn())
100: {
101: service2List = (from s in db.Service2
102: where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.PstnService && serviceList.Contains(s.Service)
103: select s).ToList();
104: }
105:
106: return service2List;
107: }
108:
109: ////////////////////////////////////////////////////////////////////////////
110:
111: /// <summary>
112: /// Read service of a number
113: /// </summary>
114: public static Ia.Ngn.Cl.Model.Service2 Read(long number)
115: {
116: Ia.Ngn.Cl.Model.Service2 service;
117:
118: using (var db = new Ia.Ngn.Cl.Model.Ngn())
119: {
120: service = (from s in db.Service2
121: where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Service == number.ToString()
122: select s).SingleOrDefault();
123: }
124:
125: return service;
126: }
127:
128: ////////////////////////////////////////////////////////////////////////////
129:
130: /// <summary>
131: /// Read service from Id
132: /// </summary>
133: public static Ia.Ngn.Cl.Model.Service2 ReadByIdIncludeAccess(string serviceId)
134: {
135: Ia.Ngn.Cl.Model.Service2 service2;
136:
137: using (var db = new Ia.Ngn.Cl.Model.Ngn())
138: {
139: service2 = (from s in db.Service2.Include(a => a.Access)
140: where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Id == serviceId
141: select s).SingleOrDefault();
142: }
143:
144: return service2;
145: }
146:
147: ////////////////////////////////////////////////////////////////////////////
148:
149: /// <summary>
150: /// Read service of a number
151: /// </summary>
152: public static Ia.Ngn.Cl.Model.Service2 ReadWithAccess(string service)
153: {
154: Ia.Ngn.Cl.Model.Service2 service2;
155:
156: using (var db = new Ia.Ngn.Cl.Model.Ngn())
157: {
158: service2 = (from s in db.Service2.Include(a => a.Access)
159: where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Service == service
160: select s).SingleOrDefault();
161: }
162:
163: return service2;
164: }
165:
166: ////////////////////////////////////////////////////////////////////////////
167:
168: /// <summary>
169: ///
170: /// </summary>
171: public static List<Ia.Ngn.Cl.Model.Service2> List()
172: {
173: List<Ia.Ngn.Cl.Model.Service2> serviceList;
174:
175: using (var db = new Ia.Ngn.Cl.Model.Ngn())
176: {
177: serviceList = (from s in db.Service2 where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService select s).ToList();
178: }
179:
180: return serviceList;
181: }
182:
183: ////////////////////////////////////////////////////////////////////////////
184:
185: /// <summary>
186: ///
187: /// </summary>
188: public static List<string> List(List<int> domainList)
189: {
190: List<string> stringDomainList;
191: List<string> serviceList;
192:
193: stringDomainList = new List<string>();
194:
195: using (var db = new Ia.Ngn.Cl.Model.Ngn())
196: {
197: if (domainList != null)
198: {
199: foreach (int i in domainList) stringDomainList.Add(i.ToString());
200:
201: serviceList = (from s in db.Service2
202: where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && stringDomainList.Any(u => s.Service.StartsWith(u.ToString()))
203: select s.Service).ToList();
204: }
205: else
206: {
207: serviceList = (from s in db.Service2 where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService select s.Service).ToList();
208: }
209: }
210:
211: return serviceList;
212: }
213:
214: ////////////////////////////////////////////////////////////////////////////
215:
216: /// <summary>
217: ///
218: /// </summary>
219: public static List<string> ServiceList
220: {
221: get
222: {
223: List<string> list;
224:
225: using (var db = new Ia.Ngn.Cl.Model.Ngn())
226: {
227: list = (from s in db.Service2 where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService select s.Service).ToList();
228: }
229:
230: return list;
231: }
232: }
233:
234: ////////////////////////////////////////////////////////////////////////////
235:
236: /// <summary>
237: ///
238: /// </summary>
239: public static List<string> PstnServiceList
240: {
241: get
242: {
243: List<string> list;
244:
245: using (var db = new Ia.Ngn.Cl.Model.Ngn())
246: {
247: list = (from s in db.Service2 where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.PstnService select s.Service).ToList();
248: }
249:
250: return list.ToList();
251: }
252: }
253:
254: ////////////////////////////////////////////////////////////////////////////
255:
256: /// <summary>
257: ///
258: /// </summary>
259: public static List<string> ServiceIdList
260: {
261: get
262: {
263: List<string> list;
264:
265: using (var db = new Ia.Ngn.Cl.Model.Ngn())
266: {
267: list = (from s in db.Service2 /*where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService*/ select s.Id).ToList();
268: }
269:
270: return list.ToList();
271: }
272: }
273:
274: ////////////////////////////////////////////////////////////////////////////
275:
276: /// <summary>
277: ///
278: /// </summary>
279: public static List<Ia.Ngn.Cl.Model.Business.ServiceOnt> ServiceOntList
280: {
281: get
282: {
283: List<Ia.Ngn.Cl.Model.Business.ServiceOnt> list;
284:
285: var ontAccessIdToOntForOltIdListDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntDictionary;
286:
287: using (var db = new Ia.Ngn.Cl.Model.Ngn())
288: {
289: list = (from s in db.Service2
290: where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService
291: select new Ia.Ngn.Cl.Model.Business.ServiceOnt { ServiceId = s.Id, Service = s.Service, AccessId = s.Access != null ? s.Access.Id : string.Empty, CreatedDateTime = s.Created }).ToList();
292: }
293:
294: foreach (var l in list)
295: {
296: l.Ont = ontAccessIdToOntForOltIdListDictionary.ContainsKey(l.AccessId) ? ontAccessIdToOntForOltIdListDictionary[l.AccessId] : null;
297: }
298:
299: return list;
300: }
301: }
302:
303: ////////////////////////////////////////////////////////////////////////////
304:
305: /// <summary>
306: ///
307: /// </summary>
308: public static List<Ia.Ngn.Cl.Model.Service2> PstnService2List
309: {
310: get
311: {
312: List<Ia.Ngn.Cl.Model.Service2> list;
313:
314: using (var db = new Ia.Ngn.Cl.Model.Ngn())
315: {
316: list = (from s in db.Service2 where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.PstnService select s).Include(s => s.Access).ToList();
317: }
318:
319: return list.ToList();
320: }
321: }
322:
323: ////////////////////////////////////////////////////////////////////////////
324:
325: /// <summary>
326: ///
327: /// </summary>
328: public static Dictionary<string, int> ServiceIdToPortDictionary
329: {
330: get
331: {
332: Dictionary<string, int> dictionary;
333:
334: using (var db = new Ia.Ngn.Cl.Model.Ngn())
335: {
336: dictionary = (from s in db.Service2
337: where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Access != null
338: select new { s.Id, s.Port }).ToDictionary(m => m.Id, m => m.Port);
339: }
340:
341: return dictionary;
342: }
343: }
344:
345: ////////////////////////////////////////////////////////////////////////////
346:
347: /// <summary>
348: ///
349: /// </summary>
350: public static Ia.Ngn.Cl.Model.Access ReadAccess(string id)
351: {
352: Ia.Ngn.Cl.Model.Access access;
353:
354: using (var db = new Ia.Ngn.Cl.Model.Ngn())
355: {
356: access = (from s in db.Service2
357: where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Id == id
358: select s.Access).SingleOrDefault();
359: }
360:
361: return access;
362: }
363:
364: ////////////////////////////////////////////////////////////////////////////
365:
366: /// <summary>
367: ///
368: /// </summary>
369: public static Dictionary<string, int> ServicePortDictionary
370: {
371: get
372: {
373: Dictionary<string, int> dictionary;
374:
375: using (var db = new Ia.Ngn.Cl.Model.Ngn())
376: {
377: dictionary = (from s in db.Service2
378: where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Port > -1
379: select new { s.Service, s.Port }).ToDictionary(m => m.Service, m => m.Port);
380: }
381:
382: return dictionary;
383: }
384: }
385:
386: ////////////////////////////////////////////////////////////////////////////
387:
388: /// <summary>
389: ///
390: /// </summary>
391: public static Ia.Ngn.Cl.Model.Access ReadAccess(Ia.Ngn.Cl.Model.Ngn db, string id)
392: {
393: Ia.Ngn.Cl.Model.Access access;
394:
395: access = (from s in db.Service2
396: where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Id == id
397: select s.Access).SingleOrDefault();
398:
399: return access;
400: }
401:
402: ////////////////////////////////////////////////////////////////////////////
403:
404: /// <summary>
405: ///
406: /// </summary>
407: public static bool UpdatePort(Ia.Ngn.Cl.Model.Service2 service, int port, out string result)
408: {
409: bool b;
410:
411: using (var db = new Ia.Ngn.Cl.Model.Ngn())
412: {
413: service = (from s in db.Service2
414: where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Id == service.Id
415: select s).SingleOrDefault();
416:
417: if (service.Port != port)
418: {
419: service.Port = port;
420:
421: db.Service2.Attach(service);
422: db.Entry(service).Property(u => u.Port).IsModified = true;
423:
424: db.SaveChanges();
425:
426: result = "Success: Service Port updated. ";
427: b = true;
428: }
429: else
430: {
431: result = "Warning: Service Port value was not updated because its the same. ";
432:
433: b = false;
434: }
435: }
436:
437: return b;
438: }
439:
440: ////////////////////////////////////////////////////////////////////////////
441:
442: /// <summary>
443: ///
444: /// </summary>
445: public static List<Ia.Ngn.Cl.Model.Service2> ServiceWithNullAccessList
446: {
447: get
448: {
449: List<Ia.Ngn.Cl.Model.Service2> serviceList;
450:
451: using (var db = new Ia.Ngn.Cl.Model.Ngn())
452: {
453: serviceList = (from s in db.Service2
454: where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Access == null
455: select s).ToList();
456: }
457:
458: return serviceList;
459: }
460: }
461:
462: ////////////////////////////////////////////////////////////////////////////
463:
464: /// <summary>
465: /// Services within a SIP designated OLT
466: /// </summary>
467: public static List<string> ServiceIdWithinSipOltList()
468: {
469: List<int> sipOltIdList;
470: List<string> list, list2;
471:
472: sipOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.SipOltIdList;
473:
474: using (var db = new Ia.Ngn.Cl.Model.Ngn())
475: {
476: // services with access
477: list = (from s in db.Service2
478: where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Access != null && sipOltIdList.Contains(s.Access.Olt)
479: select s.Id).ToList();
480:
481: // services without access might be newly installed
482: list2 = (from s in db.Service2
483: join srs in db.ServiceRequestServices on s.Service equals srs.Service
484: where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Access == null && srs.Access != null && srs.Provisioned == true && sipOltIdList.Contains(srs.Access.Olt)
485: select s.Id).ToList();
486: }
487:
488: return list.Union(list2).Distinct().ToList();
489: }
490:
491: ////////////////////////////////////////////////////////////////////////////
492:
493: /// <summary>
494: /// Services within a SIP allowed to be provisioned or migrated OLT
495: /// </summary>
496: public static List<string> ServiceIdWithinAllowedSipOltToBeProvisionedOrMigratedList()
497: {
498: List<int> sipOltIdList;
499: List<string> list, list2;
500:
501: sipOltIdList = Ia.Ngn.Cl.Model.Data.Service.AllowedToBeProvisionedSipOltIdList.Union(Ia.Ngn.Cl.Model.Data.Service.AllowedToBeMigratedSipOltIdList).ToList();
502:
503: using (var db = new Ia.Ngn.Cl.Model.Ngn())
504: {
505: // services with access
506: list = (from s in db.Service2 where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Access != null && sipOltIdList.Contains(s.Access.Olt) select s.Id).ToList();
507:
508: // services without access might be newly installed
509: list2 = (from s in db.Service2
510: join srs in db.ServiceRequestServices on s.Service equals srs.Service
511: where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Access == null && srs.Access != null && srs.Provisioned == true && sipOltIdList.Contains(srs.Access.Olt)
512: select s.Id).ToList();
513: }
514:
515: return list.Union(list2).Distinct().ToList();
516: }
517:
518: ////////////////////////////////////////////////////////////////////////////
519:
520: /// <summary>
521: /// ServiceOnts within a SIP allowed to be provisioned or migrated OLT
522: /// </summary>
523: public static List<Ia.Ngn.Cl.Model.Business.ServiceOnt> ServiceOntWithinAllowedSipOltToBeProvisionedOrMigratedList
524: {
525: get
526: {
527: List<int> oltIdList;
528: List<Ia.Ngn.Cl.Model.Business.ServiceOnt> list1, list2, list;
529:
530: oltIdList = Ia.Ngn.Cl.Model.Data.Service.AllowedToBeProvisionedSipOltIdList.Union(Ia.Ngn.Cl.Model.Data.Service.AllowedToBeMigratedSipOltIdList).ToList();
531:
532: var ontAccessIdToOntForOltIdListDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntForOltIdListDictionary(oltIdList);
533:
534: using (var db = new Ia.Ngn.Cl.Model.Ngn())
535: {
536: // services with access
537: list1 = (from s in db.Service2
538: where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Access != null && oltIdList.Contains(s.Access.Olt)
539: select new Ia.Ngn.Cl.Model.Business.ServiceOnt { ServiceId = s.Id, Service = s.Service, AccessId = s.Access.Id, CreatedDateTime = s.Created }).ToList();
540:
541: // services without access might be newly installed
542: list2 = (from s in db.Service2
543: join srs in db.ServiceRequestServices on s.Service equals srs.Service
544: where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Access == null && srs.Access != null && srs.Provisioned == true && oltIdList.Contains(srs.Access.Olt)
545: select new Ia.Ngn.Cl.Model.Business.ServiceOnt { ServiceId = s.Id, Service = s.Service, AccessId = srs.Access.Id, CreatedDateTime = s.Created }).ToList();
546: }
547:
548: list = list1.Concat(list2).ToList();
549:
550: foreach (var l in list)
551: {
552: l.Ont = ontAccessIdToOntForOltIdListDictionary.ContainsKey(l.AccessId) ? ontAccessIdToOntForOltIdListDictionary[l.AccessId] : null;
553: }
554:
555: return list;
556: }
557: }
558:
559: ////////////////////////////////////////////////////////////////////////////
560:
561: /// <summary>
562: ///
563: /// </summary>
564: public static List<Ia.Ngn.Cl.Model.Business.ServiceOnt> ServiceOntWithinAllowedToBeProvisionedOrMigratedHuaweiSwitchNokiaGponOltList()
565: {
566: List<int> oltIdList;
567: List<Ia.Ngn.Cl.Model.Business.ServiceOnt> list1, list2, list;
568:
569: //oltIdList = Ia.Ngn.Cl.Model.Data.Service.AllowedToBeProvisionedOltIdList.Intersect(Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.HuaweiSwitchNokiaGponOltIdList).ToList();
570: oltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.HuaweiSwitchNokiaGponOltIdList;
571:
572: var ontAccessIdToOntForOltIdListDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntForOltIdListDictionary(oltIdList);
573:
574: using (var db = new Ia.Ngn.Cl.Model.Ngn())
575: {
576: // services with access
577: list1 = (from s in db.Service2
578: where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Access != null && oltIdList.Contains(s.Access.Olt)
579: select new Ia.Ngn.Cl.Model.Business.ServiceOnt { ServiceId = s.Id, Service = s.Service, AccessId = s.Access.Id, CreatedDateTime = s.Created }).ToList();
580:
581: // services without access might be newly installed
582: list2 = (from s in db.Service2
583: join srs in db.ServiceRequestServices on s.Service equals srs.Service
584: where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Access == null && srs.Access != null && srs.Provisioned == true && oltIdList.Contains(srs.Access.Olt)
585: select new Ia.Ngn.Cl.Model.Business.ServiceOnt { ServiceId = s.Id, Service = s.Service, AccessId = srs.Access.Id, CreatedDateTime = s.Created }).ToList();
586: }
587:
588: list = list1.Concat(list2).ToList();
589:
590: foreach (var l in list)
591: {
592: l.Ont = ontAccessIdToOntForOltIdListDictionary.ContainsKey(l.AccessId) ? ontAccessIdToOntForOltIdListDictionary[l.AccessId] : null;
593: }
594:
595: return list;
596: }
597:
598: ////////////////////////////////////////////////////////////////////////////
599:
600: /// <summary>
601: /// Services within Huawei switch domain list
602: /// </summary>
603: public static List<string> ServiceIdWithinHuaweiSwitchDomainList()
604: {
605: List<int> huaweiSwitchDomainList;
606: List<string> list;
607:
608: huaweiSwitchDomainList = Ia.Ngn.Cl.Model.Data.Service.HuaweiSwitchDomainList;
609:
610: using (var db = new Ia.Ngn.Cl.Model.Ngn())
611: {
612: list = (from s in db.Service2
613: where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && huaweiSwitchDomainList.Any(u => s.Service.StartsWith(u.ToString()))
614: select s.Id).ToList();
615: }
616:
617: return list.ToList();
618: }
619:
620: ////////////////////////////////////////////////////////////////////////////
621:
622: /// <summary>
623: /// Services within Nokia switch domain list
624: /// </summary>
625: public static List<string> ServiceIdWithinNokiaSwitchDomainList()
626: {
627: List<int> nokiaSwitchDomainList;
628: List<string> list;
629:
630: nokiaSwitchDomainList = Ia.Ngn.Cl.Model.Data.Service.NokiaSwitchDomainList;
631:
632: using (var db = new Ia.Ngn.Cl.Model.Ngn())
633: {
634: list = (from s in db.Service2
635: where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && nokiaSwitchDomainList.Any(u => s.Service.StartsWith(u.ToString()))
636: select s.Id).ToList();
637: }
638:
639: return list.ToList();
640: }
641:
642: ////////////////////////////////////////////////////////////////////////////
643:
644: /// <summary>
645: ///
646: /// </summary>
647: public static List<string> ServiceIdWithNullAccessList()
648: {
649: List<string> list;
650:
651: using (var db = new Ia.Ngn.Cl.Model.Ngn())
652: {
653: list = (from s in db.Service2
654: where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Access == null
655: select s.Id).ToList();
656: }
657:
658: return list;
659: }
660:
661: ////////////////////////////////////////////////////////////////////////////
662:
663: /// <summary>
664: ///
665: /// </summary>
666: public static List<Ia.Ngn.Cl.Model.Service2> ServiceSuspensionIsTrueList
667: {
668: get
669: {
670: List<Ia.Ngn.Cl.Model.Service2> serviceList;
671:
672: using (var db = new Ia.Ngn.Cl.Model.Ngn())
673: {
674: serviceList = (from s in db.Service2
675: where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.ServiceSuspension == true
676: select s).ToList();
677: }
678:
679: return serviceList;
680: }
681: }
682:
683: ////////////////////////////////////////////////////////////////////////////
684:
685: /// <summary>
686: ///
687: /// </summary>
688: public static int ServiceSuspensionIsTrueListCount
689: {
690: get
691: {
692: int c;
693:
694: using (var db = new Ia.Ngn.Cl.Model.Ngn())
695: {
696: c = (from s in db.Service2
697: where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.ServiceSuspension == true
698: select s).Count();
699: }
700:
701: return c;
702: }
703: }
704:
705: ////////////////////////////////////////////////////////////////////////////
706:
707: /// <summary>
708: ///
709: /// </summary>
710: public static List<Ia.Ngn.Cl.Model.Service2> ServiceSuspensionIsFalseList
711: {
712: get
713: {
714: List<Ia.Ngn.Cl.Model.Service2> serviceList;
715:
716: using (var db = new Ia.Ngn.Cl.Model.Ngn())
717: {
718: serviceList = (from s in db.Service2
719: where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.ServiceSuspension == false
720: select s).ToList();
721: }
722:
723: return serviceList;
724: }
725: }
726:
727: ////////////////////////////////////////////////////////////////////////////
728:
729: /// <summary>
730: ///
731: /// </summary>
732: public static List<string> ServiceSuspensionIsTrueStringNumberList
733: {
734: get
735: {
736: List<string> serviceNumberStringList;
737: List<Ia.Ngn.Cl.Model.Service2> serviceList;
738:
739: using (var db = new Ia.Ngn.Cl.Model.Ngn())
740: {
741: // below:
742: serviceList = ServiceSuspensionIsTrueList;
743:
744: if (serviceList.Count > 0)
745: {
746: serviceNumberStringList = new List<string>(serviceList.Count);
747:
748: foreach (Ia.Ngn.Cl.Model.Service2 srs in serviceList)
749: {
750: serviceNumberStringList.Add(srs.Service);
751: }
752: }
753: else
754: {
755: // below: not null
756: serviceNumberStringList = new List<string>(1);
757: }
758: }
759:
760: return serviceNumberStringList;
761: }
762: }
763:
764: ////////////////////////////////////////////////////////////////////////////
765:
766: /// <summary>
767: ///
768: /// </summary>
769: public static List<string> ServiceSuspensionIsFalseStringNumberList
770: {
771: get
772: {
773: List<string> serviceNumberStringList;
774: List<Ia.Ngn.Cl.Model.Service2> serviceList;
775:
776: using (var db = new Ia.Ngn.Cl.Model.Ngn())
777: {
778: // below:
779: serviceList = ServiceSuspensionIsFalseList;
780:
781: if (serviceList.Count > 0)
782: {
783: serviceNumberStringList = new List<string>(serviceList.Count);
784:
785: foreach (Ia.Ngn.Cl.Model.Service2 srs in serviceList)
786: {
787: serviceNumberStringList.Add(srs.Service);
788: }
789: }
790: else
791: {
792: // below: not null
793: serviceNumberStringList = new List<string>(1);
794: }
795: }
796:
797: return serviceNumberStringList;
798: }
799: }
800:
801: ////////////////////////////////////////////////////////////////////////////
802:
803: /// <summary>
804: ///
805: /// </summary>
806: public static Dictionary<string, string> ServiceIdToAccessIdDictionary
807: {
808: get
809: {
810: Dictionary<string, string> dictionary, nullAccessDictionary;
811:
812: using (var db = new Ia.Ngn.Cl.Model.Ngn())
813: {
814: dictionary = (from s in db.Service2
815: where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Access != null
816: select new { s.Id, s.Access }).ToDictionary(u => u.Id, u => u.Access.Id);
817:
818: nullAccessDictionary = (from s in db.Service2
819: where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Access == null
820: select new { s.Id, s.Access }).ToDictionary(u => u.Id, u => string.Empty);
821: }
822:
823: return dictionary.Union(nullAccessDictionary).ToDictionary(u => u.Key, u => u.Value);
824: }
825: }
826:
827: ////////////////////////////////////////////////////////////////////////////
828:
829: /// <summary>
830: ///
831: /// </summary>
832: public static Dictionary<string, string> PstnServiceIdToAccessIdDictionary
833: {
834: get
835: {
836: Dictionary<string, string> dictionary, nullAccessDictionary;
837:
838: using (var db = new Ia.Ngn.Cl.Model.Ngn())
839: {
840: dictionary = (from s in db.Service2
841: where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.PstnService && s.Access != null
842: select new { s.Id, s.Access }).ToDictionary(u => u.Id, u => u.Access.Id);
843:
844: nullAccessDictionary = (from s in db.Service2
845: where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.PstnService && s.Access == null
846: select new { s.Id, s.Access }).ToDictionary(u => u.Id, u => string.Empty);
847: }
848:
849: return dictionary.Union(nullAccessDictionary).ToDictionary(u => u.Key, u => u.Value);
850: }
851: }
852:
853: ////////////////////////////////////////////////////////////////////////////
854:
855: /// <summary>
856: ///
857: /// </summary>
858: public static Dictionary<string, string> MigratedServiceIdToAccessIdDictionary
859: {
860: get
861: {
862: Dictionary<string, string> dictionary, nullAccessDictionary;
863:
864: var migrationDomainList = Ia.Ngn.Cl.Model.Data.Service.MigrationDomainList;
865: var migrationDomainStringList = migrationDomainList.ConvertAll<string>(delegate (int i) { return i.ToString(); });
866:
867: using (var db = new Ia.Ngn.Cl.Model.Ngn())
868: {
869: dictionary = (from s in db.Service2
870: where s.Access != null && migrationDomainStringList.Any(u => s.Service.StartsWith(u))
871: select new { s.Id, s.Access }).ToDictionary(u => u.Id, u => u.Access.Id);
872:
873: nullAccessDictionary = (from s in db.Service2
874: where s.Access == null && migrationDomainStringList.Any(u => s.Service.StartsWith(u))
875: select new { s.Id, s.Access }).ToDictionary(u => u.Id, u => string.Empty);
876: }
877:
878: return dictionary.Union(nullAccessDictionary).ToDictionary(u => u.Key, u => u.Value);
879: }
880: }
881:
882: ////////////////////////////////////////////////////////////////////////////
883:
884: /// <summary>
885: ///
886: /// </summary>
887: public static Dictionary<string, string> MigratedServiceIdToAccessIdInAllowedToBeMigratedOltDictionary
888: {
889: get
890: {
891: Dictionary<string, string> dictionary;
892:
893: var allowedToBeMigratedOltIdList = Ia.Ngn.Cl.Model.Data.Service.AllowedToBeMigratedOltIdList;
894:
895: var migrationDomainList = Ia.Ngn.Cl.Model.Data.Service.MigrationDomainList;
896: var migrationDomainStringList = migrationDomainList.ConvertAll<string>(delegate (int i) { return i.ToString(); });
897:
898: using (var db = new Ia.Ngn.Cl.Model.Ngn())
899: {
900: dictionary = (from s in db.Service2
901: where s.Access != null && migrationDomainStringList.Any(u => s.Service.StartsWith(u)) && allowedToBeMigratedOltIdList.Contains(s.Access.Olt) && s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService
902: select new { s.Id, s.Access }).ToDictionary(u => u.Id, u => u.Access.Id);
903: }
904:
905: return dictionary.ToDictionary(u => u.Key, u => u.Value);
906: }
907: }
908:
909: ////////////////////////////////////////////////////////////////////////////
910:
911: /// <summary>
912: ///
913: /// </summary>
914: public static Dictionary<string, string> GponServiceToAccessIdInAllowedToBeMigratedOltDictionary
915: {
916: get
917: {
918: Dictionary<string, string> dictionary;
919:
920: var allowedToBeMigratedOltIdList = Ia.Ngn.Cl.Model.Data.Service.AllowedToBeMigratedOltIdList;
921:
922: var migrationDomainList = Ia.Ngn.Cl.Model.Data.Service.MigrationDomainList;
923: var migrationDomainStringList = migrationDomainList.ConvertAll<string>(delegate (int i) { return i.ToString(); });
924:
925: using (var db = new Ia.Ngn.Cl.Model.Ngn())
926: {
927: /*
928: dictionary = (from s in db.Service2s
929: where s.Access != null && migrationDomainStringList.Any(u => s.Service.StartsWith(u)) && allowedToBeMigratedOltIdList.Contains(s.Access.Olt) && s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService
930: select new { s.Service, s.Access }).ToDictionary(u => u.Service, u => u.Access.Id);
931: */
932:
933: var list = (from s in db.Service2
934: where s.Access != null && s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService
935: select new { s.Service, AccessId = s.Access.Id, AccessOlt = s.Access.Olt }).ToList();
936:
937: dictionary = (from l in list
938: where migrationDomainStringList.Any(u => l.Service.StartsWith(u)) && allowedToBeMigratedOltIdList.Contains(l.AccessOlt)
939: select l).ToDictionary(u => u.Service, u => u.AccessId);
940: }
941:
942: return dictionary.ToDictionary(u => u.Key, u => u.Value);
943: }
944: }
945:
946: ////////////////////////////////////////////////////////////////////////////
947:
948: /// <summary>
949: ///
950: /// </summary>
951: public static Dictionary<string, string> ServiceToAccessIdDictionary
952: {
953: get
954: {
955: string key;
956: Dictionary<string, string> serviceToAccessIdDictionary, serviceIdToAccessIdDictionary;
957:
958: serviceIdToAccessIdDictionary = ServiceIdToAccessIdDictionary;
959:
960: serviceToAccessIdDictionary = new Dictionary<string, string>(serviceIdToAccessIdDictionary.Count);
961:
962: foreach (KeyValuePair<string, string> kvp in serviceIdToAccessIdDictionary)
963: {
964: key = Ia.Ngn.Cl.Model.Business.Service.ServiceIdToService(kvp.Key);
965:
966: serviceToAccessIdDictionary[key] = kvp.Value;
967: }
968:
969: return serviceToAccessIdDictionary;
970: }
971: }
972:
973: ////////////////////////////////////////////////////////////////////////////
974:
975: /// <summary>
976: ///
977: /// </summary>
978: public static Dictionary<string, string> ServiceIdToAccessNameDictionary
979: {
980: get
981: {
982: Dictionary<string, string> dictionary, nullAccessDictionary;
983:
984: using (var db = new Ia.Ngn.Cl.Model.Ngn())
985: {
986: dictionary = (from s in db.Service2
987: where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Access != null
988: select new { s.Id, s.Access }).ToDictionary(u => u.Id, u => u.Access.Name);
989:
990: nullAccessDictionary = (from s in db.Service2
991: where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Access == null
992: select s.Id).ToDictionary(u => u, null);
993: }
994:
995: return dictionary.Union(nullAccessDictionary).ToDictionary(u => u.Key, u => u.Value);
996: }
997: }
998:
999: ////////////////////////////////////////////////////////////////////////////
1000:
1001: /// <summary>
1002: ///
1003: /// </summary>
1004: public static Dictionary<string, int> AccessNameToSeviceCountDictionary()
1005: {
1006: string accessName;
1007: Dictionary<string, int> dictionary;
1008:
1009: using (var db = new Ia.Ngn.Cl.Model.Ngn())
1010: {
1011: var accessIdToAccessNameDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntAccessNameDictionary;
1012:
1013: var serviceToAccessIdDictionary = (from s in db.Service2
1014: where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.Access != null
1015: select new { s.Service, AccessId = s.Access.Id }).ToDictionary(u => u.Service, u => u.AccessId);
1016:
1017: dictionary = new Dictionary<string, int>(serviceToAccessIdDictionary.Count);
1018:
1019: foreach (KeyValuePair<string, string> kvp in serviceToAccessIdDictionary)
1020: {
1021: accessName = accessIdToAccessNameDictionary[kvp.Value];
1022:
1023: if (!string.IsNullOrEmpty(accessName))
1024: {
1025: if (dictionary.ContainsKey(accessName))
1026: {
1027: dictionary[accessName] = dictionary[accessName] + 1;
1028: }
1029: else dictionary[accessName] = 1;
1030: }
1031: }
1032: }
1033:
1034: return dictionary.ToDictionary(u => u.Key, u => u.Value);
1035: }
1036:
1037: ////////////////////////////////////////////////////////////////////////////
1038:
1039: /// <summary>
1040: ///
1041: /// </summary>
1042: public static Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont> ServiceToNddOntDictionary
1043: {
1044: get
1045: {
1046: string key;
1047: Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont> dictionary;
1048:
1049: var serviceIdToAccessIdDictionary = Ia.Ngn.Cl.Model.Data.Service2.ServiceIdToAccessIdDictionary;
1050: var ontAccessIdToOntDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntDictionary;
1051:
1052: dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont>(serviceIdToAccessIdDictionary.Count);
1053:
1054: foreach (KeyValuePair<string, string> kvp in serviceIdToAccessIdDictionary)
1055: {
1056: key = Ia.Ngn.Cl.Model.Business.Service.ServiceIdToService(kvp.Key);
1057:
1058: if (!string.IsNullOrEmpty(kvp.Value)) dictionary[key] = ontAccessIdToOntDictionary[kvp.Value];
1059: else dictionary[key] = null;
1060: }
1061:
1062: return dictionary;
1063: }
1064: }
1065:
1066: ////////////////////////////////////////////////////////////////////////////
1067:
1068: /// <summary>
1069: ///
1070: /// </summary>
1071: public static Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont> PstnServiceToNddOntDictionary
1072: {
1073: get
1074: {
1075: string key;
1076: Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont> dictionary;
1077:
1078: var pstnServiceIdToAccessIdDictionary = Ia.Ngn.Cl.Model.Data.Service2.PstnServiceIdToAccessIdDictionary;
1079: var ontAccessIdToOntDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntDictionary;
1080:
1081: dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont>(pstnServiceIdToAccessIdDictionary.Count);
1082:
1083: foreach (KeyValuePair<string, string> kvp in pstnServiceIdToAccessIdDictionary)
1084: {
1085: key = Ia.Ngn.Cl.Model.Business.Service.ServiceIdToService(kvp.Key);
1086:
1087: if (!string.IsNullOrEmpty(kvp.Value)) dictionary[key] = ontAccessIdToOntDictionary[kvp.Value];
1088: //else dictionary[key] = null;
1089: }
1090:
1091: return dictionary;
1092: }
1093: }
1094:
1095: ////////////////////////////////////////////////////////////////////////////
1096:
1097: /// <summary>
1098: ///
1099: /// </summary>
1100: public static Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor> MigratedServiceToNddOntRouterVendorDictionary
1101: {
1102: get
1103: {
1104: string key;
1105: Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor> dictionary;
1106:
1107: var migratedServiceIdToAccessIdDictionary = Ia.Ngn.Cl.Model.Data.Service2.MigratedServiceIdToAccessIdDictionary;
1108: var ontAccessIdToOntDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntDictionary;
1109:
1110: dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor>(migratedServiceIdToAccessIdDictionary.Count);
1111:
1112: foreach (KeyValuePair<string, string> kvp in migratedServiceIdToAccessIdDictionary)
1113: {
1114: key = Ia.Ngn.Cl.Model.Business.Service.ServiceIdToService(kvp.Key);
1115:
1116: //if (!string.IsNullOrEmpty(kvp.Value)) dictionary[key] = ontAccessIdToOntDictionary[kvp.Value];
1117: //else dictionary[key] = null;
1118: }
1119:
1120: return dictionary;
1121: }
1122: }
1123:
1124: ////////////////////////////////////////////////////////////////////////////
1125:
1126: /// <summary>
1127: ///
1128: /// </summary>
1129: public static Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site> ServiceToSiteDictionary
1130: {
1131: get
1132: {
1133: int fourLetterServiceDomain, fiveLetterServiceDomain;
1134: string service;
1135: Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site> dictionary;
1136:
1137: var serviceIdList = Ia.Ngn.Cl.Model.Data.Service2.ServiceIdList;
1138: var routerDomainToSiteDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.RouterDomainToSiteDictionary;
1139:
1140: dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site>(serviceIdList.Count);
1141:
1142: foreach (string s in serviceIdList)
1143: {
1144: service = Ia.Ngn.Cl.Model.Business.Service.ServiceIdToService(s);
1145:
1146: if (service.Length >= 5)
1147: {
1148: fourLetterServiceDomain = int.Parse(service.Substring(0, 4));
1149: fiveLetterServiceDomain = int.Parse(service.Substring(0, 5));
1150:
1151: if (routerDomainToSiteDictionary.ContainsKey(fiveLetterServiceDomain)) dictionary[service] = routerDomainToSiteDictionary[fiveLetterServiceDomain];
1152: else if (routerDomainToSiteDictionary.ContainsKey(fourLetterServiceDomain)) dictionary[service] = routerDomainToSiteDictionary[fourLetterServiceDomain];
1153: //else throw new System.ArgumentOutOfRangeException("Service number " + service + " is out of range");
1154: }
1155: //else throw new System.ArgumentOutOfRangeException("Service number " + service + " is out of range");
1156: }
1157:
1158: return dictionary;
1159: }
1160: }
1161:
1162: ////////////////////////////////////////////////////////////////////////////
1163:
1164: /// <summary>
1165: ///
1166: /// </summary>
1167: public static Dictionary<string, string> ServiceNotInServiceRequestServiceToSiteDictionary
1168: {
1169: get
1170: {
1171: string service, siteName;
1172: Dictionary<string, string> dictionary;
1173:
1174: var serviceToSiteNameDictionary = Ia.Ngn.Cl.Model.Data.Service2.ServiceToSiteDictionary;
1175: var serviceRequestServiceServiceToSiteNameDictionary = Ia.Ngn.Cl.Model.Data.ServiceRequestService.ServiceToSiteDictionary;
1176:
1177: dictionary = new Dictionary<string, string>();
1178:
1179: foreach (var kvp in serviceToSiteNameDictionary)
1180: {
1181: service = kvp.Key;
1182: siteName = kvp.Value.Name;
1183:
1184: if (!serviceRequestServiceServiceToSiteNameDictionary.ContainsKey(service)) dictionary.Add(service, siteName);
1185: }
1186:
1187: return dictionary;
1188: }
1189: }
1190:
1191: ////////////////////////////////////////////////////////////////////////////
1192:
1193: /// <summary>
1194: ///
1195: /// </summary>
1196: public static Dictionary<string, string> ServiceNotInProvisionedServiceRequestServiceToSiteDictionary
1197: {
1198: get
1199: {
1200: string service, siteName;
1201: Dictionary<string, string> dictionary;
1202:
1203: var serviceToSiteNameDictionary = Ia.Ngn.Cl.Model.Data.Service2.ServiceToSiteDictionary;
1204: var serviceRequestServiceProvisionedServiceToSiteNameDictionary = Ia.Ngn.Cl.Model.Data.ServiceRequestService.ProvisionedServiceToSiteDictionary;
1205:
1206: dictionary = new Dictionary<string, string>();
1207:
1208: foreach (var kvp in serviceToSiteNameDictionary)
1209: {
1210: service = kvp.Key;
1211: siteName = kvp.Value.Name;
1212:
1213: if (!serviceRequestServiceProvisionedServiceToSiteNameDictionary.ContainsKey(service)) dictionary.Add(service, siteName);
1214: }
1215:
1216: return dictionary;
1217: }
1218: }
1219:
1220: ////////////////////////////////////////////////////////////////////////////
1221:
1222: /// <summary>
1223: ///
1224: /// </summary>
1225: public static Dictionary<string, int> PstnFiveDigitDomainToCountOfServicesDictionary()
1226: {
1227: var dictionary = new Dictionary<string, int>();
1228:
1229: using (var db = new Ia.Ngn.Cl.Model.Ngn())
1230: {
1231: /*
1232: select substring(s.Service,1,5), count(s.Service)
1233: from Service2 s
1234: where ServiceType = 2 -- PSTN
1235: group by substring(s.Service,1,5)
1236: */
1237:
1238: dictionary = (from s in db.Service2
1239: where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.PstnService
1240: group s.Service.Substring(0, 5) by s.Service.Substring(0, 5) into g
1241: select new { PstnFiveDigitDomain = g.Key, ServiceCount = g.Count() }).ToDictionary(t => t.PstnFiveDigitDomain, t => t.ServiceCount);
1242: }
1243:
1244: return dictionary;
1245: }
1246:
1247: ////////////////////////////////////////////////////////////////////////////
1248:
1249: /// <summary>
1250: ///
1251: /// </summary>
1252: public static void UpdatePstnServiceAccess(string service, string newAccessId, Guid userId, out Ia.Cl.Model.Result result)
1253: {
1254: int serviceType;
1255: string service2Id;
1256: Ia.Ngn.Cl.Model.Service2 service2;
1257:
1258: result = new Ia.Cl.Model.Result();
1259:
1260: serviceType = Ia.Ngn.Cl.Model.Business.Service.ServiceType.PstnService; // PSTN
1261: service2Id = Ia.Ngn.Cl.Model.Business.Service2.ServiceId(service, serviceType);
1262:
1263: using (var db = new Ia.Ngn.Cl.Model.Ngn())
1264: {
1265: service2 = (from s in db.Service2 where s.Id == service2Id select s).SingleOrDefault();
1266:
1267: if (service2 != null)
1268: {
1269: if (!string.IsNullOrEmpty(newAccessId))
1270: {
1271: if (service2.Access == null || service2.Access != null && service2.Access.Id != newAccessId)
1272: {
1273: service2.Access = (from a in db.Accesses where a.Id == newAccessId select a).SingleOrDefault();
1274: service2.UserId = userId;
1275:
1276: db.Service2.Attach(service2);
1277: db.Entry(service2).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
1278:
1279: db.SaveChanges();
1280:
1281: result.AddSuccess("Service " + service + " was updated with access " + service2.Access.Name + " (تم تحديث ربط الجهاز بالرقم). ");
1282: }
1283: else
1284: {
1285: result.AddWarning("Service access value was not updated because submitted data is the same as current data and because access is not null (لم يتم تغيير الجهاز المربوط بالرقم لأن المعلومات المعطاة هي ذاتها لم تتغير ولأن الجهاز معرف). ");
1286: }
1287: }
1288: else //if(string.IsNullOrEmpty(updatedAccessId))
1289: {
1290: if (service2.Access != null)
1291: {
1292: service2.Access = (from a in db.Accesses where a.Id == string.Empty select a).SingleOrDefault();
1293: service2.Port = Ia.Ngn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown;
1294: service2.UserId = userId;
1295:
1296: db.Service2.Attach(service2);
1297: db.Entry(service2).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
1298:
1299: db.SaveChanges();
1300:
1301: result.AddSuccess("Service " + service + " was updated with null access and " + Ia.Ngn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown + " port (تم مسح ربط الجهاز بالرقم ومسح المنفذ). ");
1302: }
1303: else
1304: {
1305: result.AddWarning("Service access and port values were not resetted because submitted data (access null and port " + Ia.Ngn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown + ") is the same as current data (لم يتم تغيير الجهاز المربوط بالرقم أو المنفذ لأن المعلومات المعطاة هي ذاتها لم تتغير). ");
1306: }
1307: }
1308: }
1309: else
1310: {
1311: result.AddWarning("Service " + service + " does not exist (رقم الخدمة غير موجود). ");
1312: }
1313: }
1314: }
1315:
1316: ////////////////////////////////////////////////////////////////////////////
1317:
1318: /// <summary>
1319: ///
1320: /// </summary>
1321: public static void UpdateGponServiceAccess(string service, string newAccessId, Guid userId, out Ia.Cl.Model.Result result)
1322: {
1323: int serviceType;
1324: string service2Id;
1325: Ia.Ngn.Cl.Model.Service2 service2;
1326:
1327: result = new Ia.Cl.Model.Result();
1328:
1329: serviceType = Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService;
1330: service2Id = Ia.Ngn.Cl.Model.Business.Service2.ServiceId(service, serviceType);
1331:
1332: using (var db = new Ia.Ngn.Cl.Model.Ngn())
1333: {
1334: service2 = (from s in db.Service2 where s.Id == service2Id select s).Include(s => s.Access).SingleOrDefault();
1335:
1336: if (service2 != null)
1337: {
1338: if (!string.IsNullOrEmpty(newAccessId))
1339: {
1340: if (service2.Access == null || service2.Access != null && service2.Access.Id != newAccessId)
1341: {
1342: service2.Access = (from a in db.Accesses where a.Id == newAccessId select a).SingleOrDefault();
1343: service2.UserId = userId;
1344:
1345: db.Service2.Attach(service2);
1346: db.Entry(service2).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
1347:
1348: db.SaveChanges();
1349:
1350: result.AddSuccess("Service " + service + " was updated with access " + service2.Access.Name);
1351: }
1352: else
1353: {
1354: result.AddWarning("Service access not updated");
1355: }
1356: }
1357: else
1358: {
1359: if (service2.Access != null)
1360: {
1361: service2.Access = (from a in db.Accesses where a.Id == string.Empty select a).SingleOrDefault();
1362: service2.Port = Ia.Ngn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown;
1363: service2.UserId = userId;
1364:
1365: db.Service2.Attach(service2);
1366: db.Entry(service2).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
1367:
1368: db.SaveChanges();
1369:
1370: result.AddSuccess("Service " + service + " was updated with null access and " + Ia.Ngn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown + " port.");
1371: }
1372: else
1373: {
1374: result.AddWarning("Service access not resetted.");
1375: }
1376: }
1377: }
1378: else
1379: {
1380: result.AddWarning("Service " + service + " does not exist.");
1381: }
1382: }
1383: }
1384:
1385: ////////////////////////////////////////////////////////////////////////////
1386: ////////////////////////////////////////////////////////////////////////////
1387: }
1388:
1389: ////////////////////////////////////////////////////////////////////////////
1390: ////////////////////////////////////////////////////////////////////////////
1391: }