Compare commits
No commits in common. "ed820f60fce9d1e196a60c05ca0b4636bafadd5f" and "8827adf860ef068c88083b31bc14622737ee65a5" have entirely different histories.
ed820f60fc
...
8827adf860
9 changed files with 11 additions and 175 deletions
|
@ -28,8 +28,6 @@
|
||||||
<dd>@Html.DisplayFor(model => model.Document.DateAdded)</dd>
|
<dd>@Html.DisplayFor(model => model.Document.DateAdded)</dd>
|
||||||
<dt>@Html.DisplayNameFor(model => model.Document.Tags)</dt>
|
<dt>@Html.DisplayNameFor(model => model.Document.Tags)</dt>
|
||||||
<dd class="tags">@Html.DisplayFor(model => model.Document.Tags)</dd>
|
<dd class="tags">@Html.DisplayFor(model => model.Document.Tags)</dd>
|
||||||
<dt>@Html.DisplayNameFor(model => model.Document.Notes)</dt>
|
|
||||||
<dd>@Html.DisplayFor(model => model.Document.Notes)</dd>
|
|
||||||
<dt>@Html.DisplayNameFor(model => model.Document.Read)</dt>
|
<dt>@Html.DisplayNameFor(model => model.Document.Read)</dt>
|
||||||
<dd>@Html.DisplayFor(model => model.Document.Read)</dd>
|
<dd>@Html.DisplayFor(model => model.Document.Read)</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||||
|
|
||||||
@{
|
@{
|
||||||
ViewData["Title"] = "Edit";
|
ViewData["Title"] = "Edit";
|
||||||
}
|
}
|
||||||
|
|
||||||
<form method="POST">
|
<form method="POST">
|
||||||
|
@ -15,23 +15,14 @@
|
||||||
<input asp-for="ed.Title" class="form-control"/>
|
<input asp-for="ed.Title" class="form-control"/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="ed.Authors" class="control-label"></label>
|
|
||||||
<input asp-for="ed.Authors" class="form-control"/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label asp-for="ed.Category" class="control-label"></label>
|
<label asp-for="ed.Category" class="control-label"></label>
|
||||||
<input asp-for="ed.Category" class="form-control"/>
|
<input asp-for="ed.Category" class="form-control"/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="ed.Tags" class="control-label"></label>
|
|
||||||
<input asp-for="ed.Tags" class="form-control"/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label asp-for="ed.Notes" class="control-label"></label>
|
<label asp-for="ed.Notes" class="control-label"></label>
|
||||||
|
@* <input asp-for="EditDocument.Notes" class="form-control"/> *@
|
||||||
@Html.TextAreaFor(model => model.ed.Notes)
|
@Html.TextAreaFor(model => model.ed.Notes)
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -31,9 +31,9 @@ namespace Snootalogue.Pages.Documents {
|
||||||
ed = new EditDocument {
|
ed = new EditDocument {
|
||||||
ID = Document.ID,
|
ID = Document.ID,
|
||||||
Title = Document.Title,
|
Title = Document.Title,
|
||||||
Authors = string.Join(",", Document.Authors),
|
Authors = Document.Authors,
|
||||||
Category = Document.Category,
|
Category = Document.Category,
|
||||||
Tags = Document.Tags == null ? "" : string.Join(",", Document.Tags),
|
Tags = Document.Tags,
|
||||||
Read = Document.Read
|
Read = Document.Read
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -47,9 +47,7 @@ namespace Snootalogue.Pages.Documents {
|
||||||
|
|
||||||
Document d = _context.Document.First(d => d.ID == ed.ID);
|
Document d = _context.Document.First(d => d.ID == ed.ID);
|
||||||
d.Title = ed.Title;
|
d.Title = ed.Title;
|
||||||
d.Authors = ed.Authors.Split(",").ToList<string>();
|
|
||||||
d.Category = ed.Category;
|
d.Category = ed.Category;
|
||||||
d.Tags = string.IsNullOrWhiteSpace(ed.Tags) ? null : ed.Tags.Split(",").ToList<string>();
|
|
||||||
d.Notes = ed.Notes;
|
d.Notes = ed.Notes;
|
||||||
d.Read = ed.Read;
|
d.Read = ed.Read;
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
<div class="authors">By @Html.DisplayFor(modelItem => item.Authors)</div>
|
<div class="authors">By @Html.DisplayFor(modelItem => item.Authors)</div>
|
||||||
<div class="category">Category: @Html.DisplayFor(modelItem => item.Category)</div>
|
<div class="category">Category: @Html.DisplayFor(modelItem => item.Category)</div>
|
||||||
<div class="tags">@Html.DisplayFor(modelItem => item.Tags)</div>
|
<div class="tags">@Html.DisplayFor(modelItem => item.Tags)</div>
|
||||||
@{string hash = item.Hash?.Substring(0, 8);}
|
@{string hash = item.Hash.Substring(0, 8);}
|
||||||
<div class="metadata">
|
<div class="metadata">
|
||||||
@Html.DisplayFor(modelItem => item.Filename) |
|
@Html.DisplayFor(modelItem => item.Filename) |
|
||||||
<span title="@item.Size bytes">@Html.DisplayFor(modelItem => item.Size)</span> |
|
<span title="@item.Size bytes">@Html.DisplayFor(modelItem => item.Size)</span> |
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
<!DOCTYPE html>
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
|
@ -15,7 +14,7 @@
|
||||||
<div id="nav-controls">
|
<div id="nav-controls">
|
||||||
<input id="nav-search" type="search" placeholder="Search...">
|
<input id="nav-search" type="search" placeholder="Search...">
|
||||||
<a class="button inverted" href="#">Help</a>
|
<a class="button inverted" href="#">Help</a>
|
||||||
<a class="button inverted" asp-page="/Upload">Upload</a>
|
<a class="button inverted" href="#">Upload</a>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
|
|
|
@ -1,55 +0,0 @@
|
||||||
@page
|
|
||||||
@model Snootalogue.Pages.UploadModel
|
|
||||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
|
||||||
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Upload";
|
|
||||||
}
|
|
||||||
|
|
||||||
<form asp-action="Upload" enctype="multipart/form-data">
|
|
||||||
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="ud.Title" class="control-label"></label>
|
|
||||||
<input asp-for="ud.Title" class="form-control" placeholder="Determine from file"/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="ud.Authors" class="control-label"></label>
|
|
||||||
<input asp-for="ud.Authors" class="form-control"/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="ud.Category" class="control-label"></label>
|
|
||||||
<input asp-for="ud.Category" class="form-control"/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="ud.Tags" class="control-label"></label>
|
|
||||||
<input asp-for="ud.Tags" class="form-control"/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="ud.Notes" class="control-label"></label>
|
|
||||||
@Html.TextAreaFor(model => model.ud.Notes)
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="ud.Read" class="control-label"></label>
|
|
||||||
<input asp-for="ud.Read" class="form-control"/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="ud.UploadedFile" class="control-label"></label>
|
|
||||||
<input asp-for="ud.UploadedFile" class="form-control" accept=".pdf,application/pdf"/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="centred">
|
|
||||||
<input type="submit" class="button block" value="Upload"/>
|
|
||||||
<br>
|
|
||||||
<a href="/" class="button block">Cancel</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</form>
|
|
||||||
|
|
||||||
@* value="@Model.EditDocument.Title" *@
|
|
|
@ -1,69 +0,0 @@
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
||||||
using Snootalogue.Data;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using System.Net;
|
|
||||||
using System.Linq;
|
|
||||||
using System.IO;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Snootalogue.ViewModels;
|
|
||||||
using Snootalogue.Models;
|
|
||||||
|
|
||||||
namespace Snootalogue.Pages {
|
|
||||||
public class UploadModel : PageModel {
|
|
||||||
private readonly SnootalogueContext _context;
|
|
||||||
[BindProperty]
|
|
||||||
public UploadDocument ud { get; set; }
|
|
||||||
|
|
||||||
public UploadModel(SnootalogueContext context) {
|
|
||||||
_context = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpPost]
|
|
||||||
// [DisableFormValueModelBinding]
|
|
||||||
// [ValidateAntiForgeryToken]
|
|
||||||
public async Task<IActionResult> OnPostAsync(UploadDocument ud) {
|
|
||||||
|
|
||||||
if (!ModelState.IsValid) {
|
|
||||||
return Page();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ud.UploadedFile == null) {
|
|
||||||
return Page();
|
|
||||||
}
|
|
||||||
|
|
||||||
var filename = WebUtility.HtmlEncode(ud.UploadedFile.FileName);
|
|
||||||
// var uploadDirectory = Path.Combine(filename);
|
|
||||||
var uploadDirectory = "wwwroot/Content";
|
|
||||||
var destination = Path.Combine(uploadDirectory, filename);
|
|
||||||
|
|
||||||
using (var fs = new FileStream(destination, FileMode.Create)) {
|
|
||||||
await ud.UploadedFile.CopyToAsync(fs);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Document d = _context.Document.
|
|
||||||
Document d = new Document {
|
|
||||||
Title = ud.Title,
|
|
||||||
Authors = ud.Authors.Split(",").ToList<string>(),
|
|
||||||
Category = ud.Category,
|
|
||||||
Tags = string.IsNullOrWhiteSpace(ud.Tags) ? null : ud.Tags.Split(",").ToList<string>(),
|
|
||||||
Notes = ud.Notes,
|
|
||||||
Read = ud.Read,
|
|
||||||
Filename = filename
|
|
||||||
};
|
|
||||||
|
|
||||||
_context.Document.Add(d);
|
|
||||||
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -10,13 +10,11 @@ namespace Snootalogue.ViewModels {
|
||||||
public int ID { get; set; }
|
public int ID { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
public string Title { get; set; }
|
public string Title { get; set; }
|
||||||
[Required]
|
[UIHint("CommaSeparatedList")]
|
||||||
[Display(Name = "Authors (comma separated)")]
|
public List<string> Authors { get; set; }
|
||||||
public string Authors { get; set; }
|
|
||||||
[Required]
|
|
||||||
public string Category { get; set; }
|
public string Category { get; set; }
|
||||||
[Display(Name = "Tags (comma separated)")]
|
[UIHint("CommaSeparatedList")]
|
||||||
public string Tags { get; set; }
|
public List<string> Tags { get; set; }
|
||||||
public Boolean Read { get; set; }
|
public Boolean Read { get; set; }
|
||||||
public string Notes { get; set; }
|
public string Notes { get; set; }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
|
|
||||||
// a version of the Document model designed for user editing
|
|
||||||
|
|
||||||
namespace Snootalogue.ViewModels {
|
|
||||||
public class UploadDocument {
|
|
||||||
[Required]
|
|
||||||
public string Title { get; set; }
|
|
||||||
[Required]
|
|
||||||
[Display(Name = "Authors (comma separated)")]
|
|
||||||
public string Authors { get; set; }
|
|
||||||
[Required]
|
|
||||||
public string Category { get; set; }
|
|
||||||
[Display(Name = "Tags (comma separated)")]
|
|
||||||
public string Tags { get; set; }
|
|
||||||
public Boolean Read { get; set; }
|
|
||||||
public string Notes { get; set; }
|
|
||||||
[Display(Name = "File to upload")]
|
|
||||||
public IFormFile UploadedFile { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue