1: using System;
2: using System.Collections.Generic;
3: using System.Linq;
4: using System.Web;
5: using System.Xml;
6: using System.Xml.Linq;
7: using System.Globalization;
8: using System.Data.Linq.Mapping;
9: using System.ComponentModel.DataAnnotations;
10:
11: namespace Ia.Cl.Model.Life
12: {
13: ////////////////////////////////////////////////////////////////////////////
14:
15: /// <summary publish="true">
16: /// Individual object.
17: /// </summary>
18: /// <remarks>
19: /// Copyright © 2001-2015 Jasem Y. Al-Shamlan (info@ia.com.kw), Internet Applications - Kuwait. All Rights Reserved.
20: ///
21: /// 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
22: /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
23: ///
24: /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
25: /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
26: ///
27: /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
28: ///
29: /// Copyright notice: This notice may not be removed or altered from any source distribution.
30: /// </remarks>
31:
32: ////////////////////////////////////////////////////////////////////////////
33:
34: /// <summary>
35: ///
36: /// </summary>
37: public enum Gender
38: {
39: Male = 1, Female = 2, Unknown = 3, PreferNotToSay = 4
40: }
41:
42: ////////////////////////////////////////////////////////////////////////////
43:
44: /// <summary>
45: ///
46: /// </summary>
47: public partial class Individual
48: {
49: //private Social_State social_state;
50: //private Educational_State educational_state;
51: //private string religion;
52: //private Blood blood;
53: //private int civil_id_number;
54:
55: /// <summary/>
56: public Individual() { }
57:
58: /// <summary/>
59: public int Id { get; set; }
60: /// <summary/>
61: public int TypeId { get; set; }
62: /// <summary/>
63: public int[] LanguageId { get; set; }
64: /// <summary/>
65: public string FirstName { get; set; }
66: /// <summary/>
67: public string MiddleName { get; set; }
68: /// <summary/>
69: public string LastName { get; set; }
70: /// <summary/>
71: public string Description { get; set; }
72: /// <summary/>
73: public int? GenderId { get; set; }
74: /// <summary/>
75: public DateTime? DateOfBirth { get; set; }
76: /// <summary/>
77: public string Note { get; set; }
78: /// <summary/>
79: public DateTime Created { get; set; }
80: /// <summary/>
81: public DateTime Updated { get; set; }
82: /// <summary/>
83: public DateTime Inspected { get; set; }
84: /// <summary/>
85: public Guid Guid { get; set; }
86:
87: ////////////////////////////////////////////////////////////////////////////
88:
89: /// <summary>
90: ///
91: /// </summary>
92: public static bool Create(Authentication newItem, out string result)
93: {
94: bool b;
95:
96: b = false;
97: result = "";
98:
99: using (var db = new global::Ia.Cl.Model.Ia())
100: {
101: db.Authentications.Add(newItem);
102: db.SaveChanges();
103:
104: b = true;
105: }
106:
107: return b;
108: }
109:
110: ////////////////////////////////////////////////////////////////////////////
111:
112: /// <summary>
113: ///
114: /// </summary>
115: public static void Create(string password, Uri url, Guid guid)
116: {
117: bool newItemCreated;
118: string result;
119: Authentication newItem;
120:
121: newItem = new Authentication();
122:
123: // insert new item
124: newItem.Password = password;
125: newItem.Host = global::Ia.Cl.Model.Default.BasicHost(url);
126: newItem.Created = DateTime.UtcNow.AddHours(3);
127:
128: newItemCreated = Authentication.Create(newItem, out result);
129: }
130:
131: ////////////////////////////////////////////////////////////////////////////
132:
133: /// <summary>
134: ///
135: /// </summary>
136: public static bool Validate(string password, Uri url)
137: {
138: bool validated;
139: string host;
140: Authentication item;
141:
142: host = global::Ia.Cl.Model.Default.BasicHost(url);
143:
144: using (var db = new global::Ia.Cl.Model.Ia())
145: {
146: item = (from q in db.Authentications where q.Password == password && q.Host == host select q).SingleOrDefault();
147:
148: validated = (item != null);
149: }
150:
151: return validated;
152: }
153:
154: ////////////////////////////////////////////////////////////////////////////
155:
156: /// <summary>
157: ///
158: /// </summary>
159: public static Authentication Read(int id)
160: {
161: Authentication item;
162:
163: using (var db = new global::Ia.Cl.Model.Ia())
164: {
165: item = (from q in db.Authentications where q.Id == id select q).SingleOrDefault();
166: }
167:
168: return item;
169: }
170:
171: ////////////////////////////////////////////////////////////////////////////
172:
173: /// <summary>
174: ///
175: /// </summary>
176: public static List<Authentication> ReadList()
177: {
178: List<Authentication> list;
179:
180: using (var db = new global::Ia.Cl.Model.Ia())
181: {
182: list = (from q in db.Authentications select q).ToList();
183: }
184:
185: return list;
186: }
187:
188: ////////////////////////////////////////////////////////////////////////////
189:
190: /// <summary>
191: ///
192: /// </summary>
193: public static bool Update(Authentication updatedItem, out string result)
194: {
195: bool b;
196:
197: b = false;
198: result = "";
199:
200: using (var db = new global::Ia.Cl.Model.Ia())
201: {
202: updatedItem = (from q in db.Authentications where q.Id == updatedItem.Id select q).SingleOrDefault();
203:
204: updatedItem.Updated = DateTime.UtcNow.AddHours(3);
205:
206: db.Authentications.Attach(updatedItem);
207:
208: var v = db.Entry(updatedItem);
209: v.State = System.Data.Entity.EntityState.Modified;
210: db.SaveChanges();
211:
212: b = true;
213: }
214:
215: return b;
216: }
217:
218: ////////////////////////////////////////////////////////////////////////////
219:
220: /// <summary>
221: ///
222: /// </summary>
223: public static bool Delete(int id, out string result)
224: {
225: bool b;
226:
227: b = false;
228: result = "";
229:
230: using (var db = new global::Ia.Cl.Model.Ia())
231: {
232: var v = (from q in db.Authentications where q.Id == id select q).FirstOrDefault();
233:
234: db.Authentications.Remove(v);
235: db.SaveChanges();
236:
237: b = true;
238: }
239:
240: return b;
241: }
242: }
243:
244: ////////////////////////////////////////////////////////////////////////////
245: ////////////////////////////////////////////////////////////////////////////
246: }