public void OnPost() { NAITProgram ActiveStudents = new NAITProgram(); RequestDirector = new BCS(); ActiveStudents.EnrolledStudent = RequestDirector.FindStudentsByProgram(ProgramCode); if (ActiveStudents.EnrolledStudent.Count < 1) { Success = RequestDirector.DeleteProgram(ProgramCode); if (Success == true) { Message = "Program " + ProgramCode + " Deleted Successfully"; ProgramCode = null; Description = null; } else { Message = "Program Delete Failed"; } } else { Message = "There are Currently Students in " + ProgramCode + " Unable to Delete."; } }
public bool UpdateProgram(NAITProgram SelectedProgram) { bool Success = false; SqlConnection BAIS3150Connection = null; SqlCommand UpdateProgramCommand = null; SqlParameter ProgramParameter; try { BAIS3150Connection = new SqlConnection() { ConnectionString = @"Persist Security Info=False;Integrated Security=True;Database=BAIS3150;Server=.;" }; BAIS3150Connection.Open(); UpdateProgramCommand = new SqlCommand { Connection = BAIS3150Connection, CommandType = CommandType.StoredProcedure, CommandText = "UpdateProgramDescription" }; ProgramParameter = new SqlParameter { ParameterName = "@ProgramCode", DbType = DbType.String, Direction = ParameterDirection.Input, SqlValue = SelectedProgram.ProgramCode }; UpdateProgramCommand.Parameters.Add(ProgramParameter); ProgramParameter = new SqlParameter { ParameterName = "@Description", DbType = DbType.String, Direction = ParameterDirection.Input, SqlValue = SelectedProgram.Description }; UpdateProgramCommand.Parameters.Add(ProgramParameter); UpdateProgramCommand.ExecuteNonQuery(); Success = true; } finally { if (BAIS3150Connection != null) { BAIS3150Connection.Close(); } if (UpdateProgramCommand != null) { UpdateProgramCommand.Dispose(); } } return(Success); }
public void OnGet(string programCode) { RequestDirector = new BCS(); NAITProgram SelectedProgram = new NAITProgram() { ProgramCode = programCode, Description = RequestDirector.FindProgram(programCode).Description }; ProgramCode = SelectedProgram.ProgramCode; Description = SelectedProgram.Description; }
public void OnPost(string programCode, string description) { NAITProgram UpdatedProgram = new NAITProgram() { ProgramCode = programCode, Description = description }; RequestDirector = new BCS(); Success = RequestDirector.UpdateProgramDescription(UpdatedProgram); if (Success == true) { Message = "Program Description Updated Successfully"; ProgramCode = null; Description = null; } else { Message = "Prgram Update Failed"; } }
public NAITProgram GetProgram(string ProgramCode) { NAITProgram SearchedProgram = null; SqlConnection BAIS3150Connection = null; SqlCommand GetProgramCommand = null; SqlDataReader GetProgramDataReader = null; StudentController StudentArray = new StudentController(); try { BAIS3150Connection = new SqlConnection() { ConnectionString = @"Persist Security Info=False;Integrated Security=True;Database=BAIS3150;Server=.;" }; BAIS3150Connection.Open(); GetProgramCommand = new SqlCommand { Connection = BAIS3150Connection, CommandType = CommandType.StoredProcedure, CommandText = "GetProgramByProgramCode" }; SqlParameter ProgramCodeParameter = new SqlParameter { ParameterName = "@ProgramCode", DbType = DbType.String, Direction = ParameterDirection.Input, SqlValue = ProgramCode }; GetProgramCommand.Parameters.Add(ProgramCodeParameter); GetProgramDataReader = GetProgramCommand.ExecuteReader(); if (GetProgramDataReader.HasRows) { GetProgramDataReader.Read(); SearchedProgram = new NAITProgram { Description = GetProgramDataReader[GetProgramDataReader.GetOrdinal("Description")].ToString() }; SearchedProgram.ProgramCode = ProgramCode; SearchedProgram.EnrolledStudent = StudentArray.GetStudents(ProgramCode); } } finally { if (GetProgramDataReader != null) { GetProgramDataReader.Close(); } if (GetProgramCommand != null) { GetProgramCommand.Dispose(); } if (BAIS3150Connection != null) { BAIS3150Connection.Close(); } } return(SearchedProgram); }