diff --git a/Your New Favorite Poem/Pages/AddPoet.cshtml b/Your New Favorite Poem/Pages/AddPoet.cshtml index 549e1dc..13eb572 100644 --- a/Your New Favorite Poem/Pages/AddPoet.cshtml +++ b/Your New Favorite Poem/Pages/AddPoet.cshtml @@ -4,19 +4,31 @@ ViewData["Title"] = "Add a Poet"; } -
+
- - + +
-
- - +
+ +
+
+ + +
+
+ + +
+
+ + +
diff --git a/Your New Favorite Poem/Pages/AddPoet.cshtml.cs b/Your New Favorite Poem/Pages/AddPoet.cshtml.cs index f6a40d9..3fd3369 100644 --- a/Your New Favorite Poem/Pages/AddPoet.cshtml.cs +++ b/Your New Favorite Poem/Pages/AddPoet.cshtml.cs @@ -5,30 +5,64 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.Extensions.Logging; +using Renci.SshNet; using Your_New_Favorite_Poem.Database; using Your_New_Favorite_Poem.Models; namespace Your_New_Favorite_Poem.Pages +//This is not compiling in order to allow us to get the database working. We made an error on this page on purpose. { public class AddPoetModel : PageModel { + private readonly AuthorsDbContext _authorsDbContext; + private readonly ILogger _logger; + + public AddPoetModel(ILogger logger, AuthorsDbContext authorsDbContext) + { + _logger = logger; + _authorsDbContext = authorsDbContext; + + } + + public string SubmissionResult { get; private set; } = "Submit your poem above!"; - public async Task OnPostSubmit(string author, string poem, string poemName) + public async Task OnPostSubmit(string authorName, string poemUrl, string poemName, string bio, string pictureUrl, string pictureAltText ) { - var isValidUri = Uri.TryCreate(poem, UriKind.Absolute, out var poemUri); - if (!isValidUri || poemUri is null) + var isPoemUrlValid = Uri.TryCreate(poemUrl, UriKind.Absolute, out var poemUri); + var isPictureUrlValid = Uri.TryCreate(pictureUrl, UriKind.Absolute, out var pictureUri); + if (!isPoemUrlValid || poemUri is null) { - SubmissionResult = "Invalid URL"; + SubmissionResult = "Invalid Poem URL"; } - else + else if (!isPictureUrlValid || pictureUri is null) + { + SubmissionResult = "Invalid Picture URL"; + } else { try { - // await _poemDatabase.InsertData(new Poem(author, poemName, poemUri)); -#if RELEASE -#error "You big idiot." -#endif - throw new Exception("CODEPATH TEMPORARILY BROKEN; Please fix me"); + var givenAuthor = new Author + { + IsVerified = false, + PictureAltText = pictureAltText, + Bio = bio, + Name = authorName, + PictureURL = pictureUri, + Poems = new List + { + new Poem() + { + URL = poemUri, + Title = poemName, + IsVerified = false + } + } + + }; + + await _authorsDbContext.AddAsync(givenAuthor); + await _authorsDbContext.SaveChangesAsync(); + SubmissionResult = "We did it! Submission Accepted. Check back soon!"; } catch @@ -38,14 +72,6 @@ public async Task OnPostSubmit(string author, string poem, string poemName) } } - public AddPoetModel(ILogger logger, AuthorsDbContext authorsDbContext) - { - _logger = logger; - _authorsDbContext = authorsDbContext; - - } - 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 b416eed..99a9fcf 100644 --- a/Your New Favorite Poem/Pages/Index.cshtml +++ b/Your New Favorite Poem/Pages/Index.cshtml @@ -29,14 +29,14 @@ - @foreach (var author in @Model.AuthorsFromDatabase) + @foreach (var author in @Model.AuthorsFromDatabase.Where(x => x.IsVerified is true)) { //poems and links not displaying after reseeding database

@author.Name


    - @foreach (var poem in author.Poems) + @foreach (var poem in author.Poems.Where(x => x.IsVerified is true)) {
  • @poem.Title
  • diff --git a/Your New Favorite Poem/Pages/Poets.cshtml b/Your New Favorite Poem/Pages/Poets.cshtml index 9a04021..9106993 100644 --- a/Your New Favorite Poem/Pages/Poets.cshtml +++ b/Your New Favorite Poem/Pages/Poets.cshtml @@ -12,10 +12,10 @@