public static async void AddOrphan(Orphan inOrphan) { try { // Replace this with the API code. using (var context = new SMSContext()) { context.Orphans.Add(inOrphan); await context.SaveChangesAsync(); } } catch (Exception eSql) { // Your code may benefit from more robust error handling or logging. // This logging is just a reminder that you should handle exceptions when connecting to remote data. System.Diagnostics.Debug.WriteLine($"Exception: {eSql.Message} {eSql.InnerException?.Message}"); } }
public static async void DeleteAcademic(Academic inAcademic) { try { // Replace with API code using (var context = new SMSContext()) { context.Academics.Remove(inAcademic); await context.SaveChangesAsync(); } } catch (Exception eSql) { // Your code may benefit from more robust error handling or logging. // This logging is just a reminder that you should handle exceptions when connecting to remote data. System.Diagnostics.Debug.WriteLine($"Exception: {eSql.Message} {eSql.InnerException?.Message}"); } }
public static async Task <Guardian> GetGuardianByID(int id) { Guardian returnGuardian = new Guardian(); try { using (var context = new SMSContext()) { returnGuardian = await context.Guardians.FirstAsync(c => c.GuardianID == id); } } catch (Exception eSql) { // Your code may benefit from more robust error handling or logging. // This logging is just a reminder that you should handle exceptions when connecting to remote data. System.Diagnostics.Debug.WriteLine($"Exception: {eSql.Message} {eSql.InnerException?.Message}"); } return(returnGuardian); }
public static async void DeleteGuardian(Guardian inGuardian) { //TODO: If you delete a Guardian that has an Orphan, you will need to make sure the Orphan's // Guardian entry is nulled out. try { // Replace with API code using (var context = new SMSContext()) { context.Guardians.Remove(inGuardian); await context.SaveChangesAsync(); } } catch (Exception eSql) { // Your code may benefit from more robust error handling or logging. // This logging is just a reminder that you should handle exceptions when connecting to remote data. System.Diagnostics.Debug.WriteLine($"Exception: {eSql.Message} {eSql.InnerException?.Message}"); } }
public static async Task <IEnumerable <Guardian> > AllGuardians() { // Using a hard-coded SQL statement for now to make it simpler. Will need to either use API (preferred) // or stored procedure var guardianList = new List <Guardian>(); try { using (var context = new SMSContext()) { guardianList = await context.Guardians .Include(orphan => orphan.Orphans) .Include(narrations => narrations.Narrations) //.Include(notes => notes.Narrations // .OrderByDescending(n => n.EntryDate)) .ToListAsync(); } #region Old code //using (var conn = new SqlConnection(GetConnectionString())) //{ // await conn.OpenAsync(); // if (conn.State == System.Data.ConnectionState.Open) // { // using (var cmd = conn.CreateCommand()) // { // cmd.CommandText = getGuardianQuery; // using (var reader = await cmd.ExecuteReaderAsync()) // { // while (await reader.ReadAsync()) // { // //Orphan Data // var guardianID = !reader.IsDBNull(0) ? reader.GetInt32(0) : 0; // var firstName = reader.GetString(1); // var lastName = reader.GetString(2); // var fullName = reader.GetString(3); // var entryDate = !reader.IsDBNull(4) ? reader.GetDateTime(4) : default(DateTime); // var location = reader.GetString(5); // Guardian inGuardian = new Guardian() // { // GuardianID = guardianID, // FirstName = firstName, // LastName = lastName, // FullName = fullName, // EntryDate = entryDate, // Location = location // }; // // Add to the List<> // guardianList.Add(inGuardian); // } // } // } // } //} #endregion } catch (Exception eSql) { // Your code may benefit from more robust error handling or logging. // This logging is just a reminder that you should handle exceptions when connecting to remote data. System.Diagnostics.Debug.WriteLine($"Exception: {eSql.Message} {eSql.InnerException?.Message}"); } return(guardianList); }