# Class LocalLoginRepository

Namespace
  adas_core.LocalLogin

Assembly
  adas-core.LocalLogin.dll

Repository for handling user data in the local login system. This repository provides methods for inserting, updating, and retrieving user information from a MongoDB collection. It also ensures that a system user is created during the initial load if it does not already exist.

    public class LocalLoginRepository : MongoRepository<User>, ILocalLoginRepository, IMongoRepository<User>

Inheritance
  object
  MongoRepository<User>
  LocalLoginRepository

Implements
  ILocalLoginRepository
  IMongoRepository<User>

Inherited Members
  MongoRepository<User>.Db
  MongoRepository<User>.Collection
  MongoRepository<User>.InsertOneAsync(User)
  MongoRepository<User>.UpdateOneAsync(ObjectId, User)
  MongoRepository<User>.DeleteAsync(ObjectId)
  MongoRepository<User>.CreateIndexes()
  MongoRepository<User>.InsertManyAsync(List<User>)
  MongoRepository<User>.UpdateManyObjectIdAsync(string, ObjectId, ObjectId)
  MongoRepository<User>.DeleteAsync(string)
  MongoRepository<User>.CollectionExists(string)
  object.Equals(object)
  object.Equals(object, object)
  object.GetHashCode()
  object.GetType()
  object.MemberwiseClone()
  object.ReferenceEquals(object, object)
  object.ToString()

Extension Methods
  NumberUtils.IsNumber(object)
  NumberUtils.ToDouble(object)
  ObjectUtils.ToStr(object?)

## Constructors

### LocalLoginRepository(IOptions<ApiSettings>, IMongoDatabase)

Constructor for the LocalLoginRepository. It initializes the repository with the provided API settings and MongoDB database. The API settings are used to determine the collection name for user data, and the database is passed to the base MongoRepository class for handling database operations.

    public LocalLoginRepository(IOptions<ApiSettings> apiSettings, IMongoDatabase database)

#### Parameters

`apiSettings` IOptions<ApiSettings>

  The API settings containing configuration for the MongoDB collection name and other related settings.

`database` IMongoDatabase

  The MongoDB database instance used for database operations.

## Methods

### GetAll()

Retrieves all users from the MongoDB collection. This method executes a query to find all documents in the collection and returns a list of user objects.

    public Task<List<User>> GetAll()

#### Returns

Task<List<User>>

  A list of all user objects in the collection.

### GetByEmail(string)

Retrieves a user from the MongoDB collection by their email address. This method constructs a filter to find the user by their email and returns the first matching user if found; otherwise, it returns null.

    public Task<User?> GetByEmail(string email)

#### Parameters

`email` string

  The email address of the user to retrieve.

#### Returns

Task<User>

  The user object if found, or null if no user is found with the given email address.

### GetById(ObjectId)

Retrieves a user from the MongoDB collection by their unique identifier (ObjectId). This method constructs a filter to find the user by their ID and returns the first matching user if found; otherwise, it returns null.

    public Task<User?> GetById(ObjectId id)

#### Parameters

`id` ObjectId

  The unique identifier of the user to retrieve.

#### Returns

Task<User>

  The user object if found, or null if no user is found with the given ID.

### GetByUsername(string)

Retrieves a user from the MongoDB collection by their username. This method constructs a filter to find the user by their username and returns the first matching user if found; otherwise, it returns null.

    public Task<User?> GetByUsername(string username)

#### Parameters

`username` string

  The username of the user to retrieve.

#### Returns

Task<User>

  The user object if found, or null if no user is found with the given username.

### GetCollectionName()

Gets the name of the MongoDB collection for user data. This method overrides the base method from MongoRepository and returns the collection name specified in the API settings.

    public override string GetCollectionName()

#### Returns

string

  The name of the MongoDB collection for user data.

### InsertInitialLoad()

Inserts initial load data into the MongoDB collection. This method is called during the initial setup of the repository to ensure that a system user is created if it does not already exist. It calls the GetOrCreateSystemUser method to check for the existence of the system user and insert it if necessary.

    public override sealed Task InsertInitialLoad()

#### Returns

Task

### InsertUserOneAsync(User)

Inserts a new user into the MongoDB collection. This method takes a User object as input and attempts to insert it into the collection. If the insertion is successful, it returns true; otherwise, it logs the error and returns false.

    public Task<bool> InsertUserOneAsync(User user)

#### Parameters

`user` User

  The user object to insert into the collection.

#### Returns

Task<bool>

  True if the insertion is successful, false otherwise.

### UpdateOneUserAsync(ObjectId, User)

Updates an existing user in the MongoDB collection. This method takes an ObjectId representing the user's ID and a User object containing the updated information. It constructs a filter to find the user by ID and an update definition to set the new values for the user's properties. If the update is successful, it returns true; otherwise, it logs the error and returns false.

    public Task<bool> UpdateOneUserAsync(ObjectId id, User user)

#### Parameters

`id` ObjectId

  The unique identifier of the user to update.

`user` User

  The user object containing the updated information.

#### Returns

Task<bool>

  True if the update is successful, false otherwise.