-
Notifications
You must be signed in to change notification settings - Fork 0
Database
The database is an in-memory database. The reason I did this is because I wanted a simple connection for demonstration purposes. It makes the process easier for the person viewing the project. I did use Entity Framework Core 6 to connect to it, which can be easily detached and attached to a live database.
| File |
|---|
| ~\Staffify\Database\DatabaseContext.cs |
To setup the database, I created a Database Context based off of EFCore's DbContext. For the options, I configured the database name. From there I made the only "table" needed, Employees. This table is based off of the Employee Model.
// Build DB - Options
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
// Set DB name
optionsBuilder.UseInMemoryDatabase(databaseName: "StaffifyDB");
}
// Tables
public DbSet<Employee>? Employees { get; set; }| File |
|---|
| ~\Staffify\Database\IDatabase.cs |
I created this interface because there might be other tables that we need to connect to and do various operations. This interface defines the base operations for inheriting classes. As of right now, there are only the needed operations per the assessment. These operations are read and update.
| File |
|---|
| ~\Staffify\Database\Database.cs |
This is where I perform all of the database operations. First in the constructor I check to see if there is anything in the database. If there is nothing, I populate test data.
if (!_context.Employees.Any())
{
List<Employee> _employeesToAdd = new()
{
new Employee
{
EmployeeId = 1,
Name = "Jalen Hurts",
PhoneNumber = "(123) 456-7890",
EmailAddress = "jhurts@flyeaglesfly.com"
},
new Employee
{
EmployeeId = 11,
Name = "A.J. Brown",
PhoneNumber = "(123) 456-7891",
EmailAddress = "abrown@flyeaglesfly.com"
},
new Employee
{
EmployeeId = 6,
Name = "DeVonta Smith",
PhoneNumber = "(123) 456-7892",
EmailAddress = "dsmith@flyeaglesfly.com"
},
new Employee
{
EmployeeId = 91,
Name = "Fletcher Cox",
PhoneNumber = "(123) 456-7893",
EmailAddress = "fcox@flyeaglesfly.com"
}
};
_context.AddRange(_employeesToAdd);
_context.SaveChanges();
}From here, I implement the inherited methods from the interface using simple LINQ queries.
- π Home
- π’ Getting Started
- π About
- π Overview
- π₯οΈ Technologies
- π οΈ Builder
- π© Components
- πΎ Database
- π Overview
- π§ Setting Up
- π Interface
- βοΈ Class
- π Logging
- π Overview
- π Configuration
- π§βπ€βπ§ Models
- π Overview
- π§βπΌ Employee
- π AppSingletonData
- π Pages
- π Overview
- π Index
- π¨ββοΈ Employee Details
- π·ββοΈ About