From 3a7058d2c13d9b8a7ccc8f891171322ddd210eb2 Mon Sep 17 00:00:00 2001 From: Pj Metz <65838556+MetzinAround@users.noreply.github.com> Date: Sun, 8 Nov 2020 14:28:22 -0500 Subject: [PATCH 1/6] The Vague Beginnings of Author Database Table --- .../Database/AuthorDatabase.cs | 33 +++++++++++++++++++ Your New Favorite Poem/Models/Author.cs | 27 +++++++++++++++ Your New Favorite Poem/Models/Poem.cs | 2 +- 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 Your New Favorite Poem/Database/AuthorDatabase.cs create mode 100644 Your New Favorite Poem/Models/Author.cs diff --git a/Your New Favorite Poem/Database/AuthorDatabase.cs b/Your New Favorite Poem/Database/AuthorDatabase.cs new file mode 100644 index 0000000..944e6fe --- /dev/null +++ b/Your New Favorite Poem/Database/AuthorDatabase.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using Your_New_Favorite_Poem.Models; + +namespace Your_New_Favorite_Poem.Database +{ + public class AuthorDatabase : BaseDatabase + { + public override Task PatchData(Author data) + { + return PerformDatabaseFunction(patchPoemFunction); + + async Task patchPoemFunction(DatabaseContext dataContext) + { + var authorFromDatabase = await dataContext.Data.SingleAsync(y => y.Id.Equals(data.Id)).ConfigureAwait(false); + + authorFromDatabase.Name = data.Name; + authorFromDatabase.Bio = data.Bio; + authorFromDatabase.PictureURL = data.PictureURL; + authorFromDatabase.IsVerified = data.IsVerified; + authorFromDatabase.IsDeleted = data.IsDeleted; + authorFromDatabase.UpdatedAt = DateTimeOffset.UtcNow; + + dataContext.Update(authorFromDatabase); + + return authorFromDatabase; + } + } + } +} diff --git a/Your New Favorite Poem/Models/Author.cs b/Your New Favorite Poem/Models/Author.cs new file mode 100644 index 0000000..20a5722 --- /dev/null +++ b/Your New Favorite Poem/Models/Author.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Threading.Tasks; +using Your_New_Favorite_Poem.Constants; + +namespace Your_New_Favorite_Poem.Models +{ + [Table("authors")] + public class Author : IDatabaseModel + { + [Key, DatabaseGenerat‌ed(DatabaseGeneratedOp‌​tion.Identity)] + public Guid Id { get; set; } + public string Name { get; set; } = string.Empty; + public string Bio { get; set; } = string.Empty; + public List Poems { get; set; } = new List(); + public Uri? PictureURL { get; set; } + public bool IsDeleted { get; set; } + public DateTimeOffset CreatedAt { get; set; } + [DatabaseGenerat‌ed(DatabaseGeneratedOp‌​tion.Identity)] + public DateTimeOffset UpdatedAt { get; set; } + [DatabaseGenerat‌ed(DatabaseGeneratedOp‌​tion.Computed)] + public bool IsVerified { get; set; } + } +} diff --git a/Your New Favorite Poem/Models/Poem.cs b/Your New Favorite Poem/Models/Poem.cs index a8f63dc..0d98304 100644 --- a/Your New Favorite Poem/Models/Poem.cs +++ b/Your New Favorite Poem/Models/Poem.cs @@ -22,7 +22,7 @@ public Poem(string author, string title, Uri url) } [Key, DatabaseGenerat‌ed(DatabaseGeneratedOp‌​tion.Identity)] public Guid Id { get; set; } - public string Author { get; set; } + public Author Author { get; set; } public string Title { get; set; } public Uri URL { get; set; } public bool IsDeleted { get; set; } From 5d5eaddd798eecffab50e0067de99bede1390b5d Mon Sep 17 00:00:00 2001 From: Pj Metz <65838556+MetzinAround@users.noreply.github.com> Date: Sun, 15 Nov 2020 14:44:18 -0500 Subject: [PATCH 2/6] Successfully created Authors Database and replaced index with a single foreach loop. See above --- .../Constants/PoemsConstants.cs | 72 +++++++-- .../Database/BaseDatabase.cs | 8 +- Your New Favorite Poem/Models/Author.cs | 16 +- .../Models/IDatabaseModel.cs | 4 + Your New Favorite Poem/Models/Poem.cs | 16 +- .../Pages/AddPoet.cshtml.cs | 6 +- Your New Favorite Poem/Pages/Index.cshtml | 137 +++--------------- Your New Favorite Poem/Pages/Index.cshtml.cs | 22 ++- Your New Favorite Poem/Startup.cs | 1 + 9 files changed, 122 insertions(+), 160 deletions(-) diff --git a/Your New Favorite Poem/Constants/PoemsConstants.cs b/Your New Favorite Poem/Constants/PoemsConstants.cs index 417b96d..af0db45 100644 --- a/Your New Favorite Poem/Constants/PoemsConstants.cs +++ b/Your New Favorite Poem/Constants/PoemsConstants.cs @@ -8,22 +8,64 @@ namespace Your_New_Favorite_Poem.Constants { public static class PoemsConstants { - public static IReadOnlyList PoemList { get; } = new List + public static IReadOnlyList AuthorList { get; } = new List { - new Poem ("Ocean Vuong", "One Day I'll Love Ocean Vuong", new Uri ("https://www.poetryinvoice.com/poems/someday-ill-love-ocean-vuong")), - new Poem ( "Ocean Vuong", "Untitled (Blue, Green, & Brown)", new Uri ("https://www.triquarterly.org/issues/issue-146/untitled-blue-green-brown-oil-canvas-mark-rothko-1952")), - new Poem ( "Mary Oliver", "The Summer Day", new Uri ("https://wordsfortheyear.com/2015/06/21/the-summer-day-by-mary-oliver/")), - new Poem ( "Mary Oliver", "Wild Geese", new Uri ("http://www.phys.unm.edu/~tw/fas/yits/archive/oliver_wildgeese.html")), - new Poem ( "Layli Long Soldier", "38", new Uri ("https://onbeing.org/poetry/38/")), - new Poem ( "Layli Long Soldier", "Obligations 2", new Uri ("https://www.poetryfoundation.org/poems/149976/obligations-2")), - new Poem ( "Terrance Hayes", "I lock you in an American sonnet that is part prison", new Uri ("https://www.poetryfoundation.org/poetrymagazine/poems/143917/american-sonnet-for-my-past-and-future-assassin-598dc83c976f1")), - new Poem ( "Terrance Hayes", "Probably, Ghosts Are Allergic To Us. Our Uproarious", new Uri ("https://rhymings.com/terrance-hayes/probably-ghosts-are-allergic-to-us-our-uproarious/")), - new Poem ( "Shay Alexi", "John Mayer's 'Your Body is a Wonderland'is Kinda Gross But", new Uri ("http://www.glass-poetry.com/journal/2018/may/alexi-john.html")), - new Poem ( "Shay Alexi", "OUR MOTHER IS A NIGHTWITCH OR AN ODE TO FEMME FRIENDSHIP", new Uri ("https://tinderboxpoetry.com/our-mother-is-a-nightwitch-or-an-ode-to-femme-friendship")), - new Poem ( "Marci Calabretta Cancio-Bello", "In the Animal Garden of My Body", new Uri ("https://poets.org/poem/animal-garden-my-body")), - new Poem ( "Marci Calabretta Cancio-Bello", "Vase of Ashes", new Uri ("https://www.tupeloquarterly.com/vase-of-ashes-by-marci-calabretta-cancio-bello/")), - new Poem ( "Martín Espada", "Flowers and Bullets", new Uri ("https://poets.org/poem/flowers-and-bullets")), - new Poem ( "Martín Espada", "How We Could Have Lived or Died This Way", new Uri ("https://poets.org/poem/how-we-could-have-lived-or-died-way")) + new Author + { + Name = "Ocean Vuong", + IsVerified = true, + Bio = "Coming Soon", + PictureURL = new Uri("https://www.thenation.com/wp-content/uploads/2019/12/Ocean-Vuong-1-credit-Peter-Bienkowski.jpg"), + PictureAltText = "Picture of the poet Ocean Vuong. He is sitting and smiling in a blue sweater.", + Poems = new List + { + new Poem + { + Title = "One Day I'll Love Ocean Vuong", + URL = new Uri ("https://www.poetryinvoice.com/poems/someday-ill-love-ocean-vuong"), + IsVerified = true, + }, + new Poem + { + Title = "Untitled (Blue, Green, & Brown)", + URL = new Uri ("https://www.triquarterly.org/issues/issue-146/untitled-blue-green-brown-oil-canvas-mark-rothko-1952"), + IsVerified = true, + } + } + }, + new Author + { + Name = "Layli Long Soldier", + Bio = "Coming Soon", + IsVerified = true, + PictureURL = new Uri("https://upload.wikimedia.org/wikipedia/commons/thumb/d/d5/Layli_Long_Soldier_172902.jpg/330px-Layli_Long_Soldier_172902.jpg"), + PictureAltText = "Picure of the poet Layli Long Soldier. She is standing behind a podium in a black and white shawl giving a speech ", + Poems = new List + { + new Poem + { + Title = "38", + URL = new Uri ("https://onbeing.org/poetry/38/"), + IsVerified = true, + }, + new Poem + { + Title = "Obligations 2", + URL = new Uri ("https://www.poetryfoundation.org/poems/149976/obligations-2"), + IsVerified = true, + } + } + }, + //new Poem ( "Mary Oliver", "The Summer Day", new Uri ("https://wordsfortheyear.com/2015/06/21/the-summer-day-by-mary-oliver/")), + //new Poem ( "Mary Oliver", "Wild Geese", new Uri ("http://www.phys.unm.edu/~tw/fas/yits/archive/oliver_wildgeese.html")), + //new Poem ( "Terrance Hayes", "I lock you in an American sonnet that is part prison", new Uri ("https://www.poetryfoundation.org/poetrymagazine/poems/143917/american-sonnet-for-my-past-and-future-assassin-598dc83c976f1")), + //new Poem ( "Terrance Hayes", "Probably, Ghosts Are Allergic To Us. Our Uproarious", new Uri ("https://rhymings.com/terrance-hayes/probably-ghosts-are-allergic-to-us-our-uproarious/")), + //new Poem ( "Shay Alexi", "John Mayer's 'Your Body is a Wonderland'is Kinda Gross But", new Uri ("http://www.glass-poetry.com/journal/2018/may/alexi-john.html")), + //new Poem ( "Shay Alexi", "OUR MOTHER IS A NIGHTWITCH OR AN ODE TO FEMME FRIENDSHIP", new Uri ("https://tinderboxpoetry.com/our-mother-is-a-nightwitch-or-an-ode-to-femme-friendship")), + //new Poem ( "Marci Calabretta Cancio-Bello", "In the Animal Garden of My Body", new Uri ("https://poets.org/poem/animal-garden-my-body")), + //new Poem ( "Marci Calabretta Cancio-Bello", "Vase of Ashes", new Uri ("https://www.tupeloquarterly.com/vase-of-ashes-by-marci-calabretta-cancio-bello/")), + //new Poem ( "Martín Espada", "Flowers and Bullets", new Uri ("https://poets.org/poem/flowers-and-bullets")), + //new Poem ( "Martín Espada", "How We Could Have Lived or Died This Way", new Uri ("https://poets.org/poem/how-we-could-have-lived-or-died-way")) }; } diff --git a/Your New Favorite Poem/Database/BaseDatabase.cs b/Your New Favorite Poem/Database/BaseDatabase.cs index e3614f2..8ef33c8 100644 --- a/Your New Favorite Poem/Database/BaseDatabase.cs +++ b/Your New Favorite Poem/Database/BaseDatabase.cs @@ -128,7 +128,11 @@ protected class DatabaseContext : DbContext public DatabaseContext() { Database.EnsureCreated(); - + if(Data is DbSet authorDb && !authorDb.Any()) + { + authorDb.AddRange(PoemsConstants.AuthorList); + SaveChanges(); + } } public DbSet? Data { get; set; } @@ -137,7 +141,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity().Property(b => b.CreatedAt).HasDefaultValue(DateTimeOffset.UtcNow); modelBuilder.Entity().Property(b => b.UpdatedAt).HasDefaultValue(DateTimeOffset.UtcNow); - + } } } diff --git a/Your New Favorite Poem/Models/Author.cs b/Your New Favorite Poem/Models/Author.cs index 20a5722..c2a53a9 100644 --- a/Your New Favorite Poem/Models/Author.cs +++ b/Your New Favorite Poem/Models/Author.cs @@ -4,7 +4,7 @@ using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Threading.Tasks; -using Your_New_Favorite_Poem.Constants; + namespace Your_New_Favorite_Poem.Models { @@ -13,15 +13,25 @@ public class Author : IDatabaseModel { [Key, DatabaseGenerat‌ed(DatabaseGeneratedOp‌​tion.Identity)] public Guid Id { get; set; } + public string Name { get; set; } = string.Empty; + public string Bio { get; set; } = string.Empty; + public List Poems { get; set; } = new List(); + public Uri? PictureURL { get; set; } + + public string PictureAltText { get; set; } = string.Empty; + public bool IsDeleted { get; set; } - public DateTimeOffset CreatedAt { get; set; } + [DatabaseGenerat‌ed(DatabaseGeneratedOp‌​tion.Identity)] - public DateTimeOffset UpdatedAt { get; set; } + public DateTimeOffset CreatedAt { get; set; } + [DatabaseGenerat‌ed(DatabaseGeneratedOp‌​tion.Computed)] + public DateTimeOffset UpdatedAt { get; set; } + public bool IsVerified { get; set; } } } diff --git a/Your New Favorite Poem/Models/IDatabaseModel.cs b/Your New Favorite Poem/Models/IDatabaseModel.cs index 87fe0a6..bab04f6 100644 --- a/Your New Favorite Poem/Models/IDatabaseModel.cs +++ b/Your New Favorite Poem/Models/IDatabaseModel.cs @@ -9,9 +9,13 @@ namespace Your_New_Favorite_Poem.Models public interface IDatabaseModel { public Guid Id { get; set; } + public bool IsDeleted { get; set; } + public DateTimeOffset CreatedAt { get; set; } + public DateTimeOffset UpdatedAt { get; set; } + public bool IsVerified { get; set; } } } diff --git a/Your New Favorite Poem/Models/Poem.cs b/Your New Favorite Poem/Models/Poem.cs index 0d98304..33e06f3 100644 --- a/Your New Favorite Poem/Models/Poem.cs +++ b/Your New Favorite Poem/Models/Poem.cs @@ -14,22 +14,26 @@ public Poem() { } - public Poem(string author, string title, Uri url) - { - Author = author; - Title = title; - URL = url; - } + [Key, DatabaseGenerat‌ed(DatabaseGeneratedOp‌​tion.Identity)] public Guid Id { get; set; } + public Author Author { get; set; } + + public Guid AuthorId { get; set; } + public string Title { get; set; } + public Uri URL { get; set; } + public bool IsDeleted { get; set; } + [DatabaseGenerat‌ed(DatabaseGeneratedOp‌​tion.Identity)] public DateTimeOffset CreatedAt { get; set; } + [DatabaseGenerat‌ed(DatabaseGeneratedOp‌​tion.Computed)] public DateTimeOffset UpdatedAt { get; set; } + public bool IsVerified { get; set; } = false; } diff --git a/Your New Favorite Poem/Pages/AddPoet.cshtml.cs b/Your New Favorite Poem/Pages/AddPoet.cshtml.cs index 4eb532d..39e6ecd 100644 --- a/Your New Favorite Poem/Pages/AddPoet.cshtml.cs +++ b/Your New Favorite Poem/Pages/AddPoet.cshtml.cs @@ -24,7 +24,11 @@ public async Task OnPostSubmit(string author, string poem, string poemName) { try { - await _poemDatabase.InsertData(new Poem(author, poemName, poemUri)); + // await _poemDatabase.InsertData(new Poem(author, poemName, poemUri)); +#if RELEASE +#error "You big idiot." +#endif + throw new Exception("CODEPATH TEMPORARILY BROKEN; Please fix me"); SubmissionResult = "We did it! Submission Accepted. Check back soon!"; } catch diff --git a/Your New Favorite Poem/Pages/Index.cshtml b/Your New Favorite Poem/Pages/Index.cshtml index fdeee36..502e9c7 100644 --- a/Your New Favorite Poem/Pages/Index.cshtml +++ b/Your New Favorite Poem/Pages/Index.cshtml @@ -27,129 +27,26 @@ - -
-

Ocean Vuong Poems

-
-
    - @foreach (var poem in @Model.PoemsFromDatabase.Where(x => x.Author is "Ocean Vuong")) - { + -
  • @poem.Title
  • - } -
-
- - -
- -
- - -
- -

Layli Long Soldier

-
-
    - @foreach (var poem in @Model.PoemsFromDatabase.Where(x => x.Author is "Layli Long Soldier")) - { - -
  • @poem.Title
  • - } -
-
- -
- -
- - -
-

Mary Oliver

-
-
    - @foreach (var poem in @Model.PoemsFromDatabase.Where(x => x.Author is "Mary Oliver")) - { - -
  • @poem.Title
  • - } -
-
- -
- -
- - -
-

Terrance Hayes

-
-
    - @foreach (var poem in @Model.PoemsFromDatabase.Where(x => x.Author is "Terrance Hayes")) - { - -
  • @poem.Title
  • - } -
-
+ @foreach (var author in @Model.AuthorsFromDatabase) + { +
+

@author.Name Poems

+
+
    + @foreach (var poem in author.Poems) + { -
    - -
    - - -
    -

    Shay Alexi

    -
    -
      - @foreach (var poem in @Model.PoemsFromDatabase.Where(x => x.Author is "Shay Alexi")) - { - -
    • @poem.Title
    • - } -
    -
    - -
    - -
    - - -
    -

    Marci Calabretta Cancio-Bello

    -
    -
      - @foreach (var poem in @Model.PoemsFromDatabase.Where(x => x.Author is "Marci Calabretta Cancio-Bello")) - { - -
    • @poem.Title
    • - } -
    -
    - - -
    - -
    - - -
    -

    Martín Espada

    -
    -
      - @foreach (var poem in @Model.PoemsFromDatabase.Where(x => x.Author is "Martín Espada")) - { - -
    • @poem.Title
    • - } -
    -
    - - -
    - -
    +
  • @poem.Title
  • + } +
+
+
+ +
+ } \ No newline at end of file diff --git a/Your New Favorite Poem/Pages/Index.cshtml.cs b/Your New Favorite Poem/Pages/Index.cshtml.cs index 3543796..eca0338 100644 --- a/Your New Favorite Poem/Pages/Index.cshtml.cs +++ b/Your New Favorite Poem/Pages/Index.cshtml.cs @@ -1,12 +1,8 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.Extensions.Logging; -using Your_New_Favorite_Poem.Constants; using Your_New_Favorite_Poem.Database; using Your_New_Favorite_Poem.Models; @@ -14,26 +10,26 @@ namespace Your_New_Favorite_Poem.Pages { public class IndexModel : PageModel { - public IReadOnlyList PoemsFromDatabase { get; } + public IReadOnlyList AuthorsFromDatabase { get; } public string Home { get; set; } = "Home"; public IActionResult OnPostRandomPoem() { var rnd = new Random(); - var index = rnd.Next(0, PoemsFromDatabase.Count); + var index = rnd.Next(0, AuthorsFromDatabase.Count); - var randomPoem = PoemsFromDatabase[index]; - - return Redirect(randomPoem.URL.ToString()); + var randomAuthor = AuthorsFromDatabase[index]; + var poemIndex = rnd.Next(0, randomAuthor.Poems.Count); + return Redirect(randomAuthor.Poems[poemIndex].URL.ToString()); } private readonly ILogger _logger; - public IndexModel(ILogger logger, PoemDatabase poemDatabase) + public IndexModel(ILogger logger, AuthorDatabase authorDatabase) { _logger = logger; - _poemDatabase = poemDatabase; - PoemsFromDatabase = poemDatabase.GetAllData(); + _authorDatabase = authorDatabase; + AuthorsFromDatabase = authorDatabase.GetAllData(); } - private readonly PoemDatabase _poemDatabase; + private readonly AuthorDatabase _authorDatabase; } } diff --git a/Your New Favorite Poem/Startup.cs b/Your New Favorite Poem/Startup.cs index b86a1c1..51dc135 100644 --- a/Your New Favorite Poem/Startup.cs +++ b/Your New Favorite Poem/Startup.cs @@ -26,6 +26,7 @@ public void ConfigureServices(IServiceCollection services) { services.AddRazorPages(); services.AddSingleton(); + services.AddSingleton(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. From 2da201e525785805d42c4aa894023351ea99219d Mon Sep 17 00:00:00 2001 From: Pj Metz <65838556+MetzinAround@users.noreply.github.com> Date: Sun, 15 Nov 2020 23:31:05 -0500 Subject: [PATCH 3/6] Databse Seed complete / Random button not working and refresh page loses poems. --- .../Constants/PoemsConstants.cs | 137 ++++++++++++++++-- Your New Favorite Poem/Pages/Index.cshtml | 4 +- Your New Favorite Poem/Pages/Index.cshtml.cs | 2 +- 3 files changed, 130 insertions(+), 13 deletions(-) diff --git a/Your New Favorite Poem/Constants/PoemsConstants.cs b/Your New Favorite Poem/Constants/PoemsConstants.cs index af0db45..c5d4cbe 100644 --- a/Your New Favorite Poem/Constants/PoemsConstants.cs +++ b/Your New Favorite Poem/Constants/PoemsConstants.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Threading.Tasks; using Your_New_Favorite_Poem.Models; @@ -56,17 +57,133 @@ public static class PoemsConstants } } }, - //new Poem ( "Mary Oliver", "The Summer Day", new Uri ("https://wordsfortheyear.com/2015/06/21/the-summer-day-by-mary-oliver/")), - //new Poem ( "Mary Oliver", "Wild Geese", new Uri ("http://www.phys.unm.edu/~tw/fas/yits/archive/oliver_wildgeese.html")), - //new Poem ( "Terrance Hayes", "I lock you in an American sonnet that is part prison", new Uri ("https://www.poetryfoundation.org/poetrymagazine/poems/143917/american-sonnet-for-my-past-and-future-assassin-598dc83c976f1")), - //new Poem ( "Terrance Hayes", "Probably, Ghosts Are Allergic To Us. Our Uproarious", new Uri ("https://rhymings.com/terrance-hayes/probably-ghosts-are-allergic-to-us-our-uproarious/")), - //new Poem ( "Shay Alexi", "John Mayer's 'Your Body is a Wonderland'is Kinda Gross But", new Uri ("http://www.glass-poetry.com/journal/2018/may/alexi-john.html")), - //new Poem ( "Shay Alexi", "OUR MOTHER IS A NIGHTWITCH OR AN ODE TO FEMME FRIENDSHIP", new Uri ("https://tinderboxpoetry.com/our-mother-is-a-nightwitch-or-an-ode-to-femme-friendship")), - //new Poem ( "Marci Calabretta Cancio-Bello", "In the Animal Garden of My Body", new Uri ("https://poets.org/poem/animal-garden-my-body")), - //new Poem ( "Marci Calabretta Cancio-Bello", "Vase of Ashes", new Uri ("https://www.tupeloquarterly.com/vase-of-ashes-by-marci-calabretta-cancio-bello/")), - //new Poem ( "Martín Espada", "Flowers and Bullets", new Uri ("https://poets.org/poem/flowers-and-bullets")), - //new Poem ( "Martín Espada", "How We Could Have Lived or Died This Way", new Uri ("https://poets.org/poem/how-we-could-have-lived-or-died-way")) + new Author + { + Name = "Mary Oliver", + Bio = "Coming Soon", + IsVerified = true, + PictureURL = new Uri("https://media.newyorker.com/photos/5c4369fcaeb70d48728418ac/master/w_2560%2Cc_limit/Aizenman-MaryOliverTNY-1.jpg"), + PictureAltText = "A black and white photo of Mary Oliver. She is standing outside and looking to her left. ", + Poems = new List + { + new Poem + { + Title = "The Summer Day", + URL = new Uri ("https://wordsfortheyear.com/2015/06/21/the-summer-day-by-mary-oliver/"), + IsVerified = true, + }, + new Poem + { + Title = "Wild Geese", + URL = new Uri ("http://www.phys.unm.edu/~tw/fas/yits/archive/oliver_wildgeese.html"), + IsVerified = true + } + } + + }, + + new Author + { + Name = "Terrance Hayes", + Bio = "Coming Soon", + IsVerified = true, + PictureURL = new Uri("https://media.poetryfoundation.org/uploads/media/default/0001/19/198496b3f730c85668327e98d20f7bd9906064e2.jpeg?w=1274&h=&fit=max&1274"), + PictureAltText = " A black and white photo of Terrance Hayes' face. He is standing in the shadow of blinds, casting light across his face in stripes.", + Poems = new List + { + new Poem + { + Title = "I lock you in an American sonnet that is part prison", + URL = new Uri ("https://www.poetryfoundation.org/poetrymagazine/poems/143917/american-sonnet-for-my-past-and-future-assassin-598dc83c976f1"), + IsVerified = true + }, + new Poem + { + Title = "Probably, Ghosts Are Allergic To Us. Our Uproarious", + URL = new Uri("https://rhymings.com/terrance-hayes/probably-ghosts-are-allergic-to-us-our-uproarious/"), + IsVerified = true + } + } + + }, + + new Author + { + Name ="Shay Alexi", + Bio = "Coming Soon", + IsVerified = true, + PictureURL = new Uri("https://img.evbuc.com/https%3A%2F%2Fcdn.evbuc.com%2Fimages%2F58740676%2F139090090596%2F1%2Foriginal.20190318-174408?auto=compress&s=3d4ce76e5ea4d37b47e63a4524f585f3"), + PictureAltText = "Shay Alexi is standing and looking at the camera with one arm across their body and the other posing up towards their face.", + Poems = new List + { + new Poem + { + Title = "John Mayer's 'Your Body is a Wonderland'is Kinda Gross But", + URL = new Uri("http://www.glass-poetry.com/journal/2018/may/alexi-john.html"), + IsVerified = true + }, + + new Poem + { + Title = "OUR MOTHER IS A NIGHTWITCH OR AN ODE TO FEMME FRIENDSHIP", + URL = new Uri("https://tinderboxpoetry.com/our-mother-is-a-nightwitch-or-an-ode-to-femme-friendship"), + IsVerified = true + + } + } + + }, + + new Author + { + Name = "Marci Calabretta Cancio-Bello", + Bio = "Coming Soon", + IsVerified = true, + PictureURL = new Uri("https://149349728.v2.pressablecdn.com/wp-content/uploads/2019/03/Marci-Calabretta-Cancio-Bello-c-Margarita-Corporan-high-res-1-1024x998.jpg"), + PictureAltText = "Headshot of Marci Calabretta Cancio-Bello. She is standing outside and the background is blurry. She is smiling at the camera.", + Poems = new List + { + new Poem + { + Title = "In the Animal Garden of My Body", + URL = new Uri("https://poets.org/poem/animal-garden-my-body"), + IsVerified = true + }, + + new Poem + { + Title = "Vase of Ashes", + URL = new Uri("https://www.tupeloquarterly.com/vase-of-ashes-by-marci-calabretta-cancio-bello/"), + IsVerified = true + } + } + }, + + new Author + { + Name = "Martín Espada", + Bio = "Coming Soon", + IsVerified = true, + PictureURL = new Uri("https://onwisconsin.uwalumni.com/content/uploads/2010/02/Espada_Martin_port09_4056.jpg"), + PictureAltText = "Poet Martin Espada is lounging in a chair with one arm ofer the back. He is looking at the camera with a serious expression on his face.", + Poems = new List + { + new Poem + { + Title = "Flowers and Bullets", + URL = new Uri("https://poets.org/poem/flowers-and-bullets"), + IsVerified = true + }, + + new Poem + { + Title = "How We Could Have Lived or Died This Way", + URL = new Uri("https://poets.org/poem/how-we-could-have-lived-or-died-way"), + IsVerified = true, + } + } + } }; } } diff --git a/Your New Favorite Poem/Pages/Index.cshtml b/Your New Favorite Poem/Pages/Index.cshtml index 502e9c7..453c6e0 100644 --- a/Your New Favorite Poem/Pages/Index.cshtml +++ b/Your New Favorite Poem/Pages/Index.cshtml @@ -31,9 +31,9 @@ @foreach (var author in @Model.AuthorsFromDatabase) { - + //poems and links not displaying after reseeding database
-

@author.Name Poems

+

@author.Name


    @foreach (var poem in author.Poems) diff --git a/Your New Favorite Poem/Pages/Index.cshtml.cs b/Your New Favorite Poem/Pages/Index.cshtml.cs index eca0338..a9b45e2 100644 --- a/Your New Favorite Poem/Pages/Index.cshtml.cs +++ b/Your New Favorite Poem/Pages/Index.cshtml.cs @@ -14,7 +14,7 @@ public class IndexModel : PageModel public string Home { get; set; } = "Home"; public IActionResult OnPostRandomPoem() { - + //random button not working var rnd = new Random(); var index = rnd.Next(0, AuthorsFromDatabase.Count); From b10b1a88a7f28985ea0c2146af5f4c28f489873f Mon Sep 17 00:00:00 2001 From: Pj Metz <65838556+MetzinAround@users.noreply.github.com> Date: Sun, 6 Dec 2020 14:37:36 -0500 Subject: [PATCH 4/6] Fixed Bug where Poems were not showing up Poems were listed as "0", changed architecture and eventually fixed but oh man we really have no idea how. --- .../Database/AuthorDatabase.cs | 33 ---- .../Database/AuthorsDbContext.cs | 36 +++++ .../Database/BaseDatabase.cs | 148 ------------------ .../Database/DbInitializer.cs | 21 +++ .../Database/PoemDatabase.cs | 35 ----- Your New Favorite Poem/Models/Author.cs | 2 +- .../Models/IDatabaseModel.cs | 2 +- Your New Favorite Poem/Models/Poem.cs | 4 +- .../Pages/AddPoet.cshtml.cs | 6 +- Your New Favorite Poem/Pages/Index.cshtml | 2 +- Your New Favorite Poem/Pages/Index.cshtml.cs | 12 +- Your New Favorite Poem/Pages/Poets.cshtml.cs | 9 +- Your New Favorite Poem/Program.cs | 24 ++- Your New Favorite Poem/Startup.cs | 30 +++- 14 files changed, 128 insertions(+), 236 deletions(-) delete mode 100644 Your New Favorite Poem/Database/AuthorDatabase.cs create mode 100644 Your New Favorite Poem/Database/AuthorsDbContext.cs delete mode 100644 Your New Favorite Poem/Database/BaseDatabase.cs create mode 100644 Your New Favorite Poem/Database/DbInitializer.cs delete mode 100644 Your New Favorite Poem/Database/PoemDatabase.cs diff --git a/Your New Favorite Poem/Database/AuthorDatabase.cs b/Your New Favorite Poem/Database/AuthorDatabase.cs deleted file mode 100644 index 944e6fe..0000000 --- a/Your New Favorite Poem/Database/AuthorDatabase.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; -using Your_New_Favorite_Poem.Models; - -namespace Your_New_Favorite_Poem.Database -{ - public class AuthorDatabase : BaseDatabase - { - public override Task PatchData(Author data) - { - return PerformDatabaseFunction(patchPoemFunction); - - async Task patchPoemFunction(DatabaseContext dataContext) - { - var authorFromDatabase = await dataContext.Data.SingleAsync(y => y.Id.Equals(data.Id)).ConfigureAwait(false); - - authorFromDatabase.Name = data.Name; - authorFromDatabase.Bio = data.Bio; - authorFromDatabase.PictureURL = data.PictureURL; - authorFromDatabase.IsVerified = data.IsVerified; - authorFromDatabase.IsDeleted = data.IsDeleted; - authorFromDatabase.UpdatedAt = DateTimeOffset.UtcNow; - - dataContext.Update(authorFromDatabase); - - return authorFromDatabase; - } - } - } -} diff --git a/Your New Favorite Poem/Database/AuthorsDbContext.cs b/Your New Favorite Poem/Database/AuthorsDbContext.cs new file mode 100644 index 0000000..61e3c84 --- /dev/null +++ b/Your New Favorite Poem/Database/AuthorsDbContext.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using Your_New_Favorite_Poem.Constants; +using Your_New_Favorite_Poem.Models; + +namespace Your_New_Favorite_Poem +{ + public class AuthorsDbContext : DbContext + { + public AuthorsDbContext(DbContextOptions options) : base(options) + { + + } + + public DbSet? Authors { get; set; } + public DbSet? Poems { get; set; } + + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity().HasOne(p => p.Author).WithMany(b => b.Poems); + modelBuilder.Entity().Property(b => b.CreatedAt).HasDefaultValue(DateTimeOffset.UtcNow); + modelBuilder.Entity().Property(b => b.UpdatedAt).HasDefaultValue(DateTimeOffset.UtcNow); + modelBuilder.Entity().Property(b => b.CreatedAt).HasDefaultValue(DateTimeOffset.UtcNow); + modelBuilder.Entity().Property(b => b.UpdatedAt).HasDefaultValue(DateTimeOffset.UtcNow); + + } + + } + +} + diff --git a/Your New Favorite Poem/Database/BaseDatabase.cs b/Your New Favorite Poem/Database/BaseDatabase.cs deleted file mode 100644 index 8ef33c8..0000000 --- a/Your New Favorite Poem/Database/BaseDatabase.cs +++ /dev/null @@ -1,148 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text.RegularExpressions; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; -using Your_New_Favorite_Poem.Constants; -using Your_New_Favorite_Poem.Models; - -namespace Your_New_Favorite_Poem.Database -{ - public abstract class BaseDatabase where T : class, IDatabaseModel - { - readonly static string _connectionString = GetConnectionString(); - public abstract Task PatchData(T data); - public List GetAllData(Func wherePredicate) - { - using var connection = new DatabaseContext(); - - return connection.Data?.Where(wherePredicate).ToList() ?? new List(); - } - - public List GetAllData() => GetAllData(x => true); - - public Task GetData(string id) - { - return PerformDatabaseFunction(getDataFunction); - - Task getDataFunction(DatabaseContext dataContext) => dataContext.Data.SingleAsync(x => x.Id.Equals(id)); - } - - public Task InsertData(T data) - { - return PerformDatabaseFunction(insertDataFunction); - - async Task insertDataFunction(DatabaseContext dataContext) - { - data.Id = Guid.NewGuid(); - - data.CreatedAt = DateTimeOffset.UtcNow; - data.UpdatedAt = DateTimeOffset.UtcNow; - - await dataContext.AddAsync(data).ConfigureAwait(false); - - return data; - } - } - - - - public Task DeleteData(string id) - { - return PerformDatabaseFunction(deleteDataFunction); - - async Task deleteDataFunction(DatabaseContext dataContext) - { - var dataFromDatabase = await dataContext.Data.SingleAsync(y => y.Id.Equals(id)).ConfigureAwait(false); - - dataFromDatabase.IsDeleted = true; - - return await PatchData(dataFromDatabase).ConfigureAwait(false); - } - } - - public Task RemoveData(string id) - { - return PerformDatabaseFunction(removeDataDatabaseFunction); - - async Task removeDataDatabaseFunction(DatabaseContext dataContext) - { - var dataFromDatabase = await dataContext.Data.SingleAsync(x => x.Id.Equals(id)).ConfigureAwait(false); - - dataContext.Remove(dataFromDatabase); - - return dataFromDatabase; - } - } - - protected static async Task PerformDatabaseFunction(Func> databaseFunction) where TResult : class - { - using var connection = new DatabaseContext(); - - try - { - var result = await databaseFunction.Invoke(connection).ConfigureAwait(false); - await connection.SaveChangesAsync().ConfigureAwait(false); - - return result; - } - catch (Exception e) - { - Debug.WriteLine(""); - Debug.WriteLine(e.Message); - Debug.WriteLine(e.ToString()); - Debug.WriteLine(""); - - throw; - } - } - - //https://stackoverflow.com/a/43740589/13741035 - static string GetConnectionString() - { - var connectionStringFromEnvironmentVariable = Environment.GetEnvironmentVariable("MYSQLCONNSTR_localdb") ?? string.Empty; - var connArray = Regex.Split(connectionStringFromEnvironmentVariable, ";"); - - var connectionstring = string.Empty; - for (int i = 0; i < connArray.Length; i++) - { - - if (i is 1) - { - string[] datasource = Regex.Split(connArray[i], ":"); - connectionstring += datasource[0] + string.Format(";port={0};", datasource[1]); - } - else - { - connectionstring += connArray[i] + ";"; - } - } - - return connectionstring; - } - - protected class DatabaseContext : DbContext - { - public DatabaseContext() - { - Database.EnsureCreated(); - if(Data is DbSet authorDb && !authorDb.Any()) - { - authorDb.AddRange(PoemsConstants.AuthorList); - SaveChanges(); - } - } - public DbSet? Data { get; set; } - - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) => optionsBuilder.UseMySQL(_connectionString); - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - modelBuilder.Entity().Property(b => b.CreatedAt).HasDefaultValue(DateTimeOffset.UtcNow); - modelBuilder.Entity().Property(b => b.UpdatedAt).HasDefaultValue(DateTimeOffset.UtcNow); - - } - } - } -} \ No newline at end of file diff --git a/Your New Favorite Poem/Database/DbInitializer.cs b/Your New Favorite Poem/Database/DbInitializer.cs new file mode 100644 index 0000000..7732f48 --- /dev/null +++ b/Your New Favorite Poem/Database/DbInitializer.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Your_New_Favorite_Poem.Constants; + +namespace Your_New_Favorite_Poem.Database +{ + public static class DbInitializer + { + public static void Initialize(AuthorsDbContext authorsDbContext) + { + authorsDbContext.Database.EnsureCreated(); + if (authorsDbContext.Authors != null && !authorsDbContext.Authors.Any()) + { + authorsDbContext.Authors.AddRange(PoemsConstants.AuthorList); + authorsDbContext.SaveChanges(); + } + } + } +} diff --git a/Your New Favorite Poem/Database/PoemDatabase.cs b/Your New Favorite Poem/Database/PoemDatabase.cs deleted file mode 100644 index df19f60..0000000 --- a/Your New Favorite Poem/Database/PoemDatabase.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; -using Your_New_Favorite_Poem.Database; -using Your_New_Favorite_Poem.Models; - -namespace Your_New_Favorite_Poem.Database -{ - public class PoemDatabase : BaseDatabase - { - public override Task PatchData(Poem data) - { - return PerformDatabaseFunction(patchPoemFunction); - - async Task patchPoemFunction(DatabaseContext dataContext) - { - var poemFromDatabase = await dataContext.Data.SingleAsync(y => y.Id.Equals(data.Id)).ConfigureAwait(false); - - poemFromDatabase.Author = data.Author; - poemFromDatabase.Title = data.Title; - poemFromDatabase.URL = data.URL; - poemFromDatabase.IsVerified = data.IsVerified; - poemFromDatabase.IsDeleted = data.IsDeleted; - poemFromDatabase.UpdatedAt = DateTimeOffset.UtcNow; - - dataContext.Update(poemFromDatabase); - - return poemFromDatabase; - } - } - } -} - diff --git a/Your New Favorite Poem/Models/Author.cs b/Your New Favorite Poem/Models/Author.cs index c2a53a9..6521662 100644 --- a/Your New Favorite Poem/Models/Author.cs +++ b/Your New Favorite Poem/Models/Author.cs @@ -12,7 +12,7 @@ namespace Your_New_Favorite_Poem.Models public class Author : IDatabaseModel { [Key, DatabaseGenerat‌ed(DatabaseGeneratedOp‌​tion.Identity)] - public Guid Id { get; set; } + public int Id { get; set; } public string Name { get; set; } = string.Empty; diff --git a/Your New Favorite Poem/Models/IDatabaseModel.cs b/Your New Favorite Poem/Models/IDatabaseModel.cs index bab04f6..886e39f 100644 --- a/Your New Favorite Poem/Models/IDatabaseModel.cs +++ b/Your New Favorite Poem/Models/IDatabaseModel.cs @@ -8,7 +8,7 @@ namespace Your_New_Favorite_Poem.Models //Interface to force classes to include properties needed in database public interface IDatabaseModel { - public Guid Id { get; set; } + public int Id { get; set; } public bool IsDeleted { get; set; } diff --git a/Your New Favorite Poem/Models/Poem.cs b/Your New Favorite Poem/Models/Poem.cs index 33e06f3..4d2ff77 100644 --- a/Your New Favorite Poem/Models/Poem.cs +++ b/Your New Favorite Poem/Models/Poem.cs @@ -16,12 +16,10 @@ public Poem() } [Key, DatabaseGenerat‌ed(DatabaseGeneratedOp‌​tion.Identity)] - public Guid Id { get; set; } + public int Id { get; set; } public Author Author { get; set; } - public Guid AuthorId { get; set; } - public string Title { get; set; } public Uri URL { get; set; } diff --git a/Your New Favorite Poem/Pages/AddPoet.cshtml.cs b/Your New Favorite Poem/Pages/AddPoet.cshtml.cs index 39e6ecd..f6a40d9 100644 --- a/Your New Favorite Poem/Pages/AddPoet.cshtml.cs +++ b/Your New Favorite Poem/Pages/AddPoet.cshtml.cs @@ -38,13 +38,13 @@ public async Task OnPostSubmit(string author, string poem, string poemName) } } - public AddPoetModel(ILogger logger, PoemDatabase poemDatabase) + public AddPoetModel(ILogger logger, AuthorsDbContext authorsDbContext) { _logger = logger; - _poemDatabase = poemDatabase; + _authorsDbContext = authorsDbContext; } - private readonly PoemDatabase _poemDatabase; + private readonly AuthorsDbContext _authorsDbContext; private readonly ILogger _logger; public void OnGet() { diff --git a/Your New Favorite Poem/Pages/Index.cshtml b/Your New Favorite Poem/Pages/Index.cshtml index 453c6e0..b416eed 100644 --- a/Your New Favorite Poem/Pages/Index.cshtml +++ b/Your New Favorite Poem/Pages/Index.cshtml @@ -30,7 +30,7 @@ @foreach (var author in @Model.AuthorsFromDatabase) - { + { //poems and links not displaying after reseeding database

    @author.Name

    diff --git a/Your New Favorite Poem/Pages/Index.cshtml.cs b/Your New Favorite Poem/Pages/Index.cshtml.cs index a9b45e2..e25ae4c 100644 --- a/Your New Favorite Poem/Pages/Index.cshtml.cs +++ b/Your New Favorite Poem/Pages/Index.cshtml.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; +using System.Linq; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.Extensions.Logging; +using Your_New_Favorite_Poem.Constants; using Your_New_Favorite_Poem.Database; using Your_New_Favorite_Poem.Models; @@ -24,12 +26,14 @@ public IActionResult OnPostRandomPoem() } private readonly ILogger _logger; - public IndexModel(ILogger logger, AuthorDatabase authorDatabase) + public IndexModel(ILogger logger, AuthorsDbContext authorsDbContext) { _logger = logger; - _authorDatabase = authorDatabase; - AuthorsFromDatabase = authorDatabase.GetAllData(); + _authorsDbContext = authorsDbContext; + var temp = authorsDbContext.Poems.ToList(); + AuthorsFromDatabase = authorsDbContext.Authors.ToList(); + } - private readonly AuthorDatabase _authorDatabase; + private readonly AuthorsDbContext _authorsDbContext; } } diff --git a/Your New Favorite Poem/Pages/Poets.cshtml.cs b/Your New Favorite Poem/Pages/Poets.cshtml.cs index daa69df..8140a26 100644 --- a/Your New Favorite Poem/Pages/Poets.cshtml.cs +++ b/Your New Favorite Poem/Pages/Poets.cshtml.cs @@ -4,6 +4,7 @@ using Your_New_Favorite_Poem.Models; using System.Collections.Generic; using System; +using System.Linq; namespace Your_New_Favorite_Poem.Pages { @@ -11,12 +12,12 @@ namespace Your_New_Favorite_Poem.Pages public class PoetsModel : PageModel { public IReadOnlyList PoemsFromDatabase { get; } - readonly PoemDatabase _poemDatabase; - public PoetsModel(ILogger logger, PoemDatabase poemDatabase) + readonly AuthorsDbContext _authorsDbContext; + public PoetsModel(ILogger logger, AuthorsDbContext authorsDbContext) { Logger = logger; - _poemDatabase = poemDatabase; - PoemsFromDatabase = poemDatabase.GetAllData(); + _authorsDbContext = authorsDbContext; + PoemsFromDatabase = authorsDbContext.Poems.ToList(); } diff --git a/Your New Favorite Poem/Program.cs b/Your New Favorite Poem/Program.cs index 67d398e..67b9736 100644 --- a/Your New Favorite Poem/Program.cs +++ b/Your New Favorite Poem/Program.cs @@ -4,8 +4,10 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; +using Your_New_Favorite_Poem.Database; namespace Your_New_Favorite_Poem { @@ -13,7 +15,9 @@ public class Program { public static void Main(string[] args) { - CreateHostBuilder(args).Build().Run(); + var host = CreateHostBuilder(args).Build(); + CreateDbIfNotExists(host); + host.Run(); } public static IHostBuilder CreateHostBuilder(string[] args) => @@ -22,5 +26,23 @@ public static IHostBuilder CreateHostBuilder(string[] args) => { webBuilder.UseStartup(); }); + private static void CreateDbIfNotExists(IHost host) + { + using (var scope = host.Services.CreateScope()) + { + var services = scope.ServiceProvider; + try + { + var context = services.GetRequiredService(); + DbInitializer.Initialize(context); + } + catch (Exception ex) + { + var logger = services.GetRequiredService>(); + logger.LogError(ex, "An error occurred creating the DB."); + } + } + } } + } diff --git a/Your New Favorite Poem/Startup.cs b/Your New Favorite Poem/Startup.cs index 51dc135..5883d06 100644 --- a/Your New Favorite Poem/Startup.cs +++ b/Your New Favorite Poem/Startup.cs @@ -1,10 +1,12 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text.RegularExpressions; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.HttpsPolicy; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -25,8 +27,9 @@ public Startup(IConfiguration configuration) public void ConfigureServices(IServiceCollection services) { services.AddRazorPages(); - services.AddSingleton(); - services.AddSingleton(); + services.AddDbContext(options => options.UseMySQL(GetConnectionString())); + + } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. @@ -55,5 +58,28 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) endpoints.MapRazorPages(); }); } + //https://stackoverflow.com/a/43740589/13741035 + static string GetConnectionString() + { + var connectionStringFromEnvironmentVariable = Environment.GetEnvironmentVariable("MYSQLCONNSTR_localdb") ?? string.Empty; + var connArray = Regex.Split(connectionStringFromEnvironmentVariable, ";"); + + var connectionstring = string.Empty; + for (int i = 0; i < connArray.Length; i++) + { + + if (i is 1) + { + string[] datasource = Regex.Split(connArray[i], ":"); + connectionstring += datasource[0] + string.Format(";port={0};", datasource[1]); + } + else + { + connectionstring += connArray[i] + ";"; + } + } + + return connectionstring; + } } } From 74a474f5b422c2b18fc4214fca73b230cbab9223 Mon Sep 17 00:00:00 2001 From: Pj Metz <65838556+MetzinAround@users.noreply.github.com> Date: Sun, 20 Dec 2020 12:36:40 -0500 Subject: [PATCH 5/6] Fixed Poets page Bug Bug kept Authors from being listed on page. --- Your New Favorite Poem/Pages/Poets.cshtml | 2 +- Your New Favorite Poem/Pages/Poets.cshtml.cs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Your New Favorite Poem/Pages/Poets.cshtml b/Your New Favorite Poem/Pages/Poets.cshtml index 8a30bf3..9a04021 100644 --- a/Your New Favorite Poem/Pages/Poets.cshtml +++ b/Your New Favorite Poem/Pages/Poets.cshtml @@ -12,7 +12,7 @@