BetterFinds
Public Member Functions | Private Attributes | List of all members
BetterFinds.Utils.Client Class Reference

Provides utility functions for handling client-related operations. More...

Public Member Functions

 Client (IConfiguration configuration)
 Initializes a new instance of the Client class. More...
 
int GetClientId (HttpContext httpContext, ClaimsPrincipal user)
 Returns the ClientId of the currently logged in client. More...
 
List< Dictionary< string, object > > GetClients ()
 Returns a list of all clients in the database. More...
 

Private Attributes

readonly IConfiguration configuration
 The IConfiguration instance. More...
 

Detailed Description

Provides utility functions for handling client-related operations.

Constructor & Destructor Documentation

◆ Client()

BetterFinds.Utils.Client.Client ( IConfiguration  configuration)

Initializes a new instance of the Client class.

Parameters
configurationThe IConfiguration instance.

Member Function Documentation

◆ GetClientId()

int BetterFinds.Utils.Client.GetClientId ( HttpContext  httpContext,
ClaimsPrincipal  user 
)
inline

Returns the ClientId of the currently logged in client.

Parameters
httpContextThe HttpContext instance.
userThe ClaimsPrincipal instance.
Returns
The ClientId of the currently logged in client.

Usage example:

var clientUtils = new ClientUtils(configuration);
int clientId = clientUtils.GetClientId(HttpContext, User);
readonly IConfiguration configuration
The IConfiguration instance.
Definition: Client.cs:14

This method checks if the user is authenticated.

If the user is authenticated, it attempts to obtain the ClientId from the session cookie.

If that fails, it retrieves the ClientId from the database using the provided HttpContext and ClaimsPrincipal instances, serving as a fallback.

This ensures that the ClientId is still obtained even if the session cookie is unavailable.

◆ GetClients()

List<Dictionary<string, object> > BetterFinds.Utils.Client.GetClients ( )
inline

Returns a list of all clients in the database.

This method is used to populate the list of clients in the Auction page. Avoiding the multiple database calls that would be required to obtain the clients information. The dictionary returned by this method contains the following keys:

{
"ClientId": int,
"FullName": string,
"Username": string
}
Returns
A list of all clients in the database.

Member Data Documentation

◆ configuration

readonly IConfiguration BetterFinds.Utils.Client.configuration
private

The IConfiguration instance.


The documentation for this class was generated from the following file: