1: using EntityFramework.Triggers;
2: using System;
3: using System.Collections.Generic;
4: using System.ComponentModel.DataAnnotations;
5: using System.ComponentModel.DataAnnotations.Schema;
6:
7: namespace Ia.Ngn.Cl.Model
8: {
9: ////////////////////////////////////////////////////////////////////////////
10:
11: /// <summary publish="true">
12: /// Service Request History Entity Framework class for Next Generation Network (NGN) entity model.
13: /// </summary>
14: ///
15: /// <remarks>
16: /// Copyright © 2019-2019 Jasem Y. Al-Shamlan (info@ia.com.kw), Internet Applications - Kuwait. All Rights Reserved.
17: ///
18: /// 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
19: /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
20: ///
21: /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
22: /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
23: ///
24: /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
25: ///
26: /// Copyright notice: This notice may not be removed or altered from any source distribution.
27: /// </remarks>
28: public partial class ServiceRequestHistory : ITriggerable
29: {
30: /// <summary/>
31: public ServiceRequestHistory()
32: {
33: this.Triggers().Inserting += entry => { TriggeredInstanceQueue.Enqueue(entry.Entity); };
34: this.Triggers().Updating += entry => { TriggeredInstanceQueue.Enqueue(entry.Entity); };
35: this.Triggers().Deleting += entry => { TriggeredInstanceQueue.Enqueue(entry.Entity); };
36: }
37:
38: /// <summary/>
39: [Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
40: public string Id { get; set; }
41: /// <summary/>
42: public int Number { get; set; }
43: /// <summary/>
44: public int Serial { get; set; }
45: /// <summary/>
46: public int Status { get; set; }
47: /// <summary/>
48: public DateTime StartDateTime { get; set; }
49: /// <summary/>
50: public DateTime EndDateTime { get; set; }
51:
52: /// <summary/>
53: public DateTime ServiceDateTime { get; set; }
54: /// <summary/>
55: public int ServiceId { get; set; }
56: /// <summary/>
57: public int ServiceCategoryId { get; set; }
58: /// <summary/>
59: public DateTime Created { get; set; }
60: /// <summary/>
61: public DateTime Updated { get; set; }
62:
63: /// <summary/>
64: public virtual ServiceRequestService ServiceRequestService { get; set; }
65:
66: /// <summary/>
67: [NotMapped]
68: public static Queue<ServiceRequestHistory> TriggeredInstanceQueue = new Queue<ServiceRequestHistory>();
69:
70: ////////////////////////////////////////////////////////////////////////////
71:
72: /// <summary>
73: ///
74: /// </summary>
75: public bool UpdateSkipServiceRequestService(ServiceRequestHistory updatedServiceRequestHistory)
76: {
77: return Update(updatedServiceRequestHistory, true);
78: }
79:
80: ////////////////////////////////////////////////////////////////////////////
81:
82: /// <summary>
83: ///
84: /// </summary>
85: public bool Update(ServiceRequestHistory updatedServiceRequestHistory)
86: {
87: return Update(updatedServiceRequestHistory, false);
88: }
89:
90: ////////////////////////////////////////////////////////////////////////////
91:
92: /// <summary>
93: ///
94: /// </summary>
95: private bool Update(ServiceRequestHistory updatedServiceRequestHistory, bool skipServiceRequestService)
96: {
97: // below: this will not update Id, Created
98: bool updated;
99:
100: updated = false;
101:
102: if (this.Number != updatedServiceRequestHistory.Number) { this.Number = updatedServiceRequestHistory.Number; updated = true; }
103: if (this.Serial != updatedServiceRequestHistory.Serial) { this.Serial = updatedServiceRequestHistory.Serial; updated = true; }
104: if (this.Status != updatedServiceRequestHistory.Status) { this.Status = updatedServiceRequestHistory.Status; updated = true; }
105: if (this.StartDateTime != updatedServiceRequestHistory.StartDateTime) { this.StartDateTime = updatedServiceRequestHistory.StartDateTime; updated = true; }
106: if (this.EndDateTime != updatedServiceRequestHistory.EndDateTime) { this.EndDateTime = updatedServiceRequestHistory.EndDateTime; updated = true; }
107:
108: if (this.ServiceDateTime != updatedServiceRequestHistory.ServiceDateTime) { this.ServiceDateTime = updatedServiceRequestHistory.ServiceDateTime; updated = true; }
109: if (this.ServiceId != updatedServiceRequestHistory.ServiceId) { this.ServiceId = updatedServiceRequestHistory.ServiceId; updated = true; }
110: if (this.ServiceCategoryId != updatedServiceRequestHistory.ServiceCategoryId) { this.ServiceCategoryId = updatedServiceRequestHistory.ServiceCategoryId; updated = true; }
111:
112: if (!skipServiceRequestService) if (this.ServiceRequestService != updatedServiceRequestHistory.ServiceRequestService) { this.ServiceRequestService = updatedServiceRequestHistory.ServiceRequestService; updated = true; }
113:
114: if (updated) this.Updated = DateTime.UtcNow.AddHours(3);
115:
116: return updated;
117: }
118:
119: ////////////////////////////////////////////////////////////////////////////
120: ////////////////////////////////////////////////////////////////////////////
121:
122: /// <summary>
123: ///
124: /// </summary>
125: public string ToSimpleTextString()
126: {
127: return Ia.Ngn.Cl.Model.Data.ServiceRequestHistory.ToSimpleTextString(this);
128: }
129:
130: ////////////////////////////////////////////////////////////////////////////
131: ////////////////////////////////////////////////////////////////////////////
132: }
133:
134: ////////////////////////////////////////////////////////////////////////////
135: ////////////////////////////////////////////////////////////////////////////
136: }