#102: Moving Models and constants to their own library (#104)

* #102: Moving Models and constants to their own library

* #102: Updated sln file

* #102: Updated README to include step install migration tool
This commit was merged in pull request #104.
This commit is contained in:
KD
2024-08-05 20:05:57 -04:00
committed by GitHub
parent 8900afdfd2
commit a89580ac70
52 changed files with 53 additions and 25 deletions
+42
View File
@@ -0,0 +1,42 @@
using Microsoft.EntityFrameworkCore;
using Icarus.Models;
namespace Icarus.Database.Contexts;
public class UserContext : DbContext
{
public DbSet<User> Users { get; set; }
#region Constructors
public UserContext(DbContextOptions<UserContext> options) : base(options) { }
[ActivatorUtilitiesConstructor]
public UserContext(string connString) : base(new DbContextOptionsBuilder<UserContext>()
.UseMySQL(connString).Options)
{
}
#endregion
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<User>()
.ToTable("User");
modelBuilder.Entity<User>()
.Property(u => u.LastLogin).IsRequired(false);
modelBuilder.Entity<User>()
.Property(u => u.DateCreated).HasDefaultValue(DateTime.Now);
}
public User RetrieveRecord(User user)
{
return Users.FirstOrDefault(usr => usr.Id == user.Id)!;
}
public bool DoesRecordExist(User user)
{
return Users.FirstOrDefault(usr => usr.Id == user.Id) != null ? true : false;
}
}