private List <Praise> GetUniquePraises(IslaamDBClient idb) { var praises = idb.PraisesAPI .GetData() .Where(pr => pr.recommendeeId == id) .GroupBy(x => x.recommenderId) .Select(x => x.First()) // make unique .ToList(); return(praises); }
private IEnumerable <Student> GetTeachersAndStudents(IslaamDBClient idb) { return(idb.StudentsAPI .GetData() .Where(x => x.studentId == id || x.teacherId == id)); }
public BioInfo GetBio(IslaamDBClient idb) { var people = idb.PersonAPI.GetDataFromSheet().ToList(); var pronoun = useMasculinePronoun ? "He" : "She"; var possesivePronoun = useMasculinePronoun ? "His" : "Her"; // start var biography = $"{pronoun} is "; var praises = GetUniquePraises(idb); var teachersAndStudents = GetTeachersAndStudents(idb); var teachers = GetUniqueTeachers(teachersAndStudents); var students = GetUniqueStudents(teachersAndStudents); var titles = GetUniqueTitles(praises); var praiserNames = FriendlyJoin(praises.Select(x => x.recommenderName).ToList()); // booleans var hasPraises = praises.Count > 0; var hasTitles = titles.Count > 0; var hasLocation = location != null; var hasKunya = kunya != null; var hasDeathYear = deathYear != null; var hasBirthYear = birthYear != null; var hasBirthPlace = birthPlace != null; var hasTeachers = teachers.Count > 0; var hasStudents = students.Count > 0; var hasGeneration = generation != null; /** The amount of information in this bio **/ var amountOfInfo = GetAmountOfInfo(); // titles if (hasTitles) { biography += $"the {String.Join(", the ", titles)}, "; } // name or kunya if (hasKunya) { biography += kunya; } else { biography += name; } biography += ". "; if (hasGeneration) { biography += $"{pronoun} is from the {generation}. "; } // birth if (hasBirthYear) { if (hasBirthPlace) { biography += $"{pronoun} was born in {birthPlace} in the year {birthYear} AH. "; } else { biography += $"{pronoun} was born in the year {birthYear} AH. "; } } else if (hasBirthPlace) { biography += $"{pronoun} was born in {birthPlace}. (I don't have {possesivePronoun} birth year yet.) "; } // location if (hasLocation) { biography += $"{pronoun} lived in {location}. "; } // praises if (hasPraises) { biography += $"{pronoun} was praised by {praiserNames}. "; } // teachers if (hasTeachers) { biography += $"{pronoun} took knowledge from {FriendlyJoin(teachers)}. "; } // students if (hasStudents) { biography += $"{pronoun} taught {FriendlyJoin(students)}. "; } // books // not yet supported // death year if (hasDeathYear) { biography += $"{pronoun} died in the year {deathYear} AH."; } biography = biography.Trim(); // join sentences together return(new BioInfo { text = biography, amountOfInfo = amountOfInfo, }); int GetAmountOfInfo() { return(new bool[] { hasPraises, hasTitles, hasLocation, hasKunya, hasDeathYear, hasBirthYear, hasBirthPlace, hasTeachers, hasStudents, hasGeneration }.Where(x => x).Count()); } }