1: using System;
2: using System.Collections;
3: using System.Collections.Generic;
4: using System.Linq;
5: using System.Web;
6: using System.Web.Security;
7: using System.Text.RegularExpressions;
8: using System.Data.Entity;
9: using System.Text;
10:
11: namespace Ia.Ngn.Cl.Model.Data.Nokia
12: {
13: ////////////////////////////////////////////////////////////////////////////
14:
15: /// <summary publish="true">
16: /// ONT-SERVICEHSI support class for Next Generation Network (NGN) Nokia data model.
17: /// </summary>
18: ///
19: /// <remarks>
20: /// Copyright © 2006-2018 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
21: ///
22: /// 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
23: /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
24: ///
25: /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
26: /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
27: ///
28: /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
29: ///
30: /// Copyright notice: This notice may not be removed or altered from any source distribution.
31: /// </remarks>
32: public partial class OntServiceHsi
33: {
34: /// <summary/>
35: public OntServiceHsi() { }
36:
37: ////////////////////////////////////////////////////////////////////////////
38:
39: /// <summary>
40: ///
41: /// </summary>
42: public static bool Create(Ia.Ngn.Cl.Model.OntServiceHsi ontServiceHsi, out string result)
43: {
44: bool b;
45:
46: b = false;
47: result = "";
48:
49: using (var db = new Ia.Ngn.Cl.Model.Ngn())
50: {
51: ontServiceHsi.Created = ontServiceHsi.Updated = DateTime.UtcNow.AddHours(3);
52:
53: db.OntServiceHsis.Add(ontServiceHsi);
54: db.SaveChanges();
55:
56: b = true;
57: }
58:
59: return b;
60: }
61:
62: ////////////////////////////////////////////////////////////////////////////
63:
64: /// <summary>
65: ///
66: /// </summary>
67: public static Ia.Ngn.Cl.Model.OntServiceHsi Read(string id)
68: {
69: Ia.Ngn.Cl.Model.OntServiceHsi item;
70:
71: using (var db = new Ia.Ngn.Cl.Model.Ngn())
72: {
73: item = (from osh in db.OntServiceHsis where osh.Id == id select osh).SingleOrDefault();
74: }
75:
76: return item;
77: }
78:
79: ////////////////////////////////////////////////////////////////////////////
80:
81: /// <summary>
82: ///
83: /// </summary>
84: public static List<Ia.Ngn.Cl.Model.OntServiceHsi> ReadList()
85: {
86: List<Ia.Ngn.Cl.Model.OntServiceHsi> list;
87:
88: using (var db = new Ia.Ngn.Cl.Model.Ngn())
89: {
90: list = (from osh in db.OntServiceHsis select osh).ToList();
91: }
92:
93: return list;
94: }
95:
96: ////////////////////////////////////////////////////////////////////////////
97:
98: /// <summary>
99: ///
100: /// </summary>
101: public static List<Ia.Ngn.Cl.Model.OntServiceHsi> ListIncludeOntAccess()
102: {
103: List<Ia.Ngn.Cl.Model.OntServiceHsi> list;
104:
105: using (var db = new Ia.Ngn.Cl.Model.Ngn())
106: {
107: list = (from osh in db.OntServiceHsis select osh).Include(u => u.Ont.Access).ToList();
108: }
109:
110: return list;
111: }
112:
113: ////////////////////////////////////////////////////////////////////////////
114:
115: /// <summary>
116: ///
117: /// </summary>
118: public static bool Update(Ia.Ngn.Cl.Model.OntServiceHsi ontServiceHsi, out string result)
119: {
120: bool b;
121:
122: b = false;
123: result = "";
124:
125: using (var db = new Ia.Ngn.Cl.Model.Ngn())
126: {
127: ontServiceHsi = (from osh in db.OntServiceHsis where osh.Id == ontServiceHsi.Id select osh).SingleOrDefault();
128:
129: ontServiceHsi.Updated = DateTime.UtcNow.AddHours(3);
130:
131: db.OntServiceHsis.Attach(ontServiceHsi);
132:
133: var v = db.Entry(ontServiceHsi);
134: v.State = System.Data.Entity.EntityState.Modified;
135: db.SaveChanges();
136:
137: b = true;
138: }
139:
140: return b;
141: }
142:
143: ////////////////////////////////////////////////////////////////////////////
144:
145: /// <summary>
146: ///
147: /// </summary>
148: public static bool Delete(string id, out string result)
149: {
150: bool b;
151:
152: b = false;
153: result = "";
154:
155: using (var db = new Ia.Ngn.Cl.Model.Ngn())
156: {
157: var v = (from osh in db.OntServiceHsis where osh.Id == id select osh).FirstOrDefault();
158:
159: db.OntServiceHsis.Remove(v);
160: db.SaveChanges();
161:
162: b = true;
163: }
164:
165: return b;
166: }
167:
168: ////////////////////////////////////////////////////////////////////////////
169:
170: /// <summary>
171: ///
172: /// </summary>
173: public static Dictionary<int, int> DownstreamBandwidthProfileIdAndCountDictionary
174: {
175: get
176: {
177: Dictionary<int, int> dictionary;
178:
179: using (var db = new Ia.Ngn.Cl.Model.Ngn())
180: {
181: dictionary = (from osh in db.OntServiceHsis
182: group osh.Id by osh.DownstreamBandwidthProfileId into g
183: select new { Id = g.Key, Count = g.Count() }).ToDictionary(u => u.Id, u => u.Count);
184: }
185:
186: return dictionary;
187: }
188: }
189:
190: ////////////////////////////////////////////////////////////////////////////
191:
192: /// <summary>
193: ///
194: /// </summary>
195: public static List<string> AccessNameForDownstreamBandwidthProfileIdList(int profileId)
196: {
197: Dictionary<string, string> di;
198: List<string> accessIdList, list;
199:
200: accessIdList = AccessIdForDownstreamBandwidthProfileIdList(profileId);
201:
202: list = new List<string>(accessIdList.Count);
203:
204: di = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntAccessNameDictionary;
205:
206: foreach (string accessId in accessIdList)
207: {
208: if (di[accessId] != null) list.Add(di[accessId]);
209: }
210:
211: return list;
212: }
213:
214: ////////////////////////////////////////////////////////////////////////////
215:
216: /// <summary>
217: ///
218: /// </summary>
219: public static List<string> AccessIdForDownstreamBandwidthProfileIdList(int profileId)
220: {
221: List<string> list;
222:
223: using (var db = new Ia.Ngn.Cl.Model.Ngn())
224: {
225: list = (from osh in db.OntServiceHsis
226: join o in db.Onts on osh.Ont.Id equals o.Id
227: join a in db.Accesses on o.Access.Id equals a.Id
228: where osh.DownstreamBandwidthProfileId == profileId
229: select a.Id).ToList();
230: }
231:
232: return list;
233: }
234:
235: /*
236: ////////////////////////////////////////////////////////////////////////////
237:
238: /// <summary>
239: ///
240: /// </summary>
241: public static List<Ia.Ngn.Cl.Model.OntServiceHsi> ReadListBySerial(string serial)
242: {
243: List<Ia.Ngn.Cl.Model.OntServiceHsi> list;
244:
245: using (var db = new Ia.Ngn.Cl.Model.Ngn())
246: {
247: list = (from q in db.Onts where q.Serial == serial select q).ToList();
248: }
249:
250: return list;
251: }
252: */
253:
254: ////////////////////////////////////////////////////////////////////////////
255:
256: /// <summary>
257: ///
258: /// </summary>
259: public static Dictionary<string, string> IdToOntIdDictionary
260: {
261: get
262: {
263: Dictionary<string, string> dictionary;
264:
265: using (var db = new Ia.Ngn.Cl.Model.Ngn())
266: {
267: dictionary = (from s in db.OntServiceHsis select new { s.Id, OntId = s.Ont.Id }).ToDictionary(u => u.Id, u => u.OntId);
268: }
269:
270: return dictionary.ToDictionary(u => u.Key, u => u.Value);
271: }
272: }
273:
274: ////////////////////////////////////////////////////////////////////////////
275: ////////////////////////////////////////////////////////////////////////////
276:
277: /// <summary>
278: ///
279: /// </summary>
280: public static string ToSimpleTextString(Ia.Ngn.Cl.Model.OntServiceHsi ontServiceHsi)
281: {
282: StringBuilder sb;
283:
284: sb = new StringBuilder();
285:
286: //sb.AppendLine("Vendor: " + Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor.Nokia.Name);
287: sb.AppendLine("State: " + ontServiceHsi.State);
288: sb.AppendLine("Card: " + ontServiceHsi.Card);
289: sb.AppendLine("Port: " + ontServiceHsi.Port);
290: sb.AppendLine("Service: " + ontServiceHsi.Service);
291:
292: sb.AppendLine("DownstreamBandwidthProfile: " + Ia.Ngn.Cl.Model.Data.Hsi.ProfileFromProfileId(ontServiceHsi.DownstreamBandwidthProfileId).Name);
293: sb.AppendLine("UpstreamBandwidthProfile: " + Ia.Ngn.Cl.Model.Data.Hsi.ProfileFromProfileId(ontServiceHsi.UpstreamBandwidthProfileId).Name);
294: sb.AppendLine("PriorityQueueProfileId: " + ontServiceHsi.PriorityQueueProfileId);
295:
296: //sb.AppendLine("Aes: " + ontServiceHsi.Aes);
297: sb.AppendLine("Svlan: " + ontServiceHsi.Svlan);
298: sb.AppendLine("Label: " + ontServiceHsi.Label);
299: sb.AppendLine("Customer: " + ontServiceHsi.Customer);
300:
301: return sb.ToString();
302: }
303:
304: ////////////////////////////////////////////////////////////////////////////
305: ////////////////////////////////////////////////////////////////////////////
306: }
307:
308: ////////////////////////////////////////////////////////////////////////////
309: ////////////////////////////////////////////////////////////////////////////
310: }