Add: GetChildByID

Add: GetGuardiansByChild() //MAY NEED DEBUGGING
This commit is contained in:
kougyokugentou 2021-01-21 22:56:50 -08:00
parent acf7b2a405
commit 6ca8d8453e
1 changed files with 29 additions and 0 deletions

View File

@ -21,6 +21,21 @@ namespace GreatHomeChildcare
// ***************** Create *****************
// ***************** Read *******************
/* Gets a single child from the sqlite database
* provided an id number.
* INPUT: integer id
* OUTPUT: Child object
*/
internal Child GetChildByID(int id_in)
{
using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
{
string strQuery = "SELECT * FROM Children WHERE id=@id";
Child output = cnn.Query<Child>(strQuery, new { id = id_in }).SingleOrDefault();
return output;
}
}
/* Gets all children from the sqlite database.
* INPUT: void
* OUTPUT: list of Child objects
@ -43,6 +58,20 @@ namespace GreatHomeChildcare
// ***************** Read *****************
/* Gets all guardians for a single child.
* INPUT: Child
* OUTPUT: List of guardian object.
*/
internal List<Guardian> GetGuardiansByChild(Child child_in)
{
using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
{
string strQuery = "SELECT * FROM Guardians WHERE id IN (SELECT guardian_id FROM Authorized_Guardians WHERE child_id = @id)";
var output = cnn.Query<Guardian>(strQuery, child_in);
return output.ToList();
}
}
/* Gets a Guardian by a distinct pin number. Distinctness enforced elsewhere.
* INPUT: integer pin#
* OUTPUT: Guardian object