/Automation.Model/Document.cs

https://gitlab.com/justbediego/Isaap · C# · 596 lines · 595 code · 1 blank · 0 comment · 144 complexity · 591dd1dda27a467fc30ae0dc742cd363 MD5 · raw file

  1. using Newtonsoft.Json;
  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.Text;
  9. using System.Threading.Tasks;
  10. namespace Automation.Model
  11. {
  12. [Table("Documents")]
  13. public class Document : User
  14. {
  15. public class CompletionStatus
  16. {
  17. public string Message;
  18. public bool IsComplete;
  19. }
  20. public class Workshop : Base
  21. {
  22. public Workshop()
  23. {
  24. TechnicalProtectionCommitteeScans = new List<Attachment>();
  25. ContractScans = new List<Attachment>();
  26. }
  27. public string UnitName { get; set; }
  28. public string EmployerName { get; set; }
  29. public GenderType EmployerGender { get; set; }
  30. public string SocialSecurityCode { get; set; }
  31. public virtual FieldOfActivity FieldOfActivity { get; set; }
  32. public virtual ProductionType ProductionType { get; set; }
  33. public int MaleWorkersNo { get; set; }
  34. public int FemaleWorkersNo { get; set; }
  35. public double WorkshopSize { get; set; }
  36. public int MorningWorkersNo { get; set; }
  37. public int EveningWorkersNo { get; set; }
  38. public int NightWorkersNo { get; set; }
  39. public bool TechnicalProtectionCommittee { get; set; }
  40. [ForeignKey("TechnicalProtectionCommittee_ID")]
  41. public virtual List<Attachment> TechnicalProtectionCommitteeScans { get; set; }
  42. public int SafetyWorkersNo { get; set; }
  43. public string WorkshopAddress { get; set; }
  44. public string WorkshopPhone { get; set; }
  45. public string WorkshopPostalCode { get; set; }
  46. [ForeignKey("Contract_ID")]
  47. public virtual List<Attachment> ContractScans { get; set; }
  48. public DateTime DateFrom { get; set; }
  49. public string Email { get; set; }
  50. public enum SizeCategories
  51. {
  52. Below25 = 1,
  53. Below50Over25 = 2,
  54. Below100Over50 = 3,
  55. Below200Over100 = 4,
  56. Below300Over200 = 5,
  57. Over300 = 6,
  58. }
  59. public SizeCategories SizeCategory
  60. {
  61. get
  62. {
  63. var totalNumer = MaleWorkersNo + FemaleWorkersNo;
  64. if (totalNumer >= 300)
  65. return SizeCategories.Over300;
  66. if (totalNumer >= 200)
  67. return SizeCategories.Below300Over200;
  68. if (totalNumer >= 100)
  69. return SizeCategories.Below200Over100;
  70. if (totalNumer >= 50)
  71. return SizeCategories.Below100Over50;
  72. if (totalNumer > 25)
  73. return SizeCategories.Below50Over25;
  74. return SizeCategories.Below25;
  75. }
  76. }
  77. }
  78. public class AcademicCertification : Base
  79. {
  80. public int FieldOfStudy_ID { get; set; }
  81. [ForeignKey("FieldOfStudy_ID")]
  82. public virtual FieldOfStudy FieldOfStudy { get; set; }
  83. public int? ScanFile_ID { get; set; }
  84. [ForeignKey("ScanFile_ID")]
  85. public virtual Attachment ScanFile { get; set; }
  86. }
  87. public class ExpertContact : Base
  88. {
  89. public int? County_ID { get; set; }
  90. [ForeignKey("County_ID")]
  91. public virtual County County { get; set; }
  92. public string Address { get; set; }
  93. public string PostalCode { get; set; }
  94. public string Phone { get; set; }
  95. }
  96. public class WorkExperience : Base
  97. {
  98. public int Document_ID { get; set; }
  99. [ForeignKey("Document_ID")]
  100. [JsonIgnore]
  101. public Document Document { get; set; }
  102. public string WorkshopName { get; set; }
  103. public string EmployerName { get; set; }
  104. public DateTime DateFrom { get; set; }
  105. public DateTime DateTo { get; set; }
  106. public string Description { get; set; }
  107. }
  108. public class SafetyCertification : Base
  109. {
  110. public enum Type
  111. {
  112. ForthyHours = 1,
  113. SixteenHours = 2,
  114. Others = 3,
  115. }
  116. public Type CourseType { get; set; }
  117. public string OtherCourseName { get; set; }
  118. public double OtherDurationInHours { get; set; }
  119. public DateTime DateTaken { get; set; }
  120. public string IssuerNumber { get; set; }
  121. public int? CertificationScan_ID { get; set; }
  122. [ForeignKey("CertificationScan_ID")]
  123. public virtual Attachment CertificationScan { get; set; }
  124. public string Description { get; set; }
  125. }
  126. public enum GenderType
  127. {
  128. Male = 1,
  129. Female = 2,
  130. }
  131. public enum MilitaryServiceStates
  132. {
  133. Passed = 1,
  134. Exempted = 2,
  135. }
  136. public enum MaritalStates
  137. {
  138. Single = 1,
  139. Married = 2,
  140. }
  141. public DateTime? DeactivationDate { get; set; }
  142. public string ReasonOfDeactivation { get; set; }
  143. public string FirstName { get; set; }
  144. public string LastName { get; set; }
  145. public string FullName
  146. {
  147. get
  148. {
  149. return FirstName + " " + LastName;
  150. }
  151. }
  152. public string FatherName { get; set; }
  153. public string ShenasnameNo { get; set; }
  154. public string NationalCode { get; set; }
  155. public DateTime? BirthDate { get; set; }
  156. public string PlaceOfBirth { get; set; }
  157. public GenderType? Gender { get; set; }
  158. public MaritalStates? MaritalStatus { get; set; }
  159. public MilitaryServiceStates? MilitaryStatus { get; set; }
  160. public string ReasonOfExemption { get; set; }
  161. public virtual AcademicCertification HighSchoolCertification { get; set; }
  162. public virtual AcademicCertification DiplomaCertification { get; set; }
  163. public virtual AcademicCertification BachelorsCertification { get; set; }
  164. public virtual AcademicCertification MastersCertification { get; set; }
  165. public virtual AcademicCertification PhDCertification { get; set; }
  166. public string AssociationMembershipNo { get; set; }
  167. public int? HomeContact_ID { get; set; }
  168. [ForeignKey("HomeContact_ID")]
  169. public virtual ExpertContact HomeContact { get; set; }
  170. public int? WorkContact_ID { get; set; }
  171. [ForeignKey("WorkContact_ID")]
  172. public virtual ExpertContact WorkContact { get; set; }
  173. public string Mobile { get; set; }
  174. public int? PhotoScan_ID { get; set; }
  175. [ForeignKey("PhotoScan_ID")]
  176. public virtual Attachment PhotoScan { get; set; }
  177. [ForeignKey("Shenasname_ID")]
  178. public virtual List<Attachment> ShenasnameScans { get; set; }
  179. [ForeignKey("NationalCard_ID")]
  180. public virtual List<Attachment> NationalCardScans { get; set; }
  181. public virtual Workshop CurrentWorkShop { get; set; }
  182. public virtual List<WorkExperience> WorkExperiences { get; set; }
  183. [ForeignKey("InsuranceRecord_ID")]
  184. public virtual List<Attachment> InsuranceRecordScans { get; set; }
  185. public virtual List<SafetyCertification> SafetyCertifications { get; set; }
  186. public List<ExpertReport> Reports { get; set; }
  187. public enum LevelOfEducations
  188. {
  189. NoEducation = 0,
  190. HighSchool = 1,
  191. Diploma = 2,
  192. Bachelor = 3,
  193. Master = 4,
  194. PhD = 5,
  195. }
  196. public LevelOfEducations LevelOfEducation
  197. {
  198. get
  199. {
  200. if (PhDCertification != null)
  201. return LevelOfEducations.PhD;
  202. if (MastersCertification != null)
  203. return LevelOfEducations.Master;
  204. if (BachelorsCertification != null)
  205. return LevelOfEducations.Bachelor;
  206. if (DiplomaCertification != null)
  207. return LevelOfEducations.Diploma;
  208. if (HighSchoolCertification != null)
  209. return LevelOfEducations.HighSchool;
  210. return LevelOfEducations.NoEducation;
  211. }
  212. }
  213. public CompletionStatus BasicInfoCompleted
  214. {
  215. get
  216. {
  217. if (FirstName == null)
  218. {
  219. return new CompletionStatus()
  220. {
  221. IsComplete = false,
  222. Message = "نام وارد نشده است",
  223. };
  224. }
  225. if (LastName == null)
  226. {
  227. return new CompletionStatus()
  228. {
  229. IsComplete = false,
  230. Message = "نام خانوادگی وارد نشده است",
  231. };
  232. }
  233. if (FatherName == null)
  234. {
  235. return new CompletionStatus()
  236. {
  237. IsComplete = false,
  238. Message = "نام پدر وارد نشده است",
  239. };
  240. }
  241. if (ShenasnameNo == null)
  242. {
  243. return new CompletionStatus()
  244. {
  245. IsComplete = false,
  246. Message = "شناسنامه وارد نشده است",
  247. };
  248. }
  249. if (NationalCode == null)
  250. {
  251. return new CompletionStatus()
  252. {
  253. IsComplete = false,
  254. Message = "کد ملی وارد نشده است",
  255. };
  256. }
  257. if (BirthDate == null)
  258. {
  259. return new CompletionStatus()
  260. {
  261. IsComplete = false,
  262. Message = "تاریخ تولد وارد نشده است",
  263. };
  264. }
  265. if (PlaceOfBirth == null)
  266. {
  267. return new CompletionStatus()
  268. {
  269. IsComplete = false,
  270. Message = "محل تولد وارد نشده است",
  271. };
  272. }
  273. if (MaritalStatus == null)
  274. {
  275. return new CompletionStatus()
  276. {
  277. IsComplete = false,
  278. Message = "وضعیت تاهل وارد نشده است",
  279. };
  280. }
  281. if (Gender == null)
  282. {
  283. return new CompletionStatus()
  284. {
  285. IsComplete = false,
  286. Message = "جنسیت وارد نشده است",
  287. };
  288. }
  289. return new CompletionStatus()
  290. {
  291. IsComplete = true,
  292. };
  293. }
  294. }
  295. public CompletionStatus ContactInfoCompleted
  296. {
  297. get
  298. {
  299. if (Mobile == null)
  300. {
  301. return new CompletionStatus()
  302. {
  303. IsComplete = false,
  304. Message = "همراه وارد نشده است",
  305. };
  306. }
  307. if (HomeContact == null)
  308. {
  309. return new CompletionStatus()
  310. {
  311. IsComplete = false,
  312. Message = "محل سکونت وارد نشده است",
  313. };
  314. }
  315. if (WorkContact == null)
  316. {
  317. return new CompletionStatus()
  318. {
  319. IsComplete = false,
  320. Message = "محل کار وارد نشده است",
  321. };
  322. }
  323. if (HomeContact.County == null)
  324. {
  325. return new CompletionStatus()
  326. {
  327. IsComplete = false,
  328. Message = "شعرستان سکونت وارد نشده است",
  329. };
  330. }
  331. if (WorkContact.County == null)
  332. {
  333. return new CompletionStatus()
  334. {
  335. IsComplete = false,
  336. Message = "شهرستان محل کار وارد نشده است",
  337. };
  338. }
  339. if (HomeContact.Address == null)
  340. {
  341. return new CompletionStatus()
  342. {
  343. IsComplete = false,
  344. Message = "آدرس محل سکونت وارد نشده است",
  345. };
  346. }
  347. if (HomeContact.PostalCode == null)
  348. {
  349. return new CompletionStatus()
  350. {
  351. IsComplete = false,
  352. Message = "کدپستی محل سکونت وارد نشده است",
  353. };
  354. }
  355. if (HomeContact.Phone == null)
  356. {
  357. return new CompletionStatus()
  358. {
  359. IsComplete = false,
  360. Message = "تلفن محل سکونت وارد نشده است",
  361. };
  362. }
  363. if (WorkContact.Address == null)
  364. {
  365. return new CompletionStatus()
  366. {
  367. IsComplete = false,
  368. Message = "آدرس محل کار وارد نشده است",
  369. };
  370. }
  371. if (WorkContact.PostalCode == null)
  372. {
  373. return new CompletionStatus()
  374. {
  375. IsComplete = false,
  376. Message = "کد پستی محل کار وارد نشده است",
  377. };
  378. }
  379. if (WorkContact.Phone == null)
  380. {
  381. return new CompletionStatus()
  382. {
  383. IsComplete = false,
  384. Message = "تلفن محل کار وارد نشده است",
  385. };
  386. }
  387. return new CompletionStatus()
  388. {
  389. IsComplete = true,
  390. };
  391. }
  392. }
  393. public CompletionStatus BasicAttachmentsCompleted
  394. {
  395. get
  396. {
  397. if (PhotoScan_ID == null)
  398. {
  399. return new CompletionStatus()
  400. {
  401. IsComplete = false,
  402. Message = "تصویر شخص وارد نشده است",
  403. };
  404. }
  405. if (ShenasnameScans.Count == 0)
  406. {
  407. return new CompletionStatus()
  408. {
  409. IsComplete = false,
  410. Message = "تصویر شناسنامه وارد نشده است",
  411. };
  412. }
  413. if (NationalCardScans.Count == 0)
  414. {
  415. return new CompletionStatus()
  416. {
  417. IsComplete = false,
  418. Message = "تصویر کارت ملی وارد نشده است",
  419. };
  420. }
  421. return new CompletionStatus()
  422. {
  423. IsComplete = true,
  424. };
  425. }
  426. }
  427. public CompletionStatus CertificationAttachmentsCompleted
  428. {
  429. get
  430. {
  431. if (HighSchoolCertification != null && HighSchoolCertification.ScanFile_ID == null)
  432. return new CompletionStatus()
  433. {
  434. IsComplete = false,
  435. Message = "تصویر مدرک دیپلم وارد نشده است"
  436. };
  437. if (DiplomaCertification != null && DiplomaCertification.ScanFile_ID == null)
  438. return new CompletionStatus()
  439. {
  440. IsComplete = false,
  441. Message = "تصویر مدرک کاردانی وارد نشده است"
  442. };
  443. if (BachelorsCertification != null && BachelorsCertification.ScanFile_ID == null)
  444. return new CompletionStatus()
  445. {
  446. IsComplete = false,
  447. Message = "تصویر مدرک کارشناسی وارد نشده است"
  448. };
  449. if (MastersCertification != null && MastersCertification.ScanFile_ID == null)
  450. return new CompletionStatus()
  451. {
  452. IsComplete = false,
  453. Message = "تصویر مدرک کارشناسی ارشد وارد نشده است"
  454. };
  455. if (PhDCertification != null && PhDCertification.ScanFile_ID == null)
  456. return new CompletionStatus()
  457. {
  458. IsComplete = false,
  459. Message = "تصویر مدرک دکترا وارد نشده است"
  460. };
  461. foreach (var certification in SafetyCertifications)
  462. if (certification.CertificationScan_ID == null)
  463. return new CompletionStatus()
  464. {
  465. IsComplete = false,
  466. Message = "تصویر مدارک ایمنی وارد نشده است"
  467. };
  468. return new CompletionStatus()
  469. {
  470. IsComplete = true,
  471. };
  472. }
  473. }
  474. public CompletionStatus WorkshopAttachmentsCompleted
  475. {
  476. get
  477. {
  478. if (CurrentWorkShop == null)
  479. return new CompletionStatus()
  480. {
  481. IsComplete = false,
  482. Message = "CurrentWorkShop وجود ندارد",
  483. };
  484. if (CurrentWorkShop.ContractScans.Count == 0)
  485. return new CompletionStatus()
  486. {
  487. IsComplete = false,
  488. Message = "تصویر قرارداد وارد نشده است",
  489. };
  490. if (CurrentWorkShop.TechnicalProtectionCommittee && CurrentWorkShop.TechnicalProtectionCommitteeScans.Count == 0)
  491. return new CompletionStatus()
  492. {
  493. IsComplete = false,
  494. Message = "تصویر کمیته حفاظت فنی وارد نشده است",
  495. };
  496. return new CompletionStatus()
  497. {
  498. IsComplete = true,
  499. };
  500. }
  501. }
  502. public CompletionStatus AcademicInfoCompleted
  503. {
  504. get
  505. {
  506. if (HighSchoolCertification == null &&
  507. DiplomaCertification == null &&
  508. BachelorsCertification == null &&
  509. MastersCertification == null &&
  510. PhDCertification == null)
  511. {
  512. return new CompletionStatus()
  513. {
  514. IsComplete = false,
  515. Message = "هیچ مدرک تحصیلی وارد نشده است",
  516. };
  517. }
  518. return new CompletionStatus()
  519. {
  520. IsComplete = true,
  521. };
  522. }
  523. }
  524. public CompletionStatus CertificationCompleted
  525. {
  526. get
  527. {
  528. if (Requires16HourseSafetyCertification)
  529. return new CompletionStatus()
  530. {
  531. IsComplete = false,
  532. Message = "دوره شناسایی خطر و ارزیابی ریسک 16 ساعته وارد نشده است",
  533. };
  534. if (Requires40HourseSafetyCertification)
  535. return new CompletionStatus()
  536. {
  537. IsComplete = false,
  538. Message = "دوره آموزش عمومی ایمنی 40 ساعته یا گواهی آزمون ادواری وارد نشده است",
  539. };
  540. return new CompletionStatus()
  541. {
  542. IsComplete = true,
  543. };
  544. }
  545. }
  546. public bool Requires16HourseSafetyCertification
  547. {
  548. get
  549. {
  550. return !((HighSchoolCertification != null && HighSchoolCertification.FieldOfStudy != null && !HighSchoolCertification.FieldOfStudy.Requires16Hours) ||
  551. (DiplomaCertification != null && DiplomaCertification.FieldOfStudy != null && !DiplomaCertification.FieldOfStudy.Requires16Hours) ||
  552. (BachelorsCertification != null && BachelorsCertification.FieldOfStudy != null && !BachelorsCertification.FieldOfStudy.Requires16Hours) ||
  553. (MastersCertification != null && MastersCertification.FieldOfStudy != null && !MastersCertification.FieldOfStudy.Requires16Hours) ||
  554. (PhDCertification != null && PhDCertification.FieldOfStudy != null && !PhDCertification.FieldOfStudy.Requires16Hours))
  555. && SafetyCertifications.Count(c => c.CourseType == SafetyCertification.Type.SixteenHours) == 0;
  556. }
  557. }
  558. public bool Requires40HourseSafetyCertification
  559. {
  560. get
  561. {
  562. return !((HighSchoolCertification != null && HighSchoolCertification.FieldOfStudy != null && !HighSchoolCertification.FieldOfStudy.Requires40Hours) ||
  563. (DiplomaCertification != null && DiplomaCertification.FieldOfStudy != null && !DiplomaCertification.FieldOfStudy.Requires40Hours) ||
  564. (BachelorsCertification != null && BachelorsCertification.FieldOfStudy != null && !BachelorsCertification.FieldOfStudy.Requires40Hours) ||
  565. (MastersCertification != null && MastersCertification.FieldOfStudy != null && !MastersCertification.FieldOfStudy.Requires40Hours) ||
  566. (PhDCertification != null && PhDCertification.FieldOfStudy != null && !PhDCertification.FieldOfStudy.Requires40Hours))
  567. && SafetyCertifications.Count(c => c.CourseType == SafetyCertification.Type.ForthyHours) == 0;
  568. }
  569. }
  570. public virtual List<Flow> Flows { get; set; }
  571. [ForeignKey("Objection_ID")]
  572. public virtual List<Attachment> ObjectionAttachments { get; set; }
  573. public Flow CurrentFlow
  574. {
  575. get
  576. {
  577. return Flows.OrderBy(f => f.DateCreated).LastOrDefault();
  578. }
  579. }
  580. public string NezamCode { get; set; }
  581. public DateTime? OlympiadRequestDate { get; set; }
  582. public Document()
  583. {
  584. Type = UserType.Expert;
  585. ShenasnameScans = new List<Attachment>();
  586. NationalCardScans = new List<Attachment>();
  587. WorkExperiences = new List<WorkExperience>();
  588. InsuranceRecordScans = new List<Attachment>();
  589. Flows = new List<Flow>();
  590. ObjectionAttachments = new List<Attachment>();
  591. Reports = new List<ExpertReport>();
  592. SafetyCertifications = new List<SafetyCertification>();
  593. }
  594. }
  595. }