Implement GetSchoolByName for school editor
Bugfix .single() to .SingleOrDefault() Move school stuff to a new region.
This commit is contained in:
parent
ea3947eaf2
commit
06e167a75f
@ -64,7 +64,7 @@ namespace DBWizard
|
|||||||
using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
|
using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
|
||||||
{
|
{
|
||||||
string strQuery = "SELECT * FROM students WHERE id=@id";
|
string strQuery = "SELECT * FROM students WHERE id=@id";
|
||||||
Student stu_out = cnn.Query<Student>(strQuery, new { id = dbid_in }).Single();
|
Student stu_out = cnn.Query<Student>(strQuery, new { id = dbid_in }).SingleOrDefault();
|
||||||
|
|
||||||
return stu_out;
|
return stu_out;
|
||||||
}
|
}
|
||||||
@ -155,7 +155,7 @@ namespace DBWizard
|
|||||||
string strQuery = "INSERT INTO PARENTS (FirstName,LastName,PhoneNumber,EmailAddress)" +
|
string strQuery = "INSERT INTO PARENTS (FirstName,LastName,PhoneNumber,EmailAddress)" +
|
||||||
"VALUES (@FirstName,@LastName,@PhoneNumber,@EmailAddress);" +
|
"VALUES (@FirstName,@LastName,@PhoneNumber,@EmailAddress);" +
|
||||||
"SELECT MAX(parent_id) as parent_id from parents;";
|
"SELECT MAX(parent_id) as parent_id from parents;";
|
||||||
int parent_id_out = cnn.Query<int>(strQuery, par).Single();
|
int parent_id_out = cnn.Query<int>(strQuery, par).SingleOrDefault();
|
||||||
return parent_id_out;
|
return parent_id_out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -222,22 +222,23 @@ namespace DBWizard
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Misc
|
#region school
|
||||||
/* Returns the list of available programs from the DB to fill the Programs drop-down.
|
// ***************** Create *****************
|
||||||
* INPUT: no args
|
/* Inserts a new school to the SQL database.
|
||||||
* OUTPUT: List<Program>
|
* INPUT: School
|
||||||
|
* OUTPUT: new row to SQL database, null to program.
|
||||||
*/
|
*/
|
||||||
internal List<Program> GetPrograms()
|
internal void InsertNewSchool(School sch)
|
||||||
{
|
{
|
||||||
using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
|
using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
|
||||||
{
|
{
|
||||||
string strQuery = "SELECT name FROM programs;";
|
string strQuery = "INSERT INTO SCHOOLS (name) VALUES (@name)";
|
||||||
|
cnn.Execute(strQuery, sch);
|
||||||
var output = cnn.Query<Program>(strQuery, new DynamicParameters());
|
|
||||||
return output.ToList();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ***************** Read *****************
|
||||||
|
|
||||||
/* Returns the list of available schools from the DB to fill the Schools drop-down.
|
/* Returns the list of available schools from the DB to fill the Schools drop-down.
|
||||||
* INPUT: no args
|
* INPUT: no args
|
||||||
* OUTPUT: List<School>
|
* OUTPUT: List<School>
|
||||||
@ -252,6 +253,40 @@ namespace DBWizard
|
|||||||
return output.ToList();
|
return output.ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Returns the a single School from the DB by name.
|
||||||
|
* Needed for the school editor.
|
||||||
|
* INPUT: string school_name_in
|
||||||
|
* OUTPUT: School
|
||||||
|
*/
|
||||||
|
internal School GetSchoolByName(string school_name_in)
|
||||||
|
{
|
||||||
|
using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
|
||||||
|
{
|
||||||
|
string strQuery = "SELECT name FROM Schools WHERE name = @school_name;";
|
||||||
|
|
||||||
|
School output = cnn.Query<School>(strQuery, new { school_name = school_name_in }).SingleOrDefault();
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Misc
|
||||||
|
/* Returns the list of available programs from the DB to fill the Programs drop-down.
|
||||||
|
* INPUT: no args
|
||||||
|
* OUTPUT: List<Program>
|
||||||
|
*/
|
||||||
|
internal List<Program> GetPrograms()
|
||||||
|
{
|
||||||
|
using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
|
||||||
|
{
|
||||||
|
string strQuery = "SELECT name FROM programs;";
|
||||||
|
|
||||||
|
var output = cnn.Query<Program>(strQuery, new DynamicParameters());
|
||||||
|
return output.ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region reports
|
#region reports
|
||||||
|
Loading…
Reference in New Issue
Block a user