You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.7 KiB

11 years ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel.DataAnnotations;
  4. using System.ComponentModel.DataAnnotations.Schema;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace Sevomin.Models
  9. {
  10. public class DovominJob
  11. {
  12. [Key]
  13. public long Id { get; set; }
  14. [Index("IX_DovominJobUniqueIndex", Order = 1, IsUnique = true)]
  15. [Required]
  16. [StringLength(128)]
  17. public string DovominId { get; set; }
  18. [Index]
  19. [Index("IX_DovominJobUniqueIndex", Order = 2, IsUnique = true)]
  20. [Required]
  21. public long JobId { get; set; }
  22. [Required]
  23. public DateTime ApplyDate { get; set; }
  24. [Required]
  25. public string CoverLetter { get; set; }
  26. public decimal Affinity { get; set; }
  27. public bool MinimumRequirement { get; set; }
  28. public DateTime? AvalinSeen { get; set; }
  29. public string AvalinComment { get; set; }
  30. public bool AvalinDelete { get; set; }
  31. public virtual Dovomin Dovomin { get; set; }
  32. public virtual Job Job { get; set; }
  33. public DovominJob(Dovomin dovomin, Job job)
  34. {
  35. this.Dovomin = dovomin;
  36. this.Job = job;
  37. CalculateAffinity();
  38. }
  39. private void CalculateAffinity()
  40. {
  41. MinimumRequirement = true;
  42. decimal sum = 0;
  43. decimal count = 0;
  44. Affinity = 0;
  45. foreach (var jp in
  46. Job.JobParameters.Where(x=>x.Moscow != 0 && !string.IsNullOrWhiteSpace(x.StringValue) ))
  47. {
  48. DovominParameter dp = Dovomin.DovominParameters.SingleOrDefault(x=>x.ParameterId == jp.ParameterId);
  49. if (jp.Moscow == 4)
  50. {
  51. if (dp == null)
  52. MinimumRequirement = false;
  53. if ((jp.StringValue != dp.StringValue && jp.NumericValue == 0) ||
  54. (jp.NumericValue > 0 && jp.NumericValue > dp.NumericValue))
  55. {
  56. MinimumRequirement = false;
  57. }
  58. }
  59. count++;
  60. decimal? dpv = dp.NumericValue;
  61. decimal? jpv = jp.NumericValue;
  62. decimal m = jp.Moscow / 4;
  63. if (jpv == null)
  64. {
  65. if (jp.StringValue == dp.StringValue)
  66. sum += m;
  67. continue;
  68. }
  69. if (dpv == null)
  70. continue;
  71. if (jpv > dpv)
  72. sum += m;
  73. else
  74. sum += m * ((jpv.Value - dpv.Value) / jpv.Value);
  75. }
  76. }
  77. }
  78. }