diff --git a/Migrations/20200915115113_InitialCreate.Designer.cs b/Migrations/20200917125618_InitialCreate.Designer.cs similarity index 90% rename from Migrations/20200915115113_InitialCreate.Designer.cs rename to Migrations/20200917125618_InitialCreate.Designer.cs index 95d8af2..c797f79 100644 --- a/Migrations/20200915115113_InitialCreate.Designer.cs +++ b/Migrations/20200917125618_InitialCreate.Designer.cs @@ -9,7 +9,7 @@ using Snootalogue.Data; namespace snootalogue.Migrations { [DbContext(typeof(SnootalogueContext))] - [Migration("20200915115113_InitialCreate")] + [Migration("20200917125618_InitialCreate")] partial class InitialCreate { protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -25,7 +25,7 @@ namespace snootalogue.Migrations .HasColumnType("INTEGER"); b.Property("Authors") - .HasColumnType("TEXT"); + .HasColumnType("jsonb"); b.Property("Category") .HasColumnType("TEXT"); @@ -39,6 +39,9 @@ namespace snootalogue.Migrations b.Property("Hash") .HasColumnType("TEXT"); + b.Property("Notes") + .HasColumnType("TEXT"); + b.Property("Read") .HasColumnType("INTEGER"); @@ -46,7 +49,7 @@ namespace snootalogue.Migrations .HasColumnType("INTEGER"); b.Property("Tags") - .HasColumnType("TEXT"); + .HasColumnType("jsonb"); b.Property("Title") .HasColumnType("TEXT"); diff --git a/Migrations/20200915115113_InitialCreate.cs b/Migrations/20200917125618_InitialCreate.cs similarity index 81% rename from Migrations/20200915115113_InitialCreate.cs rename to Migrations/20200917125618_InitialCreate.cs index 6e8fd93..22b2c65 100644 --- a/Migrations/20200915115113_InitialCreate.cs +++ b/Migrations/20200917125618_InitialCreate.cs @@ -17,11 +17,12 @@ namespace snootalogue.Migrations Hash = table.Column(nullable: true), Size = table.Column(nullable: false), Title = table.Column(nullable: true), - Authors = table.Column(nullable: true), + Authors = table.Column(type: "jsonb", nullable: true), Category = table.Column(nullable: true), DateAdded = table.Column(nullable: false), - Tags = table.Column(nullable: true), - Read = table.Column(nullable: false) + Tags = table.Column(type: "jsonb", nullable: true), + Read = table.Column(nullable: false), + Notes = table.Column(nullable: true) }, constraints: table => { diff --git a/Migrations/SnootalogueContextModelSnapshot.cs b/Migrations/SnootalogueContextModelSnapshot.cs index c78896e..d983f36 100644 --- a/Migrations/SnootalogueContextModelSnapshot.cs +++ b/Migrations/SnootalogueContextModelSnapshot.cs @@ -23,7 +23,7 @@ namespace snootalogue.Migrations .HasColumnType("INTEGER"); b.Property("Authors") - .HasColumnType("TEXT"); + .HasColumnType("jsonb"); b.Property("Category") .HasColumnType("TEXT"); @@ -37,6 +37,9 @@ namespace snootalogue.Migrations b.Property("Hash") .HasColumnType("TEXT"); + b.Property("Notes") + .HasColumnType("TEXT"); + b.Property("Read") .HasColumnType("INTEGER"); @@ -44,7 +47,7 @@ namespace snootalogue.Migrations .HasColumnType("INTEGER"); b.Property("Tags") - .HasColumnType("TEXT"); + .HasColumnType("jsonb"); b.Property("Title") .HasColumnType("TEXT"); diff --git a/Models/Document.cs b/Models/Document.cs index 722c491..493ba8a 100644 --- a/Models/Document.cs +++ b/Models/Document.cs @@ -15,10 +15,11 @@ namespace Snootalogue.Models { [UIHint("CommaSeparatedList")] public List Authors { get; set; } public string Category { get; set; } - [Display(Name = "Release Date")] + [Display(Name = "Date added")] public DateTime DateAdded { get; set; } [UIHint("CommaSeparatedList")] public List Tags { get; set; } public Boolean Read { get; set; } + public string Notes { get; set; } } } diff --git a/Pages/Documents/Edit.cshtml b/Pages/Documents/Edit.cshtml new file mode 100644 index 0000000..0f98120 --- /dev/null +++ b/Pages/Documents/Edit.cshtml @@ -0,0 +1,42 @@ +@page "{id:int}" +@model Snootalogue.Pages.Documents.EditModel +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers + +@{ + ViewData["Title"] = "Edit"; +} + +
+
+ + +
+ + +
+ +
+ + +
+ +
+ + @* *@ + @Html.TextAreaFor(model => model.ed.Notes) +
+ +
+ + +
+ +
+ +
+ Cancel +
+ +
+ +@* value="@Model.EditDocument.Title" *@ diff --git a/Pages/Documents/Edit.cshtml.cs b/Pages/Documents/Edit.cshtml.cs new file mode 100644 index 0000000..ed3b089 --- /dev/null +++ b/Pages/Documents/Edit.cshtml.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.EntityFrameworkCore; +using Snootalogue.Data; +using Snootalogue.Models; +using Snootalogue.ViewModels; + +namespace Snootalogue.Pages.Documents { + public class EditModel : PageModel { + private readonly SnootalogueContext _context; + [BindProperty] + public EditDocument ed { get; set; } + + public EditModel(SnootalogueContext context) { + _context = context; + } + + public async Task OnGetAsync(int? id) { + if (id == null) { + return NotFound(); + } + + var Document = await _context.Document.FirstOrDefaultAsync(d => d.ID == id); + + if (Document == null) { + return NotFound(); + } + + ed = new EditDocument { + ID = Document.ID, + Title = Document.Title, + Authors = Document.Authors, + Category = Document.Category, + Tags = Document.Tags, + Read = Document.Read + }; + + return Page(); + } + + public async Task OnPostAsync() { + if (!ModelState.IsValid) { + return Page(); + } + + Document d = _context.Document.First(d => d.ID == ed.ID); + d.Title = ed.Title; + d.Category = ed.Category; + d.Notes = ed.Notes; + d.Read = ed.Read; + + _context.Attach(d).State = EntityState.Modified; + + try { + await _context.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException e) { + // TODO: handle it like https://github.com/dotnet/AspNetCore.Docs/blob/master/aspnetcore/tutorials/razor-pages/razor-pages-start/sample/RazorPagesMovie30/Pages/Movies/Edit.cshtml.cs#L56 + throw e; + } + + return RedirectToPage("/Index"); + } + } +} diff --git a/Pages/Index.cshtml b/Pages/Index.cshtml index 67e8f24..54d7815 100644 --- a/Pages/Index.cshtml +++ b/Pages/Index.cshtml @@ -28,7 +28,7 @@ diff --git a/Pages/Shared/_Layout.cshtml b/Pages/Shared/_Layout.cshtml index c87eb01..4fe835c 100644 --- a/Pages/Shared/_Layout.cshtml +++ b/Pages/Shared/_Layout.cshtml @@ -10,7 +10,7 @@