using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using seekyouth.BLL;
using seekyouth.Model;
using Webdiyer.WebControls.Mvc;
namespace Seekyouth.Areas.Admin.Controllers
{
public class AdminArticleController : Controller
{
private channel _channel = new channel();
private ChannelManager _channelManager = new ChannelManager();
private article _article = new article();
private ArticleManager _articleManager = new ArticleManager();
private ArticleClassManager _articleClassManager = new ArticleClassManager();
//
// GET: /Admin/Article/
public ActionResult Index()
{
var model = _channelManager.GetAllchannel().Where(m => m.channel_isDel == 0).OrderBy(m => m.channel_orderID);
return View(model);
}
public ActionResult Detail(string id)
{
if (!string.IsNullOrEmpty(id))
{
var model = _articleManager.GetarticleById(id);
if (model != null)
{
return View(model);
}
else //表示为单篇文章的列表
{
var articlemodel = _articleManager.GetAllarticle().FirstOrDefault(m => m.article__ClassID == id);
ViewBag.classId = id;
return View(articlemodel);
}
}
else
{
var channelModel =
_channelManager.GetAllchannel()
.Where(m => m.channel_isArticle == 1 && m.channel_isDel == 0)
.OrderBy(m => m.channel_inputTime)
.FirstOrDefault();
if (channelModel!=null)
{
return
View(
_articleManager.GetAllarticle()
.FirstOrDefault(m => m.article__channelId == channelModel.channel_guid));
}
else
{
return View();
}
}
}
public ActionResult ArticleList(string id,int?pageId)
{
var model = _articleManager.GetAllarticle().Where(m => m.article__ClassID == id && m.article_isDel == 0);
ViewBag.classId = id;
return View(model.AsQueryable().ToPagedList(pageId??1,2));
}
public ActionResult Edit(string id)
{
var model = _articleManager.GetarticleById(id);
ViewBag.ClassId = model.article__ClassID;
return View(model);
}
[AcceptVerbs(HttpVerbs.Post)]
[ValidateInput(false)]
public ActionResult Edit(string id,FormCollection collection)
{
var model = _articleManager.GetarticleById(id);
UpdateModel(model);
var classId=model.article__ClassID;
_articleManager.Savearticle();
return Content("<script>alert('修改成功');window.location='/Admin/AdminArticle/ArticleList/"+ classId+"' </script>");
}
public ActionResult Delete(string id)
{
var model = _articleManager.GetarticleById(id);
_articleManager.SoftDeletearticle(model);
return RedirectToAction("ArticleList",new{id=model.article__ClassID});
}
public ActionResult Create(string id)
{
ViewBag.classId = id;
return View();
}
[AcceptVerbs(HttpVerbs.Post)]
[ValidateInput(false)]
public ActionResult Create(string id, CreateArticle article)
{
if (ModelState.IsValid)
{
var articleClassModel =
_articleClassManager.GetAllarticleClass().FirstOrDefault(m => m.articleClass_guid == id);
var model = new article();
UpdateModel(model);
model.article__ClassID = id;
model.article__channelId = articleClassModel.articleClass_channelId;
_articleManager.Addarticle(model);
_articleManager.Savearticle();
return RedirectToAction("ArticleList", new { id = model.article__ClassID });
}
else
{
return View();
}
}
/// <summary>
///
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
[AcceptVerbs(HttpVerbs.Post)]
public JsonResult AJaxDelete(string ids)
{
try
{
_articleManager.DelBatch(ids ?? "");
return Json(new { aa = "true" });
}
catch (Exception ex)
{
return Json(new { value = "Err", message = ex.Message });
}
}
}
}