hi How are you guys? I need some help Let me explain to you in the first. I have a table with a group of patients per month that means it's a month data compilation process I want to collect patient data per month according to type of disease i mean a total number of patients per month, depending on the type of disease I tried to collect the data by month but I can't collect the data by type of disease here I need your help
- {
- public class Pation
- {
- [Key]
- public int Id { get; set; }
- public string PationName { get; set; }
- public int Age { get; set; }
- public Sex Sex { get; set; }
- public DateTime DateWared { get; set; } = DateTime.UtcNow.AddHours(3);
- public int Type_diseaseId { get; set; }
- [ForeignKey("Type_diseaseId")]
- public virtual Type_disease Type_diseases { get; set; }
- public ApplicationUser User { get; set; }
- }
- public enum Sex
- {
- boys,
- girls,
- }
- }
- {
- public class Type_disease
- {
- [Key]
- public int Id { get; set; }
- public string Namedisease { get; set; }
- public virtual ICollection
Pations { get; set; } - }
- }
i grouped the pation by age an sum values in the model i called
UserRing and it's like this
- {
- public class UserRange
- {
- public string AgeRange { get; set; }
- public int Count { get; set; }
- public string Gender { get; internal set; }
- public string grilsTotal { get; internal set; }
- public string boysTotal { get; internal set; }
- public string Type_d { get; internal set; }
- }
- }
- public ActionResult ShowPation()
- {
- var query1 = from t in db.Pations()
- let Agerange =
- (
- t.Age >= (0) && t.Age < (1) ? "Under year" :
- t.Age >= (1) && t.Age < (5) ? "1 _ 4" :
- t.Age >= (5) && t.Age < (15) ? "5 _ 14" :
- t.Age >= (15) && t.Age < (25) ? "15 _ 24" :
- t.Age >= (25) && t.Age < (45) ? "24 _ 44" :
- "over 45"
- )
- let Sex = (t.Sex == 0 ? "boys" : "girls")
- group new { t.Age, t.Sex, Agerange } by new { t.DateWared.Year, t.DateWared.Month, Agerange, Sex } into g
- select g;
- var query2 = from g in query1
- select new { mycount = g.Count(), g.Key.Year, g.Key.Month, g.Key.Agerange, g.Key.Sex };
- var query3 = from i in query2
- group i by new { i.Year, i.Month} into g
- select g;
- Dictionary<string, List
> urn = new Dictionary<string, List>(); - foreach (var item in query3)
- {
- foreach (var item1 in item)
- {
- if (!urn.ContainsKey(item.Key.Month + "/" + item.Key.Year))
- {
- urn[item.Key.Month + "/" + item.Key.Year] = new List
(); - }
- urn[item.Key.Month + "/" + item.Key.Year].Add(new UserRange { Count = item1.mycount, AgeRange = item1.Agerange, Gender = item1.Sex });
- }
- 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
- }
- return View(urn);
- }
- @model Dictionary<string, List
> -
"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;"> - @foreach (string key in Model.Keys)
- {
-
"17" >@key - @foreach (The_Hospital_Project.Models.UserRange item1 in Model[key])
- {
-
"height: 57px;" >@item1.AgeRange - }
- @foreach (The_Hospital_Project.Models.UserRange item1 in Model[key])
- {
- @item1.Gender
- }
- @foreach (The_Hospital_Project.Models.UserRange item1 in Model[key])
- {
- @item1.Count
- }
- }
The table simply collects all the records every month.
What I want is to sort the records by type of disease
each month , for So far, The code I have works well and collects records every month but I can not sort by type of diseases within each month that's all .


محمد صلاح الدينPosted Jan 24, 2019, 10:41 AM
Salman BegPosted Jan 24, 2019, 9:27 AM