JXMovies/CMS/JXCMS.CMS.Movie/Admin/Controllers/CollectionController.cs

93 lines
3.3 KiB
C#
Raw Normal View History

2020-02-12 15:23:34 +08:00
using System.Collections.ObjectModel;
2020-02-10 22:30:27 +08:00
using System.Linq;
2020-02-09 19:10:05 +08:00
using JXCMS.CMS.Attribute;
using JXCMS.CMS.Movie.Entity;
2020-02-12 15:23:34 +08:00
using JXCMS.CMS.Movie.Jobs;
using JXCMS.Core.TimingTask;
2020-02-09 19:10:05 +08:00
using Microsoft.AspNetCore.Mvc;
2020-02-12 15:23:34 +08:00
using Quartz;
2020-02-09 19:10:05 +08:00
2020-02-12 15:23:34 +08:00
namespace JXCMS.CMS.Movie.Admin.Controllers
2020-02-09 19:10:05 +08:00
{
[Area("Admin")]
[AdminAuthentication]
public class CollectionController : Controller
{
2020-02-10 22:30:27 +08:00
public IActionResult Index(int pageNumber = 1, int pageSize = 20)
2020-02-09 19:10:05 +08:00
{
ViewBag.title = "采集地址";
2020-02-10 22:30:27 +08:00
var website = WebSiteEntity.Select.Count(out long count).Page(pageNumber, pageSize).ToList();
2020-02-09 19:10:05 +08:00
ViewBag.website = website;
2020-02-10 22:30:27 +08:00
ViewBag.count = count;
ViewBag.pageNumber = pageNumber;
ViewBag.totlePage = count % pageSize == 0 ? count / pageSize : count / pageSize + 1;
2020-02-09 19:10:05 +08:00
return View();
}
[HttpPost]
public IActionResult AddWebSite(WebSiteEntity webSiteEntity)
{
webSiteEntity.Save();
2020-02-12 15:23:34 +08:00
if (webSiteEntity.IsEnable)
{
QuartzTask.Instance().AddTask(typeof(CollectionJob), webSiteEntity.Cron, webSiteEntity.Id.ToString(), "default", ("id", webSiteEntity.Id));
}
2020-02-09 19:10:05 +08:00
return Redirect(Url.Action("Index"));
}
2020-02-09 22:43:16 +08:00
public IActionResult DeleteWebSite(int id)
{
2020-02-10 22:30:27 +08:00
WebSiteEntity.Find(id).Delete();
2020-02-12 15:23:34 +08:00
QuartzTask.Instance().DeleteTask(id.ToString());
2020-02-10 22:30:27 +08:00
return Redirect(Url.Action("Index"));
}
public IActionResult DeleteWebSiteBatch(int[] ids)
{
WebSiteEntity.Where(x => ids.Contains(x.Id)).ToDelete().ExecuteAffrows();
2020-02-12 15:23:34 +08:00
QuartzTask.Instance()
.DeleteTasks(
new ReadOnlyCollection<JobKey>(ids.Select(x => new JobKey(x.ToString(), "default")).ToList()));
2020-02-10 22:30:27 +08:00
return Redirect(Url.Action("Index"));
}
public IActionResult EnableWebSiteBatch(int[] ids)
{
2020-02-12 15:23:34 +08:00
var webSiteEntities = WebSiteEntity.Where(x => ids.Contains(x.Id)).ToUpdate()
.Set(y => y.IsEnable, true).ExecuteUpdated();
foreach (var webSiteEntity in webSiteEntities)
{
QuartzTask.Instance().AddTask(typeof(CollectionJob), webSiteEntity.Cron, webSiteEntity.Id.ToString(),
"default", ("id", webSiteEntity.Id));
}
2020-02-10 22:30:27 +08:00
return Redirect(Url.Action("Index"));
}
public IActionResult DisableWebSiteBatch(int[] ids)
{
WebSiteEntity.Where(x => ids.Contains(x.Id)).ToUpdate()
.Set(y => y.IsEnable, false).ExecuteAffrows();
2020-02-12 15:23:34 +08:00
QuartzTask.Instance().DeleteTasks(new ReadOnlyCollection<JobKey>(ids.Select(x => new JobKey(x.ToString(), "default")).ToList()));
2020-02-09 22:43:16 +08:00
return Redirect(Url.Action("Index"));
}
2020-02-09 19:10:05 +08:00
public IActionResult WebSiteDialog(int id)
{
WebSiteEntity webSiteEntity = null;
if (id == 0)
{
webSiteEntity = new WebSiteEntity();
ViewBag.title = "添加新网站";
}
else
{
webSiteEntity = WebSiteEntity.Find(id);
ViewBag.title = "修改" + webSiteEntity.WebSiteName;
}
return View(webSiteEntity);
}
2020-02-10 22:30:27 +08:00
2020-02-09 19:10:05 +08:00
}
}