1: using Microsoft.EntityFrameworkCore.Metadata.Internal;
2: using System;
3: using System.Collections.Generic;
4: using System.ComponentModel.DataAnnotations;
5: using System.ComponentModel.DataAnnotations.Schema;
6: using System.Linq;
7: using System.Runtime.Serialization;
8: using System.Threading;
9: using System.Threading.Tasks;
10:
11: namespace Ia.Ngn.Cl.Model
12: {
13: ////////////////////////////////////////////////////////////////////////////
14:
15: /// <summary publish="true">
16: /// Service Request Entity Framework class for Optical Fiber Network (OFN) entity model.
17: /// </summary>
18: ///
19: /// <remarks>
20: /// Copyright © 2006-2021 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: [DataContract(IsReference = true, Namespace = "kw.com.ia.ofn.api", Name = "ServiceRequest")]
33: public class ServiceRequest
34: {
35: /// <summary/>
36: public ServiceRequest()
37: {
38: }
39:
40: /// <summary/>
41: [DataMember]
42: [Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
43: public int Id { get; set; }
44:
45: /// <summary/>
46: [DataMember]
47: public int Number { get; set; }
48:
49: /// <summary/>
50: [DataMember]
51: public int Serial { get; set; }
52:
53: /// <summary/>
54: [DataMember]
55: public int Status { get; set; }
56:
57: /// <summary/>
58: [DataMember]
59: public DateTime RequestDateTime { get; set; }
60:
61: /// <summary/>
62: [DataMember]
63: public int CustomerId { get; set; }
64:
65: /// <summary/>
66: [DataMember]
67: public string CustomerName { get; set; }
68:
69: /// <summary/>
70: [DataMember]
71: public int CustomerCategoryId { get; set; }
72:
73: /// <summary/>
74: [DataMember]
75: public string CustomerAddress { get; set; }
76:
77: /// <summary/>
78: [DataMember]
79: public int AreaId { get; set; }
80:
81: /// <summary/>
82: [DataMember]
83: public int ServiceId { get; set; }
84:
85: /// <summary/>
86: [DataMember]
87: public int ServiceCategoryId { get; set; }
88:
89: /// <summary/>
90: [DataMember]
91: public double Balance { get; set; }
92:
93: /// <summary/>
94: [DataMember]
95: public DateTime Created { get; set; }
96:
97: /// <summary/>
98: [DataMember]
99: public DateTime Updated { get; set; }
100:
101: /// <summary/>
102: [DataMember]
103: public System.Guid UserId { get; set; }
104:
105: /// <summary/>
106: [ForeignKey("ServiceRequestService_Id")]
107: public virtual ServiceRequestService ServiceRequestService { get; set; }
108:
109: /// <summary/>
110: public virtual ICollection<ServiceRequestType> ServiceRequestTypes { get; set; }
111:
112: /// <summary/>
113: //public virtual ICollection<ServiceRequestOnt> ServiceRequestOnts { get; set; }
114:
115: ////////////////////////////////////////////////////////////////////////////
116:
117: /// <summary>
118: ///
119: /// </summary>
120: public bool UpdateSkipServiceRequestServiceAndCheckIfOnlyBalanceWasUpdated(ServiceRequest updatedServiceRequest, out bool onlyBalanceWasUpdated)
121: {
122: return Update(updatedServiceRequest, true, out onlyBalanceWasUpdated);
123: }
124:
125: ////////////////////////////////////////////////////////////////////////////
126:
127: /// <summary>
128: ///
129: /// </summary>
130: public bool UpdateSkipServiceRequestService(ServiceRequest updatedServiceRequest)
131: {
132: return Update(updatedServiceRequest, true, out _);
133: }
134:
135: ////////////////////////////////////////////////////////////////////////////
136:
137: /// <summary>
138: ///
139: /// </summary>
140: public bool Update(ServiceRequest updatedServiceRequest)
141: {
142: return Update(updatedServiceRequest, false, out _);
143: }
144:
145: ////////////////////////////////////////////////////////////////////////////
146:
147: /// <summary>
148: ///
149: /// </summary>
150: private bool Update(ServiceRequest updatedServiceRequest, bool skipServiceRequestService, out bool onlyBalanceWasUpdated)
151: {
152: // below: this will not update Id, Created
153: bool updated, balanceWasUpdated;
154:
155: updated = false;
156: balanceWasUpdated = false;
157:
158: if (this.CustomerAddress != updatedServiceRequest.CustomerAddress) { this.CustomerAddress = updatedServiceRequest.CustomerAddress; updated = true; }
159: if (this.AreaId != updatedServiceRequest.AreaId) { this.AreaId = updatedServiceRequest.AreaId; updated = true; }
160: if (this.CustomerCategoryId != updatedServiceRequest.CustomerCategoryId) { this.CustomerCategoryId = updatedServiceRequest.CustomerCategoryId; updated = true; }
161: if (this.CustomerId != updatedServiceRequest.CustomerId) { this.CustomerId = updatedServiceRequest.CustomerId; updated = true; }
162: if (this.CustomerName != updatedServiceRequest.CustomerName) { this.CustomerName = updatedServiceRequest.CustomerName; updated = true; }
163: if (this.Number != updatedServiceRequest.Number) { this.Number = updatedServiceRequest.Number; updated = true; }
164: if (this.RequestDateTime != updatedServiceRequest.RequestDateTime) { this.RequestDateTime = updatedServiceRequest.RequestDateTime; updated = true; }
165: if (this.Serial != updatedServiceRequest.Serial) { this.Serial = updatedServiceRequest.Serial; updated = true; }
166: if (this.ServiceCategoryId != updatedServiceRequest.ServiceCategoryId) { this.ServiceCategoryId = updatedServiceRequest.ServiceCategoryId; updated = true; }
167: if (this.ServiceId != updatedServiceRequest.ServiceId) { this.ServiceId = updatedServiceRequest.ServiceId; updated = true; }
168:
169: if (!skipServiceRequestService) if (this.ServiceRequestService != updatedServiceRequest.ServiceRequestService) { this.ServiceRequestService = updatedServiceRequest.ServiceRequestService; updated = true; }
170: //if (this.ServiceRequestOnts != updatedServiceRequest.ServiceRequestOnts) { this.ServiceRequestOnts = updatedServiceRequest.ServiceRequestOnts; updated = true; }
171: //if (this.ServiceRequestTypes != updatedServiceRequest.ServiceRequestTypes) { this.ServiceRequestTypes = updatedServiceRequest.ServiceRequestTypes; updated = true; }
172:
173: if (this.Status != updatedServiceRequest.Status) { this.Status = updatedServiceRequest.Status; updated = true; }
174: if (this.Balance != updatedServiceRequest.Balance) { this.Balance = updatedServiceRequest.Balance; balanceWasUpdated = true; }
175:
176: if (updated || balanceWasUpdated) this.Updated = DateTime.UtcNow.AddHours(3);
177:
178: onlyBalanceWasUpdated = balanceWasUpdated && !updated;
179:
180: return updated;
181: }
182:
183: ////////////////////////////////////////////////////////////////////////////
184: ////////////////////////////////////////////////////////////////////////////
185:
186: /// <summary>
187: ///
188: /// </summary>
189: public string ToSimpleTextString()
190: {
191: return Ia.Ngn.Cl.Model.Data.ServiceRequest.ToSimpleTextString(this);
192: }
193:
194: ////////////////////////////////////////////////////////////////////////////
195: ////////////////////////////////////////////////////////////////////////////
196: }
197:
198: ////////////////////////////////////////////////////////////////////////////
199: ////////////////////////////////////////////////////////////////////////////
200: }