/// <summary> /// Uses the FileDataContext to retrieve records of families. The calling class can /// just perform lambda expression to filter data. /// Since a Family record has a foreign key reference of two Resident model, then this method also handles the assignment /// of the two Resident records. /// </summary> /// <returns>List of Family models that contains the data in the text file.</returns> public List <Family> Families() { List <Family> families = new FileDataContext().ReadFamilies(); List <Resident> residents = new FileDataContext().ReadResidents(); List <Family> invalidFamilies = new List <Family>(); foreach (var family in families) { // A family may only have one parent Resident parentInfo = residents.Where(m => m.ResidentId == family.ParentOneId).FirstOrDefault(); // if there is no parent one then skip the family record, and add to invalid families if (parentInfo != null) { family.ParentOne = parentInfo; parentInfo = residents.Where(m => m.ResidentId == family.ParentTwoId).FirstOrDefault(); if (parentInfo != null) { family.ParentTwo = parentInfo; } } else { invalidFamilies.Add(family); } } // remove invalid families foreach (var invalidFamily in invalidFamilies) { families.Remove(invalidFamily); } return(families); }
/// <summary> /// Uses the FileDataContext to retrieve records of recorded summon reports. The calling class can /// just perform lambda expression to filter data. /// Since an Summon record has a foreign key reference of Account model, then this method also handles the assignment /// of the Account record. /// </summary> /// <returns>List of Resident model that contains the data in the text file.</returns> public List <Summon> Summons() { List <Summon> summons = new FileDataContext().ReadSummons(); List <Account> accounts = new FileDataContext().ReadAccounts(); List <Summon> invalidSummons = new List <Summon>(); foreach (var summon in summons) { Account accountInfo = accounts.Where(m => m.AccountId == summon.AccountId).FirstOrDefault(); if (accountInfo != null) { summon.Account = accountInfo; } else { invalidSummons.Add(summon); } } // delete foreach (var invalidSummon in invalidSummons) { summons.Remove(invalidSummon); } return(summons); }
/// <summary> /// Uses the FileDataContext to retrieve records of registered user accounts. The calling class can /// just perform lambda expression to filter data. /// Since an Account record has a foreign key reference of Resident model, then this method also handles the assignment /// of the Resident record. /// </summary> /// <returns>List of Accounts model that contains the data in the text file.</returns> public List <Account> Accounts() { List <Account> accounts = new FileDataContext().ReadAccounts(); List <Resident> residents = new FileDataContext().ReadResidents(); List <Account> invalidAccounts = new List <Account>(); foreach (var account in accounts) { // the account is invalid if the Account does not have Resident record, then we remove it from the list Resident userinfo = residents.Where(m => m.ResidentId == account.ResidentId).FirstOrDefault(); if (userinfo != null) { account.Resident = userinfo; } else { invalidAccounts.Add(account); } } // delete invalid account foreach (var invalidAccount in invalidAccounts) { accounts.Remove(invalidAccount); } return(accounts); }
/// <summary> /// Uses the FileDataContext to retrieve records of recorded audit trails. The calling class can /// just perform lambda expression to filter data. /// Since a AuditTrail record has a foreign key reference of Account model, then this method also handles the assignment /// of the Account record. /// </summary> /// <returns>List of AuditTrail model that contains the data in the text file.</returns> public List <AuditTrail> AuditTrails() { List <AuditTrail> auditTrails = new FileDataContext().ReadAuditTrails(); List <Account> accounts = new FileDataContext().ReadAccounts(); List <AuditTrail> invalidAuditTrails = new List <AuditTrail>(); foreach (var auditTrail in auditTrails) { Account accountInfo = accounts.Where(m => m.AccountId == auditTrail.AccountId).FirstOrDefault(); if (accountInfo != null) { auditTrail.Account = accountInfo; } else { invalidAuditTrails.Add(auditTrail); } } // delete invalid audit trail foreach (var invalidAuditTrail in invalidAuditTrails) { auditTrails.Remove(invalidAuditTrail); } return(auditTrails); }