WIP: adds first steps to use datatables for mass updates and search / sort

This commit is contained in:
2020-02-08 01:05:48 +01:00
parent d4badf7f9e
commit 796c5516f9
3 changed files with 66 additions and 41 deletions

View File

@@ -33,22 +33,6 @@ namespace Tv7Playlist.Controllers
return View(model);
}
[HttpPost]
public async Task<IActionResult> DisableSelectedEntries([FromForm] HomeModel model)
{
if (ModelState.IsValid) await UpdateEnabledForItems(model, false);
return Redirect("/");
}
[HttpPost]
public async Task<IActionResult> EnableSelectedEntries([FromForm] HomeModel model)
{
if (ModelState.IsValid) await UpdateEnabledForItems(model, true);
return Redirect("/");
}
[HttpGet]
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
@@ -75,19 +59,6 @@ namespace Tv7Playlist.Controllers
return RedirectToAction("Index", "Home");
}
private async Task UpdateEnabledForItems(HomeModel model, bool isEnabled)
{
if (model == null) throw new ArgumentNullException(nameof(model));
var idsToUpdate = model.PlaylistEntries.Where(e => e.Selected).Select(e => e.Id);
foreach (var id in idsToUpdate)
{
var entry = await _playlistContext.PlaylistEntries.FindAsync(id);
if (entry == null) continue;
entry.IsEnabled = isEnabled;
}
await _playlistContext.SaveChangesAsync();
}
}
}