Пример #1
0
        public ActionResult Detail(string id)
        {
            IndexModel detail = new IndexModel();
            News news = null;

            if (id == null || (news = newsRepository.FindBy(id)) == null)
            {
                var routeValueDictionary = new RouteValueDictionary
                                       {
                                           { "controller", "Index" }, // Security Controller
                                           { "action", "Index" }, // Unauthorized Action
                                           { "reason", "请选择相应的模块!" }  // Put the reason here
                                       };
                return new RedirectToRouteResult(routeValueDictionary);

            }

            news = newsRepository.FindBy(id);
            detail.New = news;

            NewsCategory newsCategory = newsCategoryRepository.FindBy(news.Category);
            detail.category = newsCategory;

            detail.Categorys = newsCategoryRepository.FindAll();
            if (detail.Categorys != null && detail.Categorys.Count > 0)
            {
                NewsCategory category = detail.Categorys.Where(item => item.Name.Equals("新闻")).FirstOrDefault();
                if (category != null)
                {
                    detail.News.Add(category, this.newsRepository.Find(null, category, null, null, null, null, 10, 1));
                }
            }

            if (detail.New.Attachment != null)
            {
                string a = detail.New.Attachment.Path;
                string b = "/UserFiles/FileShare/" + detail.New.Attachment.DateCreated.Year + "/" + detail.New.Attachment.DateCreated.Month.ToString("00") + "/";
                string fileName = a.Replace(b, "");
                ViewData["path"] = fileName;
            }

            return View(detail);
        }
Пример #2
0
        //首页各个模块
        public ActionResult Index(string reason)
        {
            IndexModel model = new IndexModel();

            model.Categorys = newsCategoryRepository.FindAll();

            if (model.Categorys != null && model.Categorys.Count > 0)
            {
                //下载模块
                NewsCategory category = model.Categorys.Where(item => item.Name.Equals("下载")).FirstOrDefault();

                if (category != null)
                {
                    model.category = newsCategoryRepository.FindBy(category.Key);
                    model.News.Add(category, this.newsRepository.Find(null, category, null, null, null, null, 6, 1));
                }

                //通知公告模块
                category = model.Categorys.Where(item => item.Name.Equals("通知公告")).FirstOrDefault();

                if (category != null)
                {
                    model.category = newsCategoryRepository.FindBy(category.Key);
                    model.Categorys.Add(category);
                    model.News.Add(category, this.newsRepository.Find(null, category, null, null, null, null, 6, 1));
                }

                //新闻模块
                category = model.Categorys.Where(item => item.Name.Equals("新闻")).FirstOrDefault();

                if (category != null)
                {
                    model.category = newsCategoryRepository.FindBy(category.Key);
                    //model.Categorys.Add(category);
                    model.News.Add(category, this.newsRepository.Find(null, category, null, null, null, null, 6, 1));
                }
            }

            if (!string.IsNullOrEmpty(reason))
            {
                ViewData["HintMessage"] = new PDCPMS.Application.HintMessage() { Content = reason, Type = HintMessageType.Error };
            }

            #region 获取图片新闻
            //String dirPath = HttpContext.Server.MapPath("/Scripts/KindEditor3.5.2/attached/");
            //string imgtype = "*.BMP|*.JPG|*.GIF|*.PNG";
            //string[] ImageType = imgtype.Split('|');
            //IList<String> imgs = new List<String>();

            //for (int i = 0; i < ImageType.Length; i++)
            //{
            //    string[] dirs = Directory.GetFiles(dirPath, ImageType[i]);

            //    foreach (string dir in dirs)
            //    {
            //        string[] names = dir.Split('\\');
            //        string name = names[names.Length - 1];

            //        imgs.Add("/Scripts/KindEditor3.5.2/attached/" + name);
            //    }
            //}
            //ViewData["Imgs"] = imgs;
            #endregion

            return View(model);
        }
Пример #3
0
        public ActionResult Download(string id)
        {
            IndexModel detail = new IndexModel();
            News news = null;

            if (id == null || (news = newsRepository.FindBy(id)) == null)
            {
                var routeValueDictionary = new RouteValueDictionary
                                       {
                                           { "controller", "Index" }, // Security Controller
                                           { "action", "Index" }, // Unauthorized Action
                                           { "reason", "请选择相应的模块!" }  // Put the reason here
                                       };
                return new RedirectToRouteResult(routeValueDictionary);

            }

            news = newsRepository.FindBy(id);
            detail.New = news;

            #region 下载

            if (detail.New.Attachment != null)
            {
                string a = detail.New.Attachment.Path;
                string b = "/UserFiles/FileShare/" + detail.New.Attachment.DateCreated.Year + "/" + detail.New.Attachment.DateCreated.Month.ToString("00") + "/";
                string fileName = a.Replace(b, "");//客户端保存的文件名

                string filePath = Server.MapPath(a);//路径

                FileStream fs = new FileStream(filePath, FileMode.Open);//以字符流的形式下载文件

                byte[] bytes = new byte[(int)fs.Length]; fs.Read(bytes, 0, bytes.Length);

                fs.Close();

                Response.ContentType = "application/octet-stream";

                Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));//通知浏览器下载文件而不是打开

                Response.BinaryWrite(bytes);

                Response.Flush();

                Response.End();
            }
            else
            {
                var routeValueDictionary = new RouteValueDictionary
                                       {
                                           { "controller", "Index" }, // Security Controller
                                           { "action", "Index" }, // Unauthorized Action
                                           { "reason", "该新闻没有上传附件,请联系管理员!" }  // Put the reason here
                                       };
                return new RedirectToRouteResult(routeValueDictionary);
            }
            #endregion

            return View();
        }