ASP.NET.4.5.1+MVC5.0设置系统角色与权限(二)(21)


 public class JobController : Controller
    {
        JobRepository jobryrepository = new JobRepository();
        #region 岗位列表
        /// <summary>
        /// 默认页面
        /// </summary>
        /// <returns></returns>
        ///
        [Authorize]
        public ActionResult Index(int? page)
        {
            ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
            var source = jobryrepository.GetModelListByState(1);
            return View(jobryrepository.GetPageModelList(source, 10, page ?? 1));
        }
        #endregion
        #region 添加
        /// <summary>
        /// 添加页
        /// </summary>
        /// <param>实体类</param>
        /// <returns></returns>
        [Authorize]
        public ActionResult Add(Job model)
        {
            ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
            // ViewData["State"] = SelectListHelper.GetIsOrNoSelectList(0);
            return View();
        }
        /// <summary>
        /// 添加事件
        /// </summary>
        /// <param>实体类</param>
        /// <param></param>
        /// <returns></returns>
        [Authorize, HttpPost, ValidateInput(false)]
        public ActionResult Add(Job model, FormCollection fc)
        {
            ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
            model.State = 1;
            model.CreateTime = DateTime.Now;
            jobryrepository.SaveOrEditModel(model);
            return RedirectToAction("Index");
        }
        #endregion
        #region 删除
        /// <summary>
        /// 删除
        /// </summary>
        /// <param>删除编号</param>
        /// <returns></returns>
        [Authorize]
        public ActionResult Delete(int id)
        {
            ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
            var model = jobryrepository.GetModel(id);
            model.State = 0;
            if (model != null)
            {
                jobryrepository.SaveOrEditModel(model);
                return RedirectToAction("index");
            }
            else
                return View("404");
            //var model = categoryrepository.GetModel(id);
            //if (model != null)
            //{
            //    categoryrepository.DeleteModel(id);
            //    return RedirectToAction("Index");
            //}
            //else
            //    return View("404");
        }
        #endregion
        #region 查询
        [Authorize]
        public ActionResult Search(int? page)
        {
            ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
            string jobname = "";
            if (page == null)
            {
                jobname = Request.Form["KeyWord"];
                CookieHelper.SetObj("KeyWord", 0, jobname);
            }
            else
                jobname = CookieHelper.GetValue("KeyWord");
            var query = QueryBuilder.Create<Job>().Like(d => d.JobName, jobname);
            var source = jobryrepository.GetModelList().Where(query.Expression);
            return View(new Pager<Job>(source, page ?? 1, 10));
        }
        #endregion
        #region 编辑
        [Authorize]
        public ActionResult Edit(int id)
        {
            ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
            var model = jobryrepository.GetModel(id);
            if (model != null)
            {
                ViewData["State"] = SelectListHelper.GetStateSelectList(model.State);
                return View(model);
            }
            else
                return View("404");
        }
        [Authorize, AcceptVerbs(HttpVerbs.Post), ValidateInput(false)]
        public ActionResult Edit(int id, FormCollection fc)
        {
            ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
            var model = jobryrepository.GetModel(id);
            if (model != null)
            {
                UpdateModel(model);
                jobryrepository.SaveOrEditModel(model);
                return RedirectToAction("index");
            }
            else
                return View("404");
        }
        #endregion
    }

View代码

Index.cshtml

复制代码 代码如下:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjzwdj.html