Compare commits
2 commits
f5123f292a
...
96d211634d
Author | SHA1 | Date | |
---|---|---|---|
Laura Hausmann | 96d211634d | ||
Laura Hausmann | fbed02c12a |
|
@ -1,20 +1,20 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<TargetFramework>net70</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>
|
||||
|
|
|
@ -14,24 +14,9 @@ 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() {
|
||||
|
@ -52,6 +37,15 @@ 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"]);
|
||||
|
@ -62,6 +56,6 @@ public class EditMovie : PageModel {
|
|||
|
||||
db.Update(movie);
|
||||
|
||||
Response.Redirect("/Movies");
|
||||
Response.Redirect($"/Movies#movie_{movie.MovieId}");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,20 +7,37 @@ 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.Query.ContainsKey("action") && Request.Query["action"] == "autoinc") {
|
||||
|
||||
if (Request.Form["action"] == "delete") {
|
||||
db.Delete(show);
|
||||
Response.Redirect("/Shows");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Request.Form["action"] == "autoinc") {
|
||||
if (show.WatchStatus == WatchStatus.Finished) {
|
||||
Response.Redirect("/Shows");
|
||||
return;
|
||||
|
@ -39,46 +56,31 @@ public class EditShow : PageModel {
|
|||
};
|
||||
|
||||
db.Update(show);
|
||||
Response.Redirect("/Shows");
|
||||
}
|
||||
|
||||
if (Request.Query.ContainsKey("action") && Request.Query["action"] == "rewatch") {
|
||||
show.SeenEpisodes = 0;
|
||||
show.WatchStatus = WatchStatus.Rewatch;
|
||||
|
||||
db.Update(show);
|
||||
Response.Redirect("/Shows");
|
||||
}
|
||||
|
||||
if (Request.Query.ContainsKey("action") && Request.Query["action"] == "finish") {
|
||||
show.WatchStatus = WatchStatus.Finished;
|
||||
show.WatchCount++;
|
||||
db.Update(show);
|
||||
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("/");
|
||||
Response.Redirect($"/Shows#show_{show.ShowId}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Request.Form["action"] == "delete") {
|
||||
db.Delete(show);
|
||||
Response.Redirect("/Shows");
|
||||
if (Request.Form["action"] == "rewatch") {
|
||||
show.SeenEpisodes = 0;
|
||||
show.WatchStatus = WatchStatus.Rewatch;
|
||||
|
||||
db.Update(show);
|
||||
Response.Redirect($"/Shows#show_{show.ShowId}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Request.Form["action"] == "finish") {
|
||||
show.WatchStatus = WatchStatus.Finished;
|
||||
show.WatchCount++;
|
||||
db.Update(show);
|
||||
Response.Redirect($"/Shows#show_{show.ShowId}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Request.Form["action"] == "waiting") {
|
||||
show.WatchStatus = WatchStatus.Waiting;
|
||||
db.Update(show);
|
||||
Response.Redirect($"/Shows#show_{show.ShowId}");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -95,13 +97,11 @@ 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");
|
||||
Response.Redirect($"/Shows#show_{show.ShowId}");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
@page
|
||||
@inject IAntiforgery _antiforgery
|
||||
@using Microsoft.AspNetCore.Antiforgery
|
||||
@using MediaManager.database
|
||||
@model MediaManager.Pages.Movies
|
||||
@model Movies
|
||||
@{
|
||||
ViewData["Title"] = "Movies";
|
||||
Layout = "_LayoutNoContainer";
|
||||
var tokenSet = _antiforgery.GetAndStoreTokens(HttpContext);
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
|
@ -26,7 +29,7 @@
|
|||
</thead>
|
||||
<tbody>
|
||||
@foreach (var movie in new Database.DbConn().Movies.Where(p => p.UserId == Model.AuthorizedUser.UserId).OrderBy(p => p.Title.ToLower())) {
|
||||
<tr>
|
||||
<tr id="movie_@movie.MovieId">
|
||||
<td>
|
||||
<b>@movie.Title</b>
|
||||
<br/>
|
||||
|
@ -74,7 +77,7 @@
|
|||
</td>
|
||||
<td>
|
||||
<div class="btn-group" role="group">
|
||||
<a class="btn btn-sm btn-secondary" href="/EditMovie/@movie.MovieId?action=autoinc">W+1</a>
|
||||
<button class="btn btn-sm btn-secondary" onclick="ajax_and_reload('/EditMovie/@movie.MovieId', 'autoinc')">W+1</button>
|
||||
<a class="btn btn-sm btn-primary" href="/EditMovie/@movie.MovieId">Edit</a>
|
||||
</div>
|
||||
</td>
|
||||
|
@ -83,3 +86,15 @@
|
|||
</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>
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
@page
|
||||
@inject IAntiforgery _antiforgery
|
||||
@using Microsoft.AspNetCore.Antiforgery
|
||||
@using MediaManager.database
|
||||
@using MediaManager.database.Tables
|
||||
@model MediaManager.Pages.Shows
|
||||
@model Shows
|
||||
@{
|
||||
ViewData["Title"] = "Shows";
|
||||
Layout = "_LayoutNoContainer";
|
||||
var tokenSet = _antiforgery.GetAndStoreTokens(HttpContext);
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
|
@ -29,7 +32,7 @@
|
|||
</thead>
|
||||
<tbody>
|
||||
@foreach (var show in new Database.DbConn().Shows.Where(p => p.UserId == Model.AuthorizedUser.UserId).OrderBy(p => p.Title.ToLower())) {
|
||||
<tr>
|
||||
<tr id="show_@show.ShowId">
|
||||
<td>
|
||||
<b>@show.Title</b>
|
||||
<br/>
|
||||
|
@ -114,19 +117,19 @@
|
|||
<td>
|
||||
<div class="btn-group" role="group">
|
||||
@if (show.SeenEpisodes == show.TotalEpisodes && show.WatchStatus == WatchStatus.FirstWatch) {
|
||||
<a class="btn btn-sm btn-secondary" href="/EditShow/@show.ShowId?action=waiting">Waiting</a>
|
||||
<button class="btn btn-sm btn-secondary" onclick="ajax_and_reload('/EditShow/@show.ShowId', 'waiting')">Waiting</button>
|
||||
}
|
||||
@if (show.SeenEpisodes == show.TotalEpisodes && (show.WatchStatus == WatchStatus.FirstWatch || show.WatchStatus == WatchStatus.Rewatch)) {
|
||||
<a class="btn btn-sm btn-success" href="/EditShow/@show.ShowId?action=finish">Finish</a>
|
||||
<button class="btn btn-sm btn-success" onclick="ajax_and_reload('/EditShow/@show.ShowId', 'finish')">Finish</button>
|
||||
}
|
||||
@if (show.SeenEpisodes < show.TotalEpisodes && (show.WatchStatus == WatchStatus.Unwatched || show.WatchStatus == WatchStatus.FirstWatch || show.WatchStatus == WatchStatus.Rewatch)) {
|
||||
<a class="btn btn-sm btn-secondary" href="/EditShow/@show.ShowId?action=autoinc">W+1</a>
|
||||
<button class="btn btn-sm btn-secondary" onclick="ajax_and_reload('/EditShow/@show.ShowId', 'autoinc')">W+1</button>
|
||||
}
|
||||
else if (show.WatchStatus == WatchStatus.Finished) {
|
||||
<a class="btn btn-sm btn-success" href="/EditShow/@show.ShowId?action=rewatch">Start rewatch</a>
|
||||
<button class="btn btn-sm btn-success" onclick="ajax_and_reload('/EditShow/@show.ShowId', 'rewatch')">Start rewatch</button>
|
||||
}
|
||||
else if (show.WatchStatus == WatchStatus.Waiting) {
|
||||
<a class="btn btn-sm btn-secondary" href="/EditShow/@show.ShowId?action=autoinc">New episode</a>
|
||||
<button class="btn btn-sm btn-secondary" onclick="ajax_and_reload('/EditShow/@show.ShowId', 'autoinc')">New episode</button>
|
||||
}
|
||||
<a class="btn btn-sm btn-primary" href="/EditShow/@show.ShowId">Edit</a>
|
||||
</div>
|
||||
|
@ -136,3 +139,15 @@
|
|||
</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>
|
||||
|
|
Loading…
Reference in a new issue