1: using Microsoft.EntityFrameworkCore;
2: using System;
3: using System.Collections.Generic;
4: using System.Linq;
5:
6: namespace Ia.Ngn.Cl.Model.Data
7: {
8: ////////////////////////////////////////////////////////////////////////////
9:
10: /// <summary publish="true">
11: /// ServiceExemption Framework class for Optical Fiber Network (OFN) data model.
12: /// </summary>
13: ///
14: /// <remarks>
15: /// Copyright © 2006-2020 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
16: ///
17: /// 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
18: /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
19: ///
20: /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
21: /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
22: ///
23: /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
24: ///
25: /// Copyright notice: This notice may not be removed or altered from any source distribution.
26: /// </remarks>
27: public class ServiceExemption
28: {
29: /// <summary/>
30: public ServiceExemption() { }
31:
32: ////////////////////////////////////////////////////////////////////////////
33:
34: /// <summary>
35: ///
36: /// </summary>
37: public static string Create(Ia.Ngn.Cl.Model.ServiceExemption serviceExemption, out string result)
38: {
39: string id;
40:
41: id = string.Empty;
42: result = string.Empty;
43:
44: using (var db = new Ia.Ngn.Cl.Model.Ngn())
45: {
46: serviceExemption.Created = serviceExemption.Updated = DateTime.UtcNow.AddHours(3);
47:
48: db.ServiceExemptions.Add(serviceExemption);
49: db.SaveChanges();
50:
51: id = serviceExemption.Service;
52: }
53:
54: return id;
55: }
56:
57: ////////////////////////////////////////////////////////////////////////////
58:
59: /// <summary>
60: ///
61: /// </summary>
62: public static Ia.Ngn.Cl.Model.ServiceExemption Read(string id)
63: {
64: Ia.Ngn.Cl.Model.ServiceExemption serviceExemption;
65:
66: using (var db = new Ia.Ngn.Cl.Model.Ngn())
67: {
68: serviceExemption = (from s in db.ServiceExemptions where s.Id == id select s).SingleOrDefault();
69: }
70:
71: return serviceExemption;
72: }
73:
74: ////////////////////////////////////////////////////////////////////////////
75:
76: /// <summary>
77: ///
78: /// </summary>
79: public static List<Ia.Ngn.Cl.Model.ServiceExemption> List()
80: {
81: List<Ia.Ngn.Cl.Model.ServiceExemption> list;
82:
83: using (var db = new Ia.Ngn.Cl.Model.Ngn())
84: {
85: list = (from s in db.ServiceExemptions select s).ToList();
86: }
87:
88: return list;
89: }
90:
91: ////////////////////////////////////////////////////////////////////////////
92:
93: /// <summary>
94: ///
95: /// </summary>
96: public static List<string> ServiceIdList()
97: {
98: List<string> list;
99:
100: using (var db = new Ia.Ngn.Cl.Model.Ngn())
101: {
102: list = (from s in db.ServiceExemptions select s.Id).AsNoTracking().ToList();
103: }
104:
105: return list;
106: }
107:
108: ////////////////////////////////////////////////////////////////////////////
109:
110: /// <summary>
111: ///
112: /// </summary>
113: public static List<string> ServiceList()
114: {
115: List<string> list;
116:
117: using (var db = new Ia.Ngn.Cl.Model.Ngn())
118: {
119: list = (from s in db.ServiceExemptions select s.Service).AsNoTracking().ToList();
120: }
121:
122: return list;
123: }
124:
125: ////////////////////////////////////////////////////////////////////////////
126:
127: /// <summary>
128: ///
129: /// </summary>
130: public static bool Update(Ia.Ngn.Cl.Model.ServiceExemption updatedServiceExemption, out string result)
131: {
132: bool b;
133: Ia.Ngn.Cl.Model.ServiceExemption serviceExemption;
134:
135: b = false;
136: result = string.Empty;
137:
138: using (var db = new Ia.Ngn.Cl.Model.Ngn())
139: {
140: serviceExemption = (from se in db.ServiceExemptions where se.Id == updatedServiceExemption.Id select se).SingleOrDefault();
141:
142: if (serviceExemption.Update(updatedServiceExemption))
143: {
144: db.ServiceExemptions.Attach(serviceExemption);
145: db.Entry(serviceExemption).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
146: }
147:
148: db.SaveChanges();
149:
150: b = true;
151: }
152:
153: return b;
154: }
155:
156: ////////////////////////////////////////////////////////////////////////////
157:
158: /// <summary>
159: ///
160: /// </summary>
161: public static bool Delete(string id)
162: {
163: bool b;
164:
165: b = false;
166:
167: using (var db = new Ia.Ngn.Cl.Model.Ngn())
168: {
169: var v = (from s in db.ServiceExemptions where s.Id == id select s).FirstOrDefault();
170:
171: db.ServiceExemptions.Remove(v);
172: db.SaveChanges();
173:
174: b = true;
175: }
176:
177: return b;
178: }
179:
180: ////////////////////////////////////////////////////////////////////////////
181: ////////////////////////////////////////////////////////////////////////////
182: }
183:
184: ////////////////////////////////////////////////////////////////////////////
185: ////////////////////////////////////////////////////////////////////////////
186: }