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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user