public static async Task <bool> StudentCustodian(FbConnection fbConnection, EcfTableReader ecfTableReader, int tenantId, int studentId, int custodianId) { var success = 0; var sql = "INSERT INTO \"SchuelerSorgebe\" " + "(" + " \"Mandant\", \"Schueler\", \"Sorgebe\", \"Verhaeltnis\", " + " \"Benachrichtigung\", \"TelefonPrioritaet\", \"Position\" " + " )" + "VALUES ( " + " @TenantId, @StudentId, @CustodianId, @RelationshipType, @CustodianNotification, @ContactPriority, @Order " + ")"; using var fbTransaction = fbConnection.BeginTransaction(); try { using var fbCommand = new FbCommand(sql, fbConnection, fbTransaction); Helper.SetParamValue(fbCommand, "@TenantId", FbDbType.BigInt, tenantId); Helper.SetParamValue(fbCommand, "@StudentId", FbDbType.BigInt, studentId); Helper.SetParamValue(fbCommand, "@CustodianId", FbDbType.BigInt, custodianId); Helper.SetParamValue(fbCommand, "@RelationshipType", FbDbType.SmallInt, ValueConvert.RelationShip(ecfTableReader.GetValue <string>("RelationshipType"))); Helper.SetParamValue(fbCommand, "@CustodianNotification", FbDbType.SmallInt, ValueConvert.Notification(ecfTableReader.GetValue <string>("CustodianNotification"))); Helper.SetParamValue(fbCommand, "@ContactPriority", FbDbType.SmallInt, ValueConvert.Priority(ecfTableReader.GetValue <string>("ContactPriority"))); Helper.SetParamValue(fbCommand, "@Order", FbDbType.SmallInt, ecfTableReader.GetValue <string>("Order")); success = await fbCommand.ExecuteNonQueryAsync(); await fbTransaction.CommitAsync(); } catch (Exception e) { fbTransaction.Rollback(); Console.WriteLine($"[INSERT ERROR] [SchuelerSorgebe] {e.Message}"); } return(success > 0); }
public static async Task <bool> StudentCustodian(FbConnection fbConnection, EcfTableReader ecfTableReader, int tenantId, int id) { var success = 0; var sql = "UPDATE \"SchuelerSorgebe\" " + "SET \"Verhaeltnis\" = @RelationshipType " + "WHERE" + " \"Mandant\" = @TenantId AND " + " \"ID\" = @Id"; using var fbTransaction = fbConnection.BeginTransaction(); try { using var fbCommand = new FbCommand(sql, fbConnection, fbTransaction); Helper.SetParamValue(fbCommand, "@TenantId", FbDbType.BigInt, tenantId); Helper.SetParamValue(fbCommand, "@Id", FbDbType.BigInt, id); Helper.SetParamValue(fbCommand, "@RelationshipType", FbDbType.SmallInt, ValueConvert.RelationShip(ecfTableReader.GetValue <string>("RelationshipType"))); success = await fbCommand.ExecuteNonQueryAsync(); await fbTransaction.CommitAsync(); } catch (Exception e) { fbTransaction.Rollback(); Console.WriteLine($"[UPDATE ERROR] [StudentCustodian] {e.Message}"); } return(success > 0); }