Visual Basic Class for Add Data Form

Imports Blackbaud.AppFx.Server

Public NotInheritable Class ExampleAddDataForm
    Inherits AppCatalog.AppAddDataForm

    Public SHORTNAME As String
    Public LONGNAME As String
    Public DESCRIPTION As String
    Public RATING As Decimal

    Public Overrides Function Save() As Blackbaud.AppFx.Server.AppCatalog.AppAddDataFormSaveResult

        Dim dataFormSaveResult As New AppCatalog.AppAddDataFormSaveResult
        Try
            Using con As SqlClient.SqlConnection = Me.RequestContext.OpenAppDBConnection()
                Using command As SqlClient.SqlCommand = con.CreateCommand()
                    command.CommandText = _
                        "insert into dbo.[USR_EXAMPLE] (" & _
                        "ID, SHORTNAME, LONGNAME, DESCRIPTION, RATING, ADDEDBYID, CHANGEDBYID, DATEADDED, DATECHANGED" & _
                        ") " & _
                        "values (" & _
                        "@ID,@SHORTNAME,@LONGNAME,@DESCRIPTION,@RATING,@CHANGEAGENTID,@CHANGEAGENTID,@CURRENTDATE,@CURRENTDATE" & _
                        ")"

                    command.Parameters.AddWithValue("@ID", Guid.NewGuid())
                    command.Parameters.AddWithValue("@SHORTNAME", SHORTNAME)
                    command.Parameters.AddWithValue("@LONGNAME", LONGNAME)
                    command.Parameters.AddWithValue("@DESCRIPTION", DESCRIPTION)
                    command.Parameters.AddWithValue("@RATING", RATING)
                    Dim changeAgent As Nullable(Of Guid) = Me.RequestContext.GetChangeAgentID()
                    command.Parameters.AddWithValue("@CHANGEAGENTID", changeAgent)
                    command.Parameters.AddWithValue("@CURRENTDATE", Today)
                    command.ExecuteNonQuery()
                    command.Dispose()
                End Using
            End Using
        Catch ex As Exception
            Throw
        End Try

        Return dataFormSaveResult
    End Function

End Class