1: using System;
2: using System.Collections.Generic;
3: using System.ComponentModel.DataAnnotations;
4: using System.ComponentModel.DataAnnotations.Schema;
5: using System.Linq;
6: using System.Threading;
7: using System.Threading.Tasks;
8:
9: namespace Ia.Ngn.Cl.Model
10: {
11: ////////////////////////////////////////////////////////////////////////////
12:
13: /// <summary publish="true">
14: /// ONT-SERVICEVOIP Entity Framework class for Optical Fiber Network (OFN) entity model.
15: /// </summary>
16: ///
17: /// <remarks>
18: /// Copyright © 2006-2021 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
19: ///
20: /// 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
21: /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
22: ///
23: /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
24: /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
25: ///
26: /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
27: ///
28: /// Copyright notice: This notice may not be removed or altered from any source distribution.
29: /// </remarks>
30: public class OntServiceVoip
31: {
32: /// <summary/>
33: public OntServiceVoip() { }
34:
35: /// <summary/>
36: [Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
37: public string Id { get; set; }
38:
39: /// <summary/>
40: public int StateId { get; set; }
41:
42: /// <summary/>
43: public int Svlan { get; set; }
44:
45: /// <summary/>
46: public string Ip { get; set; }
47:
48: /// <summary/>
49: public string FtpIp { get; set; }
50:
51: /// <summary/>
52: public string MgcIp { get; set; }
53:
54: /// <summary/>
55: public string MgcSecondaryIp { get; set; }
56:
57: /// <summary/>
58: public string ConfiguratinFile { get; set; }
59:
60: /// <summary/>
61: public string Customer { get; set; }
62:
63: /// <summary/>
64: public string Label { get; set; }
65:
66: /// <summary/>
67: public DateTime Created { get; set; }
68:
69: /// <summary/>
70: public DateTime Updated { get; set; }
71:
72: /// <summary/>
73: public System.Guid UserId { get; set; }
74:
75: /// <summary/>
76: [ForeignKey("Ont_Id")]
77: public virtual Ont Ont { get; set; }
78:
79: ////////////////////////////////////////////////////////////////////////////
80:
81: /// <summary>
82: ///
83: /// </summary>
84: [NotMapped]
85: public string State
86: {
87: get
88: {
89: return Ia.Ngn.Cl.Model.Data.Nokia.Ams.BellcoreStateFromId(this.StateId);
90: }
91: }
92:
93: ////////////////////////////////////////////////////////////////////////////
94:
95: /// <summary>
96: ///
97: /// </summary>
98: public static bool Create(OntServiceVoip ontServiceVoip, out string result)
99: {
100: bool b;
101:
102: b = false;
103: result = string.Empty;
104:
105: using (var db = new Ia.Ngn.Cl.Model.Ngn())
106: {
107: ontServiceVoip.Created = ontServiceVoip.Updated = DateTime.UtcNow.AddHours(3);
108:
109: db.OntServiceVoips.Add(ontServiceVoip);
110: db.SaveChanges();
111:
112: b = true;
113: }
114:
115: return b;
116: }
117:
118: ////////////////////////////////////////////////////////////////////////////
119:
120: /// <summary>
121: ///
122: /// </summary>
123: public static OntServiceVoip Read(string id)
124: {
125: OntServiceVoip ontServiceVoip;
126:
127: using (var db = new Ia.Ngn.Cl.Model.Ngn())
128: {
129: ontServiceVoip = (from osv in db.OntServiceVoips where osv.Id == id select osv).SingleOrDefault();
130: }
131:
132: return ontServiceVoip;
133: }
134:
135: ////////////////////////////////////////////////////////////////////////////
136:
137: /// <summary>
138: ///
139: /// </summary>
140: public static List<OntServiceVoip> ReadList()
141: {
142: List<OntServiceVoip> ontServiceVoipList;
143:
144: using (var db = new Ia.Ngn.Cl.Model.Ngn())
145: {
146: ontServiceVoipList = (from osv in db.OntServiceVoips select osv).ToList();
147: }
148:
149: return ontServiceVoipList;
150: }
151:
152: ////////////////////////////////////////////////////////////////////////////
153:
154: /// <summary>
155: ///
156: /// </summary>
157: public static bool Update(OntServiceVoip ontServiceVoip, out string result)
158: {
159: bool b;
160:
161: b = false;
162: result = string.Empty;
163:
164: using (var db = new Ia.Ngn.Cl.Model.Ngn())
165: {
166: ontServiceVoip = (from osv in db.OntServiceVoips where osv.Id == ontServiceVoip.Id select osv).SingleOrDefault();
167:
168: ontServiceVoip.Updated = DateTime.UtcNow.AddHours(3);
169:
170: db.OntServiceVoips.Attach(ontServiceVoip);
171:
172: db.Entry(ontServiceVoip).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
173: db.SaveChanges();
174:
175: b = true;
176: }
177:
178: return b;
179: }
180:
181: ////////////////////////////////////////////////////////////////////////////
182:
183: /// <summary>
184: ///
185: /// </summary>
186: public static bool Delete(string id, out string result)
187: {
188: bool b;
189:
190: b = false;
191: result = string.Empty;
192:
193: using (var db = new Ia.Ngn.Cl.Model.Ngn())
194: {
195: var v = (from osv in db.OntServiceVoips where osv.Id == id select osv).FirstOrDefault();
196:
197: db.OntServiceVoips.Remove(v);
198: db.SaveChanges();
199:
200: b = true;
201: }
202:
203: return b;
204: }
205:
206:
207: ////////////////////////////////////////////////////////////////////////////
208:
209: /// <summary>
210: ///
211: /// </summary>
212: public bool Equal(OntServiceVoip b)
213: {
214: // below: this will not check the Id, Created, Updated fields
215: bool areEqual;
216:
217: /*if (this.BatteryBackupAvailable != b.BatteryBackupAvailable) areEqual = false;
218: else*/
219: areEqual = true;
220:
221: return areEqual;
222: }
223:
224: ////////////////////////////////////////////////////////////////////////////
225:
226: /// <summary>
227: ///
228: /// </summary>
229: public bool Update(OntServiceVoip b)
230: {
231: // below: this will not update Id, Created
232: bool updated;
233:
234: updated = false;
235:
236: if (this.ConfiguratinFile != b.ConfiguratinFile) { this.ConfiguratinFile = b.ConfiguratinFile; updated = true; }
237: if (this.Customer != b.Customer) { this.Customer = b.Customer; updated = true; }
238: if (this.FtpIp != b.FtpIp) { this.FtpIp = b.FtpIp; updated = true; }
239: if (this.Ip != b.Ip) { this.Ip = b.Ip; updated = true; }
240: if (this.Label != b.Label) { this.Label = b.Label; updated = true; }
241: if (this.MgcIp != b.MgcIp) { this.MgcIp = b.MgcIp; updated = true; }
242: if (this.MgcSecondaryIp != b.MgcSecondaryIp) { this.MgcSecondaryIp = b.MgcSecondaryIp; updated = true; }
243:
244: if (this.Ont != b.Ont) { this.Ont = b.Ont; updated = true; }
245: if (this.StateId != b.StateId) { this.StateId = b.StateId; updated = true; }
246: if (this.Svlan != b.Svlan) { this.Svlan = b.Svlan; updated = true; }
247: if (this.UserId != b.UserId) { this.UserId = b.UserId; updated = true; }
248:
249: if (updated) this.Updated = DateTime.UtcNow.AddHours(3);
250:
251: return updated;
252: }
253:
254: ////////////////////////////////////////////////////////////////////////////
255: ////////////////////////////////////////////////////////////////////////////
256:
257: /// <summary>
258: ///
259: /// </summary>
260: public string ToSimpleTextString()
261: {
262: return Ia.Ngn.Cl.Model.Data.Nokia.OntServiceVoip.ToSimpleTextString(this);
263: }
264:
265: ////////////////////////////////////////////////////////////////////////////
266: ////////////////////////////////////////////////////////////////////////////
267: }
268:
269: ////////////////////////////////////////////////////////////////////////////
270: ////////////////////////////////////////////////////////////////////////////
271: }