From c0ac3cdd3085c51e8ca4dffc51b008dcee39f82c Mon Sep 17 00:00:00 2001 From: amazing-username Date: Sat, 11 May 2019 12:43:54 -0400 Subject: [PATCH] Changed the LastLogin property of the User model to allow null values, explcitly change the Entity User context to create a User table, and resolved bug that caused build issues in the SongController API class. The bug was caused by forgetting to change the type of the method after switching it from ActionResult to IActionResult. #40 --- Controllers/SongController.cs | 4 ++-- Models/Context/UserContext.cs | 25 +++++++++++++++---------- Models/User.cs | 2 +- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Controllers/SongController.cs b/Controllers/SongController.cs index 78f1dbf..61f2515 100644 --- a/Controllers/SongController.cs +++ b/Controllers/SongController.cs @@ -45,7 +45,7 @@ namespace Icarus.Controllers [HttpGet] [Authorize("read:song_details")] - public IActionResult> Get() + public IActionResult Get() { List songs = new List(); Console.WriteLine("Attemtping to retrieve songs"); @@ -68,7 +68,7 @@ namespace Icarus.Controllers } [HttpGet("{id}")] - public IActionResult Get(int id) + public IActionResult Get(int id) { MusicStoreContext context = HttpContext .RequestServices diff --git a/Models/Context/UserContext.cs b/Models/Context/UserContext.cs index 1f9513b..7f1d821 100644 --- a/Models/Context/UserContext.cs +++ b/Models/Context/UserContext.cs @@ -10,18 +10,23 @@ using Icarus.Models; namespace Icarus.Models.Context { - public class UserContext : DbContext - { - public DbSet Users { get; set; } + public class UserContext : DbContext + { + public DbSet Users { get; set; } public UserContext(DbContextOptions options) - : base(options) - { } + : base(options) + { } - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - modelBuilder.Entity(); - } - } + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity() + .ToTable("User"); + modelBuilder.Entity() + .Property(u => u.LastLogin).IsRequired(false); + modelBuilder.Entity() + .Property(u => u.DateCreated).HasDefaultValue(DateTime.Now); + } + } } diff --git a/Models/User.cs b/Models/User.cs index 568c0e4..3bfe261 100644 --- a/Models/User.cs +++ b/Models/User.cs @@ -27,6 +27,6 @@ namespace Icarus.Models [JsonProperty("date_created")] public DateTime DateCreated { get; set; } [JsonProperty("last_login")] - public DateTime LastLogin { get; set; } + public DateTime? LastLogin { get; set; } } }