文章的增删改查

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 });

            }

        }

 

    }

}

 

转载于:https://www.cnblogs.com/noert/p/3323393.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值