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

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

Public Member Functions

 Auctions (IConfiguration configuration, IHubContext< NotificationHub > hubContext)
 Initializes a new instance of the Auctions class. More...
 
List< Dictionary< string, object > > GetAuctions (int clientId, int order, bool reversed, bool occurring)
 Returns a list of auctions based on the given parameters. More...
 
void ParseAuctionsOptions (string sort, ref int order, ref bool reversed)
 Parses the given sort option and updates the order and reversed parameters accordingly. More...
 
void CreateAuctionsToCheck ()
 Creates a list of auctions that need to be checked by the auction background service. More...
 
void AddAuction (DateTime endTime)
 Adds an auction end time to the AuctionEndTimes list. More...
 
void RemoveAuction (DateTime endTime)
 Removes an auction end time from the AuctionEndTimes list. More...
 
async Task CheckAuctionsAsync ()
 Checks for auctions that ended asynchronously, notifies users and updates the database when ended auctions are found. More...
 
void PrintAuctionsToCheck ()
 Prints the AuctionEndTimes list to the console. More...
 

Private Attributes

readonly IConfiguration configuration
 The IConfiguration instance. More...
 
readonly IHubContext< NotificationHubhubContext
 The IHubContext instance. More...
 

Static Private Attributes

static readonly List< DateTime > AuctionEndTimes = []
 The AuctionEndTimes list contains all the auction end times that need to be checked by the auction background service, initialized at the start of the application. More...
 

Detailed Description

Provides utility functions for handling auctions-related operations.

Constructor & Destructor Documentation

◆ Auctions()

BetterFinds.Utils.Auctions.Auctions ( IConfiguration  configuration,
IHubContext< NotificationHub hubContext 
)
inline

Initializes a new instance of the Auctions class.

Parameters
configurationThe IConfiguration instance.
hubContextThe IHubContext instance.

Member Function Documentation

◆ AddAuction()

void BetterFinds.Utils.Auctions.AddAuction ( DateTime  endTime)

Adds an auction end time to the AuctionEndTimes list.

Referenced by:

Parameters
endTimeThe auction end time to add.

◆ CheckAuctionsAsync()

async Task BetterFinds.Utils.Auctions.CheckAuctionsAsync ( )
inline

Checks for auctions that ended asynchronously, notifies users and updates the database when ended auctions are found.

Referenced by:

When an auction ends, the following notifications are created:

  • The seller is notified that the auction has ended.
  • The bidders (except the buyer) are notified that the auction has ended, if any.
  • The buyer is notified that he won the auction and needs to complete the purchase, if any.

The respective notification count is updated for each user, and respective auction page is refreshed for all users that are currently viewing the auction page.

The auction is marked as checked in the database, to prevent it from being checked again, and it's removed from the AuctionEndTimes list.

Returns
A task that represents the asynchronous operation.

◆ CreateAuctionsToCheck()

void BetterFinds.Utils.Auctions.CreateAuctionsToCheck ( )
inline

Creates a list of auctions that need to be checked by the auction background service.

This method is called at the start of the application to populate the AuctionEndTimes list.

It selects all the auctions that have not ended yet and are not completed (or checked as ended), and adds their end time to the AuctionEndTimes list.

◆ GetAuctions()

List<Dictionary<string, object> > BetterFinds.Utils.Auctions.GetAuctions ( int  clientId,
int  order,
bool  reversed,
bool  occurring 
)
inline

Returns a list of auctions based on the given parameters.

Referenced by:

The parameter clientId retrieves auctions with the following options:

  • 0: all clients
  • _: specific client id

The paramater order sorts the auction list, the options are:

  • 0: by ending time
  • 1: by product price
  • 2: by product name
  • _: by ending time

Returned dictionary format:

{
"AuctionId": int,
"EndTime": DateTime,
"ProductName": string,
"ProductDescription": string,
"ProductPrice": decimal
}
Parameters
clientIdThe client id to retrieve auctions from. If 0, all auctions are retrieved.
orderThe order to sort the auctions by.
reversedWhether to reverse the order of the auctions.
occurringWhether to retrieve only auctions that are occurring.
Returns
A list of auctions based on the given parameters.

◆ ParseAuctionsOptions()

void BetterFinds.Utils.Auctions.ParseAuctionsOptions ( string  sort,
ref int  order,
ref bool  reversed 
)
inline

Parses the given sort option and updates the order and reversed parameters accordingly.

This method is used to parse the sort option selected by the user in pages that have the option to sort the auctions.

Referenced by:

The parameter sort can be one of the following:

  • date or dateRev
  • price or priceRev
  • name or nameRev

The parameter order is updated with the order to sort the auctions by.

The parameter reversed is updated with whether to reverse the order of the auctions.

Parameters
sortThe sort option to parse.
orderThe order returned by the method.
reversedThe reversed returned by the method.

◆ PrintAuctionsToCheck()

void BetterFinds.Utils.Auctions.PrintAuctionsToCheck ( )
inline

Prints the AuctionEndTimes list to the console.

Used for debugging purposes.

Referenced by:

◆ RemoveAuction()

void BetterFinds.Utils.Auctions.RemoveAuction ( DateTime  endTime)

Removes an auction end time from the AuctionEndTimes list.

Referenced by:

Parameters
endTimeThe auction end time to remove.

Member Data Documentation

◆ AuctionEndTimes

readonly List<DateTime> BetterFinds.Utils.Auctions.AuctionEndTimes = []
staticprivate

The AuctionEndTimes list contains all the auction end times that need to be checked by the auction background service, initialized at the start of the application.

This property can only be set from within the class.

This list is populated by the CreateAuctionsToCheck method.

◆ configuration

readonly IConfiguration BetterFinds.Utils.Auctions.configuration
private

The IConfiguration instance.

◆ hubContext

readonly IHubContext<NotificationHub> BetterFinds.Utils.Auctions.hubContext
private

The IHubContext instance.


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