First running edit version
This commit is contained in:
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Tv7Playlist.Core;
|
||||
using Tv7Playlist.Data;
|
||||
using Tv7Playlist.Models;
|
||||
|
||||
@@ -12,10 +13,12 @@ namespace Tv7Playlist.Controllers
|
||||
public class HomeController : Controller
|
||||
{
|
||||
private readonly PlaylistContext _playlistContext;
|
||||
private readonly IPlaylistSynchronizer _playlistSynchronizer;
|
||||
|
||||
public HomeController(PlaylistContext playlistContext)
|
||||
public HomeController(PlaylistContext playlistContext, IPlaylistSynchronizer playlistSynchronizer)
|
||||
{
|
||||
_playlistContext = playlistContext ?? throw new ArgumentNullException(nameof(playlistContext));
|
||||
_playlistSynchronizer = playlistSynchronizer ?? throw new ArgumentNullException(nameof(playlistSynchronizer));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@@ -35,5 +38,14 @@ namespace Tv7Playlist.Controllers
|
||||
|
||||
return View(errorViewModel);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("synchronize")]
|
||||
public async Task<IActionResult> Synchronize()
|
||||
{
|
||||
await _playlistSynchronizer.SynchronizeAsync();
|
||||
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
}
|
||||
}
|
@@ -16,13 +16,11 @@ namespace Tv7Playlist.Controllers
|
||||
private readonly ILogger<HomeController> _logger;
|
||||
|
||||
private readonly IPlaylistBuilder _playlistBuilder;
|
||||
private readonly IPlaylistSynchronizer _playlistSynchronizer;
|
||||
|
||||
public PlaylistApiController(ILogger<HomeController> logger, IPlaylistSynchronizer playlistSynchronizer,
|
||||
IPlaylistBuilder playlistBuilder, IAppConfig appConfig)
|
||||
{
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
_playlistSynchronizer = playlistSynchronizer ?? throw new ArgumentNullException(nameof(playlistSynchronizer));
|
||||
_playlistBuilder = playlistBuilder ?? throw new ArgumentNullException(nameof(playlistBuilder));
|
||||
_appConfig = appConfig ?? throw new ArgumentNullException(nameof(appConfig));
|
||||
}
|
||||
@@ -43,15 +41,6 @@ namespace Tv7Playlist.Controllers
|
||||
};
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("")]
|
||||
public async Task<IActionResult> Synchronize()
|
||||
{
|
||||
await _playlistSynchronizer.SynchronizeAsync();
|
||||
return Ok();
|
||||
}
|
||||
|
||||
|
||||
private string GetDownloadFileName()
|
||||
{
|
||||
var downloadFileName = _appConfig.DownloadFileName;
|
||||
|
58
Tv7Playlist/Controllers/PlaylistEntryController.cs
Normal file
58
Tv7Playlist/Controllers/PlaylistEntryController.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Tv7Playlist.Core;
|
||||
using Tv7Playlist.Data;
|
||||
using Tv7Playlist.Models;
|
||||
|
||||
namespace Tv7Playlist.Controllers
|
||||
{
|
||||
public class PlaylistEntryController : Controller
|
||||
{
|
||||
private readonly PlaylistContext _playlistContext;
|
||||
|
||||
public PlaylistEntryController(PlaylistContext playlistContext)
|
||||
{
|
||||
_playlistContext = playlistContext ?? throw new ArgumentNullException(nameof(playlistContext));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public async Task<IActionResult> Edit(Guid? id)
|
||||
{
|
||||
if (id == null) return NotFound();
|
||||
|
||||
var entry = await _playlistContext.PlaylistEntries.FindAsync(id);
|
||||
if (entry == null) return NotFound();
|
||||
|
||||
return View(entry);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public async Task<IActionResult> Edit(Guid id, PlaylistEntry updatedEntry)
|
||||
//[Bind("PlaylistEntry.Id,PlaylistEntry.Position,PlaylistEntry.TrackNumberOverride,PlaylistEntry.NameOverride,PlaylistEntry.IsEnabled")]
|
||||
{
|
||||
if (updatedEntry == null) return NotFound();
|
||||
|
||||
if (id != updatedEntry.Id) return NotFound();
|
||||
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
var entry = await _playlistContext.PlaylistEntries.FindAsync(id);
|
||||
if (entry == null) return NotFound();
|
||||
|
||||
entry.Position = updatedEntry.Position;
|
||||
entry.TrackNumberOverride = updatedEntry.TrackNumberOverride;
|
||||
entry.NameOverride = updatedEntry.NameOverride;
|
||||
entry.IsEnabled = updatedEntry.IsEnabled;
|
||||
|
||||
await _playlistContext.SaveChangesAsync();
|
||||
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
|
||||
return View(updatedEntry);
|
||||
}
|
||||
}
|
||||
}
|
14
Tv7Playlist/Models/PlaylistEntryEditViewModel.cs
Normal file
14
Tv7Playlist/Models/PlaylistEntryEditViewModel.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Tv7Playlist.Data;
|
||||
|
||||
namespace Tv7Playlist.Models
|
||||
{
|
||||
public class PlaylistEntryEditViewModel
|
||||
{
|
||||
public PlaylistEntryEditViewModel(PlaylistEntry playlistEntry)
|
||||
{
|
||||
PlaylistEntry = playlistEntry;
|
||||
}
|
||||
|
||||
public PlaylistEntry PlaylistEntry { get; }
|
||||
}
|
||||
}
|
@@ -2,10 +2,12 @@
|
||||
@{
|
||||
ViewData["Title"] = "TV7 Playlist";
|
||||
}
|
||||
|
||||
<div class="row">
|
||||
<div class="col col-12">
|
||||
<table class="table table-hover table-striped">
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>Number</th>
|
||||
<th>Number override</th>
|
||||
<th>Position</th>
|
||||
@@ -21,6 +23,7 @@
|
||||
foreach (var track in Model.PlaylistEntries)
|
||||
{
|
||||
<tr>
|
||||
<td><a class="btn btn-secondary" asp-area="" asp-controller="PlaylistEntry" asp-action="Edit" asp-route-id="@track.Id">Edit</a></td>
|
||||
<td>@track.TrackNumber</td>
|
||||
<td>@(track.TrackNumberOverride==0?string.Empty:track.TrackNumberOverride.ToString())</td>
|
||||
<td>@track.Position</td>
|
||||
|
103
Tv7Playlist/Views/PlaylistEntry/Edit.cshtml
Normal file
103
Tv7Playlist/Views/PlaylistEntry/Edit.cshtml
Normal file
@@ -0,0 +1,103 @@
|
||||
@model Tv7Playlist.Data.PlaylistEntry;
|
||||
@{
|
||||
ViewData["Title"] = "Edit Entry";
|
||||
}
|
||||
|
||||
<div class="row">
|
||||
<div class="col col-12">
|
||||
<h3>Edit channel @Model.TrackNumber - @Model.Name</h3>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr/>
|
||||
|
||||
|
||||
<form asp-action="Edit" class="">
|
||||
<input type="hidden" asp-for="Id"/>
|
||||
|
||||
<div class="form-group row">
|
||||
<div class="offset-sm-2 col-sm-2">
|
||||
<label asp-for="IsAvailable" class="control-label form-check-label">Available</label>
|
||||
</div>
|
||||
<div class="col-sm-1 form-check">
|
||||
<input asp-for="IsAvailable" class="form-control form-control-sm" readonly disabled="true"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<div class="offset-sm-2 col-sm-2">
|
||||
<label asp-for="UrlOriginal" class="control-label">Original URL</label>
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
<input asp-for="UrlOriginal" readonly class="form-control"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr/>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<div class="offset-sm-2 col-sm-2">
|
||||
<label asp-for="Position" class="control-label">Position:</label>
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
<input asp-for="Position" class="form-control"/>
|
||||
</div>
|
||||
<div class="col-sm-2">
|
||||
<span asp-validation-for="Position" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<div class="offset-sm-2 col-sm-2">
|
||||
<label asp-for="NameOverride" class="control-label">Name override:</label>
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
<input asp-for="NameOverride" class="form-control"/>
|
||||
</div>
|
||||
<div class="col-sm-2">
|
||||
<span asp-validation-for="NameOverride" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<div class="offset-sm-2 col-sm-2">
|
||||
<label asp-for="TrackNumberOverride" class="control-label">Track number override</label>
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
<input asp-for="TrackNumberOverride" class="form-control"/>
|
||||
</div>
|
||||
<div class="col-sm-2">
|
||||
<span asp-validation-for="TrackNumberOverride" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<div class="offset-sm-2 col-sm-2">
|
||||
<label asp-for="IsEnabled" class="control-label form-check-label">Enabled:</label>
|
||||
</div>
|
||||
<div class="col-sm-1 form-check">
|
||||
<input asp-for="IsEnabled" class="form-control form-control-sm"/>
|
||||
</div>
|
||||
<div class="col-sm-2">
|
||||
<span asp-validation-for="IsEnabled" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr/>
|
||||
|
||||
<div class="form-group row">
|
||||
<div class="col offset-sm-4 col-sm-4">
|
||||
<input type="submit" value="Save" class="btn btn-primary"/>
|
||||
<a asp-action="Index" asp-controller="Home" class="btn btn-secondary">Cancel</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@section Scripts {
|
||||
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
|
||||
}
|
@@ -14,6 +14,7 @@
|
||||
<link rel="stylesheet" href="~/css/site.css"/>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
||||
<div class="container">
|
||||
@@ -27,11 +28,13 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Synchronize">Synchronize playlist</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
</header>
|
||||
|
||||
<div class="container-fluid">
|
||||
|
Reference in New Issue
Block a user