Compare commits

..

No commits in common. "96d211634d2ec3bf0ee62dffdc835bd0d093d3d3" and "f5123f292a7e1c0679d2d8fc5bdc90fe2d60d2d8" have entirely different histories.

5 changed files with 70 additions and 94 deletions

View file

@ -1,20 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net70</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<Folder Include="database"/>
<Folder Include="database" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="linq2db" Version="4.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.8"/>
<PackageReference Include="Microsoft.Data.Sqlite" Version="6.0.8"/>
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.115"/>
<PackageReference Include="linq2db" Version="4.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.8" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="6.0.8" />
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.115" />
</ItemGroup>
</Project>

View file

@ -14,9 +14,24 @@ public class EditMovie : PageModel {
var movie = db.Movies.First(p => p.MovieId == movieId);
AuthorizedUser = db.Users.FirstOrDefault(p => p.Username == AuthUtil.GetRemoteUser(HttpContext, db))!;
if (movie.UserId != AuthorizedUser.UserId)
if (movie.UserId != AuthorizedUser.UserId) {
Response.Redirect("/");
return;
}
if (Request.Query.ContainsKey("action") && Request.Query["action"] == "autoinc") {
if (movie.UserId != AuthorizedUser.UserId) {
Response.Redirect("/");
return;
}
movie.WatchCount++;
movie.LastSeen = DateTime.Now;
db.Update(movie);
Response.Redirect("/Movies");
}
}
public void OnPost() {
@ -37,15 +52,6 @@ public class EditMovie : PageModel {
return;
}
if (Request.Form["action"] == "autoinc") {
movie.WatchCount++;
movie.LastSeen = DateTime.Now;
db.Update(movie);
Response.Redirect($"/Movies#movie_{movie.MovieId}");
return;
}
movie.Title = Request.Form["title"];
movie.Year = int.Parse(Request.Form["year"]);
movie.WatchCount = int.Parse(Request.Form["watchcount"]);
@ -56,6 +62,6 @@ public class EditMovie : PageModel {
db.Update(movie);
Response.Redirect($"/Movies#movie_{movie.MovieId}");
Response.Redirect("/Movies");
}
}

View file

@ -7,37 +7,20 @@ namespace MediaManager.Pages;
public class EditShow : PageModel {
public User AuthorizedUser;
public void OnGet() {
using var db = new Database.DbConn();
var showId = int.Parse(RouteData.Values["id"]!.ToString()!);
var show = db.Shows.First(p => p.ShowId == showId);
AuthorizedUser = db.Users.FirstOrDefault(p => p.Username == AuthUtil.GetRemoteUser(HttpContext, db))!;
if (show.UserId != AuthorizedUser.UserId)
Response.Redirect("/");
}
public void OnPost() {
using var db = new Database.DbConn();
var showId = int.Parse(RouteData.Values["id"]!.ToString()!);
var show = db.Shows.First(p => p.ShowId == showId);
AuthorizedUser = db.Users.FirstOrDefault(p => p.Username == AuthUtil.GetRemoteUser(HttpContext, db))!;
if (show.UserId != AuthorizedUser.UserId) {
Response.Redirect("/");
return;
}
if (Request.Form["action"] == "delete") {
db.Delete(show);
Response.Redirect("/Shows");
return;
}
if (Request.Form["action"] == "autoinc") {
if (Request.Query.ContainsKey("action") && Request.Query["action"] == "autoinc") {
if (show.WatchStatus == WatchStatus.Finished) {
Response.Redirect("/Shows");
return;
@ -56,31 +39,46 @@ public class EditShow : PageModel {
};
db.Update(show);
Response.Redirect($"/Shows#show_{show.ShowId}");
return;
Response.Redirect("/Shows");
}
if (Request.Form["action"] == "rewatch") {
if (Request.Query.ContainsKey("action") && Request.Query["action"] == "rewatch") {
show.SeenEpisodes = 0;
show.WatchStatus = WatchStatus.Rewatch;
db.Update(show);
Response.Redirect($"/Shows#show_{show.ShowId}");
return;
Response.Redirect("/Shows");
}
if (Request.Form["action"] == "finish") {
if (Request.Query.ContainsKey("action") && Request.Query["action"] == "finish") {
show.WatchStatus = WatchStatus.Finished;
show.WatchCount++;
db.Update(show);
Response.Redirect($"/Shows#show_{show.ShowId}");
Response.Redirect("/Shows");
}
if (Request.Query.ContainsKey("action") && Request.Query["action"] == "waiting") {
show.WatchStatus = WatchStatus.Waiting;
db.Update(show);
Response.Redirect("/Shows");
}
}
public void OnPost() {
using var db = new Database.DbConn();
var showId = int.Parse(RouteData.Values["id"]!.ToString()!);
var show = db.Shows.First(p => p.ShowId == showId);
AuthorizedUser = db.Users.FirstOrDefault(p => p.Username == AuthUtil.GetRemoteUser(HttpContext, db))!;
if (show.UserId != AuthorizedUser.UserId) {
Response.Redirect("/");
return;
}
if (Request.Form["action"] == "waiting") {
show.WatchStatus = WatchStatus.Waiting;
db.Update(show);
Response.Redirect($"/Shows#show_{show.ShowId}");
if (Request.Form["action"] == "delete") {
db.Delete(show);
Response.Redirect("/Shows");
return;
}
@ -97,11 +95,13 @@ public class EditShow : PageModel {
if (show.SeenEpisodes >= show.TotalEpisodes) {
show.SeenEpisodes = show.TotalEpisodes;
if (show.WatchStatus != WatchStatus.Waiting)
if (show.WatchStatus != WatchStatus.Waiting) {
show.WatchStatus = WatchStatus.Finished;
}
}
db.Update(show);
Response.Redirect($"/Shows#show_{show.ShowId}");
Response.Redirect("/Shows");
}
}

View file

@ -1,12 +1,9 @@
@page
@inject IAntiforgery _antiforgery
@using Microsoft.AspNetCore.Antiforgery
@using MediaManager.database
@model Movies
@model MediaManager.Pages.Movies
@{
ViewData["Title"] = "Movies";
Layout = "_LayoutNoContainer";
var tokenSet = _antiforgery.GetAndStoreTokens(HttpContext);
}
<div class="text-center">
@ -29,7 +26,7 @@
</thead>
<tbody>
@foreach (var movie in new Database.DbConn().Movies.Where(p => p.UserId == Model.AuthorizedUser.UserId).OrderBy(p => p.Title.ToLower())) {
<tr id="movie_@movie.MovieId">
<tr>
<td>
<b>@movie.Title</b>
<br/>
@ -77,7 +74,7 @@
</td>
<td>
<div class="btn-group" role="group">
<button class="btn btn-sm btn-secondary" onclick="ajax_and_reload('/EditMovie/@movie.MovieId', 'autoinc')">W+1</button>
<a class="btn btn-sm btn-secondary" href="/EditMovie/@movie.MovieId?action=autoinc">W+1</a>
<a class="btn btn-sm btn-primary" href="/EditMovie/@movie.MovieId">Edit</a>
</div>
</td>
@ -86,15 +83,3 @@
</tbody>
</table>
</div>
<script>
function ajax_and_reload(url, action, target, value) {
if (window.location.hash.length > 0){
window.location.replace("#");
if (typeof window.history.replaceState == 'function') {
history.replaceState({}, '', window.location.href.slice(0, -1));
}
}
$.ajax(url, {method: 'POST', data: {action: action, target: target, value: value, '__RequestVerificationToken' : '@tokenSet.RequestToken'}, success: function () { location.reload() }})
}
</script>

View file

@ -1,13 +1,10 @@
@page
@inject IAntiforgery _antiforgery
@using Microsoft.AspNetCore.Antiforgery
@using MediaManager.database
@using MediaManager.database.Tables
@model Shows
@model MediaManager.Pages.Shows
@{
ViewData["Title"] = "Shows";
Layout = "_LayoutNoContainer";
var tokenSet = _antiforgery.GetAndStoreTokens(HttpContext);
}
<div class="text-center">
@ -32,7 +29,7 @@
</thead>
<tbody>
@foreach (var show in new Database.DbConn().Shows.Where(p => p.UserId == Model.AuthorizedUser.UserId).OrderBy(p => p.Title.ToLower())) {
<tr id="show_@show.ShowId">
<tr>
<td>
<b>@show.Title</b>
<br/>
@ -117,19 +114,19 @@
<td>
<div class="btn-group" role="group">
@if (show.SeenEpisodes == show.TotalEpisodes && show.WatchStatus == WatchStatus.FirstWatch) {
<button class="btn btn-sm btn-secondary" onclick="ajax_and_reload('/EditShow/@show.ShowId', 'waiting')">Waiting</button>
<a class="btn btn-sm btn-secondary" href="/EditShow/@show.ShowId?action=waiting">Waiting</a>
}
@if (show.SeenEpisodes == show.TotalEpisodes && (show.WatchStatus == WatchStatus.FirstWatch || show.WatchStatus == WatchStatus.Rewatch)) {
<button class="btn btn-sm btn-success" onclick="ajax_and_reload('/EditShow/@show.ShowId', 'finish')">Finish</button>
<a class="btn btn-sm btn-success" href="/EditShow/@show.ShowId?action=finish">Finish</a>
}
@if (show.SeenEpisodes < show.TotalEpisodes && (show.WatchStatus == WatchStatus.Unwatched || show.WatchStatus == WatchStatus.FirstWatch || show.WatchStatus == WatchStatus.Rewatch)) {
<button class="btn btn-sm btn-secondary" onclick="ajax_and_reload('/EditShow/@show.ShowId', 'autoinc')">W+1</button>
<a class="btn btn-sm btn-secondary" href="/EditShow/@show.ShowId?action=autoinc">W+1</a>
}
else if (show.WatchStatus == WatchStatus.Finished) {
<button class="btn btn-sm btn-success" onclick="ajax_and_reload('/EditShow/@show.ShowId', 'rewatch')">Start rewatch</button>
<a class="btn btn-sm btn-success" href="/EditShow/@show.ShowId?action=rewatch">Start rewatch</a>
}
else if (show.WatchStatus == WatchStatus.Waiting) {
<button class="btn btn-sm btn-secondary" onclick="ajax_and_reload('/EditShow/@show.ShowId', 'autoinc')">New episode</button>
<a class="btn btn-sm btn-secondary" href="/EditShow/@show.ShowId?action=autoinc">New episode</a>
}
<a class="btn btn-sm btn-primary" href="/EditShow/@show.ShowId">Edit</a>
</div>
@ -139,15 +136,3 @@
</tbody>
</table>
</div>
<script>
function ajax_and_reload(url, action, target, value) {
if (window.location.hash.length > 0){
window.location.replace("#");
if (typeof window.history.replaceState == 'function') {
history.replaceState({}, '', window.location.href.slice(0, -1));
}
}
$.ajax(url, {method: 'POST', data: {action: action, target: target, value: value, '__RequestVerificationToken' : '@tokenSet.RequestToken'}, success: function () { location.reload() }})
}
</script>