Ejemplo n.º 1
0
        public ActionResult Add()
        {
            if (Session["UserId"] == null)
            {
                return Redirect("/admin/login");
            }

            NewsModel model = new NewsModel();

            NewsService newsService = new NewsService();
            model.NewsCategories = newsService.GetNewsCategories();

            return View(model);
        }
Ejemplo n.º 2
0
        public ActionResult Index(string categoryId, string keywords, string page)
        {
            if (Session["UserId"] == null)
            {
                return Redirect("/admin/login");
            }

            NewsService newsService = new NewsService();

            int tempPage = 1;

            if (!string.IsNullOrEmpty(page))
            {
                Int32.TryParse(page, out tempPage);
            }

            NewsModel model = new NewsModel();

            //新闻类别列表
            model.NewsCategories = newsService.GetNewsCategories();

            //当前选中新闻类别
            model.NewsCategory = new NewsCategory();
            if (!string.IsNullOrEmpty(categoryId))
            {
                if (model.NewsCategories != null && model.NewsCategories.Count > 0)
                {
                    foreach (var item in model.NewsCategories)
                    {
                        if (item.Id == categoryId)
                        {
                            model.NewsCategory = item;
                            break;
                        }
                    }
                }
            }

            //新闻列表
            int tempCount = 0;
            model.NewsList = newsService.GetNewsList(categoryId, keywords, 15, tempPage, out tempCount);
            //分页
            if (model.NewsList != null && model.NewsList.Count > 0)
            {
                model.PageIndex = tempPage;
                model.PageSize = 15;
                model.PageStep = 10;
                model.AllCount = tempCount;
                if (model.AllCount % model.PageSize == 0)
                {
                    model.PageCount = model.AllCount / model.PageSize;
                }
                else
                {
                    model.PageCount = model.AllCount / model.PageSize + 1;
                }
            }

            //关键字
            model.Keywords = keywords;

            return View(model);
        }
Ejemplo n.º 3
0
        public ActionResult Edit(int id)
        {
            if (Session["UserId"] == null)
            {
                return Redirect("/admin/login");
            }

            NewsModel model = new NewsModel();

            NewsService newsService = new NewsService();

            model.NewsCategories = newsService.GetNewsCategories();
            model.News = newsService.GetNewsById(id);
            if (model.News != null && !model.News.IsActive)
            {
                model.News = null;
            }
            if (model.News == null)
            {
                model.News = new News();
            }

            return View(model);
        }