1: using System;
2: using System.Collections.Generic;
3: using System.Linq;
4: using System.Web;
5: using System.ComponentModel.DataAnnotations;
6: using System.ComponentModel.DataAnnotations.Schema;
7: using Microsoft.EntityFrameworkCore;
8:
9: namespace Ia.Islamic.Cl.Model.Data
10: {
11: ////////////////////////////////////////////////////////////////////////////
12:
13: /// <summary publish="true">
14: /// Koran Reference Network Class Library support functions: data model
15: /// </summary>
16: /// <value>
17: /// https://msdn.microsoft.com/en-us/library/z1hkazw7(v=vs.100).aspx
18: /// </value>
19: /// <remarks>
20: /// Copyright © 2001-2015 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 class Koran
33: {
34: ////////////////////////////////////////////////////////////////////////////
35:
36: /// <summary>
37: ///
38: /// </summary>
39: public static bool Create(Ia.Islamic.Cl.Model.Koran koran)
40: {
41: bool b;
42:
43: b = false;
44:
45: using (var db = new Ia.Islamic.Cl.Model.Context.Koran())
46: {
47: db.Korans.Add(koran);
48: db.SaveChanges();
49:
50: b = true;
51: }
52:
53: return b;
54: }
55:
56: ////////////////////////////////////////////////////////////////////////////
57:
58: /// <summary>
59: ///
60: /// </summary>
61: public static Ia.Islamic.Cl.Model.Koran Read(string id)
62: {
63: Ia.Islamic.Cl.Model.Koran koran;
64:
65: using (var db = new Ia.Islamic.Cl.Model.Context.Koran())
66: {
67: koran = (from k in db.Korans where k.Id == id select k).SingleOrDefault();
68: }
69:
70: return koran;
71: }
72:
73: ////////////////////////////////////////////////////////////////////////////
74:
75: /// <summary>
76: ///
77: /// </summary>
78: public static List<Ia.Islamic.Cl.Model.Koran> List()
79: {
80: List<Ia.Islamic.Cl.Model.Koran> list;
81:
82: using (var db = new Ia.Islamic.Cl.Model.Context.Koran())
83: {
84: list = (from k in db.Korans select k).Include(u => u.Chapters).ToList();
85: }
86:
87: return list;
88: }
89:
90: ////////////////////////////////////////////////////////////////////////////
91:
92: /// <summary>
93: ///
94: /// </summary>
95: public static bool Update(Ia.Islamic.Cl.Model.Koran updatedKoran)
96: {
97: bool b, isUpdated;
98: Ia.Islamic.Cl.Model.Koran koran;
99:
100: b = false;
101:
102: using (var db = new Ia.Islamic.Cl.Model.Context.Koran())
103: {
104: koran = (from q in db.Korans where q.Id == updatedKoran.Id select q).SingleOrDefault();
105:
106: if (koran == null)
107: {
108: db.Korans.Add(updatedKoran);
109: }
110: else
111: {
112: isUpdated = koran.IsUpdated(updatedKoran);
113:
114: if (isUpdated)
115: {
116: db.Korans.Attach(koran);
117:
118: db.Entry(koran).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
119: }
120: }
121:
122: db.SaveChanges();
123:
124: b = true;
125: }
126:
127: return b;
128: }
129:
130: ////////////////////////////////////////////////////////////////////////////
131:
132: /// <summary>
133: ///
134: /// </summary>
135: public static bool Delete(Ia.Islamic.Cl.Model.Koran koran)
136: {
137: bool b;
138:
139: b = Delete(koran.Id);
140:
141: return b;
142: }
143:
144: ////////////////////////////////////////////////////////////////////////////
145:
146: /// <summary>
147: ///
148: /// </summary>
149: public static bool Delete(string id)
150: {
151: bool b;
152:
153: b = false;
154:
155: using (var db = new Ia.Islamic.Cl.Model.Context.Koran())
156: {
157: var v = (from q in db.Korans where q.Id == id select q).FirstOrDefault();
158:
159: db.Korans.Remove(v);
160: db.SaveChanges();
161:
162: b = true;
163: }
164:
165: return b;
166: }
167:
168: ////////////////////////////////////////////////////////////////////////////
169: ////////////////////////////////////////////////////////////////////////////
170: }
171: }