1: using System;
2: using System.Collections.Generic;
3: using System.Linq;
4:
5: namespace Ia.Ngn.Cl.Model.Data.Nokia
6: {
7: ////////////////////////////////////////////////////////////////////////////
8:
9: /// <summary publish="true">
10: /// SubParty support class for Nokia's Next Generation Network (NGN) data model.
11: /// </summary>
12: ///
13: /// <remarks>
14: /// Copyright � 2014-2017 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
15: ///
16: /// 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
17: /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
18: ///
19: /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
20: /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
21: ///
22: /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
23: ///
24: /// Copyright notice: This notice may not be removed or altered from any source distribution.
25: /// </remarks>
26: public partial class SubParty
27: {
28: public SubParty() { }
29:
30: ////////////////////////////////////////////////////////////////////////////
31:
32: /// <summary>
33: ///
34: /// </summary>
35: public static bool Create(Ia.Ngn.Cl.Model.Nokia.SubParty subParty, out string result)
36: {
37: bool b;
38:
39: b = false;
40: result = string.Empty;
41:
42: using (var db = new Ia.Ngn.Cl.Model.Ngn())
43: {
44: subParty.Created = subParty.Updated = DateTime.UtcNow.AddHours(3);
45:
46: db.SubParties.Add(subParty);
47: db.SaveChanges();
48:
49: b = true;
50: }
51:
52: return b;
53: }
54:
55: ////////////////////////////////////////////////////////////////////////////
56:
57: /// <summary>
58: ///
59: /// </summary>
60: public static Ia.Ngn.Cl.Model.Nokia.SubParty Read(string id)
61: {
62: Ia.Ngn.Cl.Model.Nokia.SubParty subParty;
63:
64: using (var db = new Ia.Ngn.Cl.Model.Ngn())
65: {
66: subParty = (from sp in db.SubParties where sp.Id == id select sp).SingleOrDefault();
67: }
68:
69: return subParty;
70: }
71:
72: ////////////////////////////////////////////////////////////////////////////
73:
74: /// <summary>
75: ///
76: /// </summary>
77: public static List<Ia.Ngn.Cl.Model.Nokia.SubParty> ReadList()
78: {
79: List<Ia.Ngn.Cl.Model.Nokia.SubParty> subPartyList;
80:
81: using (var db = new Ia.Ngn.Cl.Model.Ngn())
82: {
83: subPartyList = (from sp in db.SubParties select sp).ToList();
84: }
85:
86: return subPartyList;
87: }
88:
89: ////////////////////////////////////////////////////////////////////////////
90:
91: /// <summary>
92: ///
93: /// </summary>
94: public static bool Update(Ia.Ngn.Cl.Model.Nokia.SubParty subParty, out string result)
95: {
96: bool b;
97:
98: b = false;
99: result = string.Empty;
100:
101: using (var db = new Ia.Ngn.Cl.Model.Ngn())
102: {
103: subParty = (from sp in db.SubParties where sp.Id == subParty.Id select sp).SingleOrDefault();
104:
105: subParty.Updated = DateTime.UtcNow.AddHours(3);
106:
107: db.SubParties.Attach(subParty);
108:
109: db.Entry(subParty).State = System.Data.Entity.EntityState.Modified;
110: db.SaveChanges();
111:
112: b = true;
113: }
114:
115: return b;
116: }
117:
118: ////////////////////////////////////////////////////////////////////////////
119:
120: /// <summary>
121: ///
122: /// </summary>
123: public static bool Delete(string id, out string result)
124: {
125: bool b;
126:
127: b = false;
128: result = string.Empty;
129:
130: using (var db = new Ia.Ngn.Cl.Model.Ngn())
131: {
132: var v = (from sp in db.SubParties where sp.Id == id select sp).FirstOrDefault();
133:
134: db.SubParties.Remove(v);
135: db.SaveChanges();
136:
137: b = true;
138: }
139:
140: return b;
141: }
142:
143: ////////////////////////////////////////////////////////////////////////////
144:
145: /// <summary>
146: /// Read list of service PBX numbers that have Category == "SERVICEBUNDLE2"
147: /// </summary>
148: public static List<string> ServicePbxList()
149: {
150: List<string> l1, l2;
151:
152: l1 = l2 = null;
153:
154: using (var db = new Ia.Ngn.Cl.Model.Ngn())
155: {
156: l1 = (from sp in db.SubParties where sp.Category == "SERVICEBUNDLE2" select sp.PartyId).ToList();
157:
158: if (l1.Count > 0)
159: {
160: l2 = new List<string>(l1.Count);
161:
162: foreach (string s in l1) l2.Add(Ia.Ngn.Cl.Model.Business.NumberFormatConverter.Service(s));
163: }
164: }
165:
166: return l2;
167: }
168:
169: ////////////////////////////////////////////////////////////////////////////
170:
171: /// <summary>
172: /// Read list of service Id PBX numbers that have Category == "SERVICEBUNDLE2"
173: /// </summary>
174: public static List<string> ServiceIdPbxList()
175: {
176: int serviceType;
177: string service, serviceId;
178: List<string> l1, l2;
179:
180: serviceType = Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService;
181: l1 = l2 = null;
182:
183: using (var db = new Ia.Ngn.Cl.Model.Ngn())
184: {
185: l1 = (from sp in db.SubParties where sp.Category == "SERVICEBUNDLE2" select sp.PartyId).ToList();
186:
187: if (l1.Count > 0)
188: {
189: l2 = new List<string>(l1.Count);
190:
191: foreach (string u in l1)
192: {
193: service = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.Service(u);
194:
195: serviceId = Ia.Ngn.Cl.Model.Business.Service2.ServiceId(service, serviceType);
196:
197: l2.Add(serviceId);
198: }
199: }
200: }
201:
202: return l2;
203: }
204:
205: ////////////////////////////////////////////////////////////////////////////
206:
207: /// <summary>
208: /// select PrimaryPUIDCPEProfileNumber, count(0) as Count from SubParties group by PrimaryPUIDCPEProfileNumber
209: /// </summary>
210: public static Dictionary<int, int> PrimaryPuidCpeProfileNumberCountDistributionDictionary
211: {
212: get
213: {
214: Dictionary<int, int> dictionary;
215:
216: using (var db = new Ia.Ngn.Cl.Model.Ngn())
217: {
218: var v = (from sp in db.SubParties group sp by sp.PrimaryPUIDCPEProfileNumber into g select new { PrimaryPuidCpeProfileNumber = g.Key, Count = g.Count() });
219: dictionary = v.ToDictionary(u => u.PrimaryPuidCpeProfileNumber, u => u.Count);
220: }
221:
222: return dictionary;
223: }
224: }
225:
226: ////////////////////////////////////////////////////////////////////////////
227:
228: /// <summary>
229: /// SIP numbers with AssocOtasRealm from SubParties
230: /// </summary>
231: public static Dictionary<string, string> SipNumberWithAssocOtasRealmList
232: {
233: get
234: {
235: Dictionary<string, string> dictionary;
236:
237: using (var db = new Ia.Ngn.Cl.Model.Ngn())
238: {
239: var v = (from sp in db.SubParties where sp.PrimaryPUIDCPEProfileNumber == Ia.Ngn.Cl.Model.Business.Nokia.Ims.PrimaryPUIDCPEProfileNumberForSip select new { sp.DisplayName, sp.AssocOtasRealm });
240:
241: dictionary = v.ToDictionary(u => u.DisplayName, u => u.AssocOtasRealm);
242: }
243:
244: return dictionary;
245: }
246: }
247:
248: ////////////////////////////////////////////////////////////////////////////
249: ////////////////////////////////////////////////////////////////////////////
250: }
251:
252: ////////////////////////////////////////////////////////////////////////////
253: ////////////////////////////////////////////////////////////////////////////
254: }