When developing applications on the Kuika platform, you can use various data sources and create Custom Actions. One of these processes can be performed using the C# language. C# is a programming language widely used in modern application development and can serve as a powerful data source integration tool on the Kuika platform. Kuika runs C# functions using .NET 10 and C# 14. In this training content, you will learn how to connect to databases using C#, apply object-oriented programming principles, and develop performance-focused applications.



Action naming field: The name of the data source appears in the top-left corner. You can update the name using the pencil icon next to it. You can use English characters as well as the special characters “-” or “_” in the name.
Template area: You can switch between predefined templates using the drop-down list in the top-right corner:

Editor toolbar: Includes options for undo/redo, copy/paste, code formatting (Tidy Up), line wrapping, and font size adjustment. On the right side, a checkmark indicating whether the code is valid and the cursor’s position (e.g., “Ln 18, Col 1”) are displayed.
Tidy Up: You can automatically align and format your code by clicking the formatting button on the toolbar. This improves the code’s readability.
External Libraries (BETA): You can add the NuGet packages you want to use in your action from this section. Clicking the button opens a two-tabbed panel:


The libraries you add become available for use in your C# code. Paying attention to library versions is important for compatibility.
Kuika AI: You can create functions with AI support from the panel on the right side of the editor. (See Section 3)
Test Console: You can test your function by expanding the TEST CONSOLE area below the editor.
Saving Functions: After creating functions, you can save them by clicking the CREATE button in the top-right corner.
Creating C# Functions with Kuika AI

The Custom Authentication Provider allows you to create customized authentication systems.

The class in the template implements the ICustomAuthentication interface and defines authentication functions. The following methods are provided out of the box:
Login Method: Allows users to log in. There are two separate versions:
If the login is successful, the method returns a Token object containing the user’s information. This object includes the following fields: FirstName, LastName, TokenString, RefreshToken, and Username. The user’s login must be validated; this validation can be performed via a REST API or a custom database.
Refresh Token Method: Used to refresh an expired token.
Find Manager Method: Used to find a user’s manager. Frequently used in Process Automation.
Logout Method: Logs the user out of the system. This method has no return value.
The Custom Authorization Provider is used to determine users’ roles within the application.

The class in the template implements the ICustomAuthorization interface and contains the GetRoles method.
GetRoles Method: Returns the roles the user has within the application as a List<string>.
Parameters:
This structure can be used to define customized roles for users working on specific screens or in specific sections of the app.
The Custom Verification Code Sender Provider allows you to send verification codes generated by Kuika to users via a channel of your choice (SMS, email, push notification, etc.).

The class in the template implements the ICustomVerificationCodeSender interface and contains the SendVerificationCode method.
SendVerificationCode Method: Takes two parameters:
The method’s return value determines who will send the code:
For example, if you want to send the verification code via SMS, call your SMS service within the method using the `user.PhoneNumber` and `verificationcode` values, and return true when the sending is successful.
The Custom Mail Provider allows you to handle your application’s email sending process through an infrastructure or third-party service of your choice. With this setup, you can use your own SMTP server, an email sending API (such as SendGrid, Mailgun, or Amazon SES), or an on-premises email infrastructure instead of Kuika’s default email sending mechanism.
It can be used in the following scenarios:
Creation steps:

The CustomMailClient class in the template implements the ICustomMailClient interface and handles email sending requests triggered from within the application.
request parameter: Contains the email ready for sending:
Important notes:
Return value: Success = true indicates that the email was accepted, not that it was delivered. Return this value only after your API has approved the email (2xx or 202 if queued). Otherwise, the platform will report an email as successful even though it may never have been sent. Subsequent bounces are not reported to the application.
In this example, a class named Calculator is created that contains a method to add two numbers:
using System;
namespace Kuika.ThirdPartyApisCollection
{
public class Calculator
{
public static int Add(int a, int b)
{
return a + b;
}
}
}
using System: Adds the System library, which is required to use basic system functions in C#.
namespace Kuika.ThirdPartyApisCollection: This is the namespace where the C# functions in Kuika are located. It is included by default in templates; it should not be changed.
Calculator class: Created to perform mathematical operations.
Add method: The statement `public static int Add(int a, int b)` takes two integer (int) parameters. The statement `return a + b;` returns the sum of these two values. The method is defined as `public static`, just like in Kuika templates.
This example demonstrates the process of creating a class, defining a method, and performing a simple calculation in the C# language.