diff --git a/VERAG_REST_SERVER/Controllers/AvisoController/AVISOController.vb b/VERAG_REST_SERVER/Controllers/AvisoController/AVISOController.vb index 69f8f1d..6e12c97 100644 --- a/VERAG_REST_SERVER/Controllers/AvisoController/AVISOController.vb +++ b/VERAG_REST_SERVER/Controllers/AvisoController/AVISOController.vb @@ -740,8 +740,78 @@ Namespace ApiController.Controllers Return PostValue End Function + + ''' + ''' Send AVISO_ERSTELLT notification for a specific Aviso and User + ''' + ''' The ID of the Aviso that was created + ''' The username who should receive the notification + ''' OK if notification was sent successfully, or ERROR-Code if something went wrong + ''' Returns 200 if notification is sent successfully + ''' Returns 400 if parameters are invalid + ''' Returns 404 if Aviso is not found + ''' Returns 500 if notification sending failed + + + + Public Function sendAvisoErstelltNotification(avisoId As Integer, username As String) As HttpResponseMessage + ' Globale Fehlerbehandlung einstellen + VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM = False + VERAG_PROG_ALLGEMEIN.cAllgemein.ERR_OP_GLOBAL = VERAG_PROG_ALLGEMEIN.ERROR_OP.LOG + + Dim response As HttpResponseMessage + + Try + ' Eingabevalidierung + If avisoId <= 0 Then + Return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Der Parameter 'avisoId' muss eine gültige positive Zahl sein.") + End If + + If String.IsNullOrWhiteSpace(username) Then + Return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Der Parameter 'username' darf nicht leer sein.") + End If + + ' Aviso laden und prüfen ob es existiert + Dim avisoObjekt As cAviso = cAviso.getAvisoById(avisoId) + If avisoObjekt Is Nothing Then + Return Request.CreateErrorResponse(HttpStatusCode.NotFound, "Das angegebene Aviso wurde nicht gefunden. ID: " & avisoId) + End If + + ' Benachrichtigung senden + Dim code As Integer = AvisoNotificationCodes.AVISO_ERSTELLT + Dim TXT_Titel As String = "Neues Aviso erstellt" + Dim TXT_Mitteilung As String = "Ein neues Aviso mit der ID " & avisoId & " wurde von " & username & " erstellt und ist bereit zur Bearbeitung." + + Dim benachrichtigungErfolg As Boolean = cAvisoBenachrichtigungen.send_BENACHRICHTIGUNG_AKTIV_AVISOUSER( + avisoId, + -1, ' sendungsId nicht relevant für AVISO_ERSTELLT + TXT_Titel, + TXT_Mitteilung, + code, + avisoObjekt.FIRMA + ) + + If benachrichtigungErfolg Then + response = Request.CreateResponse(HttpStatusCode.OK, "Die AVISO_ERSTELLT") + Else + response = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Die Benachrichtigung konnte nicht gesendet werden.") + End If + + Catch ex As Exception + VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine, System.Reflection.MethodInfo.GetCurrentMethod.Name) + response = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Ein unerwarteter Fehler ist aufgetreten: " & ex.Message) + End Try + + Return response + End Function End Class + ''' + ''' Local notification codes for Aviso notifications + ''' + Public Class AvisoNotificationCodes + Public Const AVISO_ERSTELLT As Integer = 1001 ' Neuer Code für AVISO_ERSTELLT + End Class Class VERAG_IN_AVISO_Exceptions Public Const ERR_01_Wrong_Format As String = "ERR_01"