Guest User

Untitled

a guest
Jan 19th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.05 KB | None | 0 0
  1. {
  2. public class Pation
  3. {
  4. [Key]
  5. public int Id { get; set; }
  6. public string PationName { get; set; }
  7. public int Age { get; set; }
  8. public Sex Sex { get; set; }
  9. public DateTime DateWared { get; set; } = DateTime.UtcNow.AddHours(3);
  10. public int Type_diseaseId { get; set; }
  11. [ForeignKey("Type_diseaseId")]
  12. public virtual Type_disease Type_diseases { get; set; }
  13. public ApplicationUser User { get; set; }
  14. }
  15. public enum Sex
  16. {
  17. boys,
  18. girls,
  19. }
  20. }
  21.  
  22. {
  23. public class Type_disease
  24. {
  25. [Key]
  26. public int Id { get; set; }
  27. public string Namedisease { get; set; }
  28. public virtual ICollection<Pation> Pations { get; set; }
  29.  
  30. }
  31. }
  32.  
  33. {
  34. public class UserRange
  35. {
  36. public string AgeRange { get; set; }
  37. public int Count { get; set; }
  38. public string Gender { get; internal set; }
  39. public string grilsTotal { get; internal set; }
  40. public string boysTotal { get; internal set; }
  41. public string Type_d { get; internal set; }
  42. }
  43.  
  44. }
  45.  
  46. public ActionResult ShowPation()
  47. {
  48. var query1 = from t in db.Pations()
  49. let Agerange =
  50. (
  51. t.Age >= (0) && t.Age < (1) ? "Under year" :
  52. t.Age >= (1) && t.Age < (5) ? "1 _ 4" :
  53. t.Age >= (5) && t.Age < (15) ? "5 _ 14" :
  54. t.Age >= (15) && t.Age < (25) ? "15 _ 24" :
  55. t.Age >= (25) && t.Age < (45) ? "24 _ 44" :
  56. "over 45"
  57. )
  58. let Sex = (t.Sex == 0 ? "boys" : "girls")
  59. group new { t.Age, t.Sex, Agerange } by new { t.DateWared.Year, t.DateWared.Month, Agerange, Sex } into g
  60. select g;
  61.  
  62. var query2 = from g in query1
  63. select new { mycount = g.Count(), g.Key.Year, g.Key.Month, g.Key.Agerange, g.Key.Sex };
  64.  
  65. var query3 = from i in query2
  66. group i by new { i.Year, i.Month} into g
  67. select g;
  68.  
  69. Dictionary<string, List<UserRange>> urn = new Dictionary<string, List<UserRange>>();
  70. foreach (var item in query3)
  71. {
  72. foreach (var item1 in item)
  73. {
  74. if (!urn.ContainsKey(item.Key.Month + "/" + item.Key.Year))
  75. {
  76. urn[item.Key.Month + "/" + item.Key.Year] = new List<UserRange>();
  77. }
  78. urn[item.Key.Month + "/" + item.Key.Year].Add(new UserRange { Count = item1.mycount, AgeRange = item1.Agerange, Gender = item1.Sex });
  79.  
  80. }
  81. urn[item.Key.Month + "/" + item.Key.Year] = urn[item.Key.Month + "/" + item.Key.Year].OrderByDescending(i => i.AgeRange).ToList();//sort the data according to Agerange
  82. }
  83. return View(urn);
  84. }
  85.  
  86. @model Dictionary<string, List<The_Hospital_Project.Models.UserRange>>
  87. <table border="1" class="table table-responsive table-bordered table-hover table-striped " style="height: 145px;text-align: center; border: solid 1px;border-radius: 5px;direction: rtl;">
  88. @foreach (string key in Model.Keys)
  89. {
  90. <tr>
  91. <td colspan="17"> <center>@key</center></td>
  92. </tr>
  93. <tr>
  94.  
  95. @foreach (The_Hospital_Project.Models.UserRange item1 in Model[key])
  96. {
  97. <td style="height: 57px;">@item1.AgeRange</td>
  98. }
  99. </tr>
  100. <tr>
  101.  
  102. @foreach (The_Hospital_Project.Models.UserRange item1 in Model[key])
  103. {
  104. <td>@item1.Gender</td>
  105. }
  106. </tr>
  107. <tr>
  108.  
  109. @foreach (The_Hospital_Project.Models.UserRange item1 in Model[key])
  110. {
  111. <td>@item1.Count</td>
  112. }
  113. </tr>
  114.  
  115. }
  116. </table>
Add Comment
Please, Sign In to add comment