示例#1
0
        public ActionResult Add(string Title, string PicUrl)
        {
            AjaxResponse <ArticleDisPhoto> obj = new AjaxResponse <ArticleDisPhoto>();

            if (string.IsNullOrEmpty(Title))
            {
                obj.ErrorMessage = "展图名称不能为空";
                return(Json(obj));
            }
            if (string.IsNullOrEmpty(PicUrl))
            {
                obj.ErrorMessage = "展图路径不能为空";
                return(Json(obj));
            }
            if (Title.Length > 15)
            {
                obj.ErrorMessage = "展图名称不能超过15个字";
                return(Json(obj));
            }

            ArticleDisPhoto ArticleDisPhoto = new ArticleDisPhoto {
                Title = Title, PicUrl = PicUrl, Status = StatusEnum.Normal
            };

            obj.IsSuccess = ArticleDisPhotoService.AddModel(ArticleDisPhoto);
            return(Json(obj));
        }
示例#2
0
        /// <summary>
        /// 文章默认展图查询
        /// </summary>
        /// <param name="page">当前页(1开始)</param>
        /// <param name="rows">显示条数</param>
        /// <returns></returns>
        public JsonResult Query(int page = 1, int rows = 20, int photoType = 1)
        {
            int total = 0;

            if (photoType == 1)
            {
                IQueryable <ArticleDisPhoto> articleList = ArticleDisPhotoService.PageLoad(a => true, a => new { a.Id }, false, page, rows, out total);

                var obj = new AjaxResponse <ListData <ArticleDisPhoto> >();
                obj.IsSuccess  = true;
                obj.Data       = new ListData <ArticleDisPhoto>();
                obj.Data.rows  = articleList;
                obj.Data.total = total;
                return(Json(obj));
            }
            else
            {
                IQueryable <PeopleDisPhoto> articleList = PeopleDisPhotoService.PageLoad(a => true, a => new { a.Id }, false, page, rows, out total);

                var obj = new AjaxResponse <ListData <PeopleDisPhoto> >();
                obj.IsSuccess  = true;
                obj.Data       = new ListData <PeopleDisPhoto>();
                obj.Data.rows  = articleList;
                obj.Data.total = total;
                return(Json(obj));
            }
        }
示例#3
0
        public JsonResult Update(int Status, string Title, string PicUrl, int Id = 0)
        {
            AjaxResponse <ArticleDisPhoto> obj = new AjaxResponse <ArticleDisPhoto>();

            if (string.IsNullOrEmpty(Title))
            {
                obj.ErrorMessage = "展图名称不能为空";
                return(Json(obj));
            }
            if (string.IsNullOrEmpty(PicUrl))
            {
                obj.ErrorMessage = "展图路径不能为空";
                return(Json(obj));
            }
            if (Title.Length > 15)
            {
                obj.ErrorMessage = "展图名称不能超过15个字";
                return(Json(obj));
            }

            ArticleDisPhoto ArticleDisPhoto = new ArticleDisPhoto {
                Id = Id, Title = Title, PicUrl = PicUrl, Status = Status != 99 ? StatusEnum.Normal : StatusEnum.Delete
            };

            obj.IsSuccess = ArticleDisPhotoService.UpdateModel(ArticleDisPhoto);

            return(Json(obj));
        }
示例#4
0
        /// <summary>
        /// 修改默认展图
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Update(int Id = 0)
        {
            ArticleDisPhoto model = ArticleDisPhotoService.FindModel(Id);

            if (model == null)//查不到就让他添加(防恶意篡改ID)
            {
                return(RedirectToAction("Add"));
            }
            return(View(model));
        }
示例#5
0
        /// <summary>
        /// 批量恢复默认展图
        /// </summary>
        /// <param name="ids">ID集合信息(逗号分隔)</param>
        /// <returns></returns>
        public JsonResult RecoverList(string ids = "")
        {
            IList <int> idList = ids.Trim(',').Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(s => Convert.ToInt32(s)).ToList();
            int         i      = ArticleDisPhotoService.UpdateModel(at => idList.Contains(at.Id), at => at.Status = StatusEnum.Normal);
            AjaxResponse <ArticleDisPhoto> obj = new AjaxResponse <ArticleDisPhoto>();

            if (i > 0)
            {
                obj.IsSuccess = true;
                obj.OtherData = "成功恢复" + i + "条记录";
            }
            else
            {
                obj.ErrorMessage = "操作失败!";
            }
            return(Json(obj));
        }
示例#6
0
        public JsonResult Update(int ArticleId = 0, int SeoId = 0, string CreateTime = "", string Title = "", string Author = "", string TContent = "", string TypeIds = "", string TagIds = "", int GroupType = 1, int Recommend = 0, int HitCount = 9, int Sort = 9, int Status = 0, string DisplayPic = "", string SeoKeywords = "", string Seodescription = "")
        {
            AjaxResponse <object> obj = new AjaxResponse <object>();

            #region 一系列验证
            if (ArticleId == 0 || SeoId == 0)
            {
                obj.ErrorMessage = "文章或Seo不存在!";
                return(Json(obj));
            }
            if (string.IsNullOrEmpty(Title))
            {
                obj.ErrorMessage = "文章标题不能为空!";
                return(Json(obj));
            }
            if (string.IsNullOrEmpty(Author))
            {
                obj.ErrorMessage = "作者不能为空!";
                return(Json(obj));
            }
            if (string.IsNullOrEmpty(TContent))
            {
                obj.ErrorMessage = "文章内容不能为空!";
                return(Json(obj));
            }
            if (string.IsNullOrEmpty(TypeIds))
            {
                obj.ErrorMessage = "请好好选择文章分类!";
                return(Json(obj));
            }
            if (string.IsNullOrEmpty(TagIds))
            {
                obj.ErrorMessage = "请好好选择文章Tag!";
                return(Json(obj));
            }
            if (string.IsNullOrEmpty(SeoKeywords))
            {
                obj.ErrorMessage = "Seo关键词不能为空!";
                return(Json(obj));
            }
            if (string.IsNullOrEmpty(Seodescription))
            {
                obj.ErrorMessage = "Seo头部描述能为空!";
                return(Json(obj));
            }
            if (Title.Length > 50)
            {
                obj.ErrorMessage = "新闻标题50个字以内!";
                return(Json(obj));
            }
            if (Author.Length > 15)
            {
                obj.ErrorMessage = "作者15个字以内!";
                return(Json(obj));
            }
            if (SeoKeywords.Length > 149)
            {
                obj.ErrorMessage = "Seo头关键词149字以内!";
                return(Json(obj));
            }
            if (Seodescription.Length > 249)
            {
                obj.ErrorMessage = "Seo头部描述249字以内!";
                return(Json(obj));
            }
            if (TagIds.Length > 100)
            {
                obj.ErrorMessage = "文章Tag好像有点太多了啊!";
                return(Json(obj));
            }
            if (TypeIds.Length > 100)
            {
                obj.ErrorMessage = "文章分类好像有点那个啥吧!";
                return(Json(obj));
            }
            #endregion

            SeoTKD seoInfo = new SeoTKD()
            {
                Id            = SeoId,
                SeoKeywords   = SeoKeywords,
                Sedescription = Seodescription,
                Status        = StatusEnum.Normal
            };

            #region 存储前的处理
            TypeIds = TypeIds.Trim(',');
            TagIds  = TagIds.Trim(',');
            DateTime timeTemp;
            DateTime.TryParse(CreateTime, out timeTemp);

            //传过来的已经url编码了【带敏感字符的url服务器默认是拒绝请求的】
            //没有url编码的,解码还是他本身
            TContent = HttpUtility.UrlDecode(TContent);
            //必须保证存在数据库里面的文字是安全的
            TContent = HttpUtility.HtmlEncode(TContent);

            //如果没有上传默认展图,就随机展示一个默认展图
            if (string.IsNullOrEmpty(DisplayPic))
            {
                IList <ArticleDisPhoto> disPics = ArticleDisPhotoService.PageLoad(p => p.Status != StatusEnum.Delete).ToList();
                int count = disPics.Count;
                if (count > 0)
                {
                    Random random = new Random();
                    int    index  = random.Next(disPics.Count);
                    DisplayPic = disPics[index].PicUrl;
                }
                else//实在没有的话就给一个默认值
                {
                    DisplayPic = LoT.Common.ConfigHelper.GetValueForConfigAppKey("ArticleTypeDisPlayPic");
                }
            }
            #endregion

            Article article = new Article()
            {
                Id         = ArticleId,
                Title      = Title,
                Author     = Author,
                TContent   = TContent,
                CreateTime = timeTemp,
                UpdateTime = DateTime.Now,
                TypeIds    = TypeIds,
                GroupType  = (GroupEnum)(GroupType == 0 ? 1 : GroupType),
                Recommend  = (RecommendEnum)Recommend,
                HitCount   = HitCount,
                Sort       = Sort,
                TagIds     = TagIds,
                Status     = (ArticleStatusEnum)Status,
                DisplayPic = DisplayPic,
                SeoId      = SeoId
            };

            bool b = ArticleService.UpdateArticle(article, seoInfo) > 0;
            obj.IsSuccess = b;
            if (!b)
            {
                obj.ErrorMessage = "未知原因添加失败~";
            }
            return(Json(obj));
        }