Example #1
0
 public ActionResult EditArticleType()
 {
     try
     {
         var ArticleID = ZNRequest.GetInt("ArticleID");
         var TypeID    = ZNRequest.GetInt("ArticleType");
         if (TypeID <= 0)
         {
             return(Json(new { result = false, message = "参数异常" }, JsonRequestBehavior.AllowGet));
         }
         var articleType = AppHelper.GetArticleType().FirstOrDefault <ArticleType>(x => x.ID == TypeID);
         if (articleType == null)
         {
             return(Json(new { result = false, message = "不存在当前类型" }, JsonRequestBehavior.AllowGet));
         }
         var result = new SubSonic.Query.Update <Article>(provider).Set("TypeID").EqualTo(TypeID).Set("TypeIDList").EqualTo(articleType.ParentIDList).Where <Article>(x => x.ID == ArticleID).Execute() > 0;
         if (result)
         {
             return(Json(new { result = true, message = "成功" }, JsonRequestBehavior.AllowGet));
         }
     }
     catch (Exception ex)
     {
         LogHelper.ErrorLoger.Error("ArticleController_EditArticleType:" + ex.Message);
     }
     return(Json(new { result = false, message = "失败" }, JsonRequestBehavior.AllowGet));
 }
Example #2
0
 public ActionResult EditShare()
 {
     try
     {
         var ArticleID       = ZNRequest.GetInt("ArticleID");
         var ArticleNumber   = ZNRequest.GetString("ArticleNumber");
         var TypeID          = ZNRequest.GetInt("ArticleType");
         var ArticlePower    = ZNRequest.GetInt("ArticlePower", Enum_ArticlePower.Myself);
         var ArticlePowerPwd = ZNRequest.GetString("ArticlePowerPwd");
         if (ArticlePower < 0)
         {
             return(Json(new { result = false, message = "请选择文章权限" }, JsonRequestBehavior.AllowGet));
         }
         if (TypeID <= 0)
         {
             return(Json(new { result = false, message = "请选择文章类别" }, JsonRequestBehavior.AllowGet));
         }
         var articleType = AppHelper.GetArticleType().FirstOrDefault <ArticleType>(x => x.ID == TypeID);
         if (articleType == null)
         {
             return(Json(new { result = false, message = "不存在当前类型" }, JsonRequestBehavior.AllowGet));
         }
         var result = new SubSonic.Query.Update <Article>(provider)
                      .Set("TypeID").EqualTo(TypeID)
                      .Set("TypeIDList").EqualTo(articleType.ParentIDList)
                      .Set("ArticlePower").EqualTo(ArticlePower)
                      .Set("ArticlePowerPwd").EqualTo(ArticlePowerPwd)
                      .Where <Article>(x => x.ID == ArticleID).Execute() > 0;
         if (result)
         {
             //用户相册是否展示
             var status = ArticlePower == Enum_ArticlePower.Public ? Enum_Status.Approved : Enum_Status.Audit;
             new SubSonic.Query.Update <ArticlePart>(provider).Set("Status").EqualTo(status).Where <ArticlePart>(x => x.ArticleNumber == ArticleNumber).Execute();
             return(Json(new { result = true, message = "成功" }, JsonRequestBehavior.AllowGet));
         }
     }
     catch (Exception ex)
     {
         LogHelper.ErrorLoger.Error("ArticleController_EditShare:" + ex.Message);
     }
     return(Json(new { result = false, message = "失败" }, JsonRequestBehavior.AllowGet));
 }
Example #3
0
        protected List <ArticleJson> ArticleListInfo(List <Article> list, string usernumber = "")
        {
            //文章编号集合
            var array        = list.Select(x => x.Number).ToArray();
            var articletypes = AppHelper.GetArticleType();
            var parts        = new SubSonic.Query.Select(provider).From <ArticlePart>().Where <ArticlePart>(x => x.Types == Enum_ArticlePart.Pic).And("ArticleNumber").In(array).OrderAsc("SortID").ExecuteTypedList <ArticlePart>();

            List <string> userids = new List <string>();

            list.ForEach(x =>
            {
                userids.Add(x.CreateUserNumber);
            });

            var users = new SubSonic.Query.Select(provider, "ID", "NickName", "Avatar", "Cover", "Signature", "Number", "IsPay").From <User>().Where("Number").In(userids.ToArray()).ExecuteTypedList <User>();

            //判断是否关注、判断是否点赞、判断是否收藏
            var fans  = new List <Fan>();
            var zans  = new List <ArticleZan>();
            var keeps = new List <Keep>();

            if (!string.IsNullOrWhiteSpace(usernumber))
            {
                fans  = db.Find <Fan>(x => x.CreateUserNumber == usernumber).ToList();
                zans  = db.Find <ArticleZan>(x => x.CreateUserNumber == usernumber).ToList();
                keeps = db.Find <Keep>(x => x.CreateUserNumber == usernumber).ToList();
            }

            var tags = GetTag();

            List <ArticleJson> newlist = new List <ArticleJson>();

            list.ForEach(x =>
            {
                var user = users.FirstOrDefault(y => y.Number == x.CreateUserNumber);
                if (user != null)
                {
                    ArticleJson model   = new ArticleJson();
                    var articletype     = articletypes.FirstOrDefault(y => y.ID == x.TypeID);
                    model.UserID        = user.ID;
                    model.NickName      = user.NickName;
                    model.Avatar        = user.Avatar;
                    model.Signature     = user.Signature;
                    model.UserCover     = user.Cover;
                    model.IsPay         = user.IsPay;
                    model.ArticleID     = x.ID;
                    model.ArticleNumber = x.Number;
                    model.Title         = x.Title;
                    model.Views         = x.Views;
                    model.Goods         = x.Goods;

                    //标签
                    model.TagList = new List <Tag>();
                    if (!string.IsNullOrWhiteSpace(x.Tag))
                    {
                        var tag = x.Tag.Split(',').ToList();
                        tag.ForEach(y =>
                        {
                            var id   = Tools.SafeInt(y);
                            var item = tags.FirstOrDefault(z => z.ID == id);
                            if (item != null)
                            {
                                model.TagList.Add(item);
                            }
                        });
                    }
                    model.IsFollow     = fans.Count(y => y.ToUserNumber == x.CreateUserNumber);
                    model.IsZan        = zans.Count(y => y.ArticleNumber == x.Number);
                    model.IsKeep       = keeps.Count(y => y.ArticleNumber == x.Number);
                    model.UserNumber   = x.CreateUserNumber;
                    model.Cover        = x.Cover;
                    model.CreateDate   = x.CreateDate.ToString("yyyy-MM-dd hh:mm");
                    model.TypeName     = articletype == null ? "" : articletype.Name;
                    model.ArticlePart  = parts.Where(y => y.ArticleNumber == x.Number).OrderBy(y => y.ID).Take(4).ToList();
                    model.ArticlePower = x.ArticlePower;
                    model.Recommend    = x.Recommend;
                    model.Province     = x.Province;
                    model.City         = x.City;
                    model.Submission   = x.Submission;
                    newlist.Add(model);
                }
            });

            return(newlist);
        }
Example #4
0
        public ActionResult Edit()
        {
            var parts = "";

            try
            {
                User user = GetUserInfo();
                if (user == null)
                {
                    return(Json(new { result = false, message = "用户信息验证失败", code = Enum_ErrorCode.UnLogin }, JsonRequestBehavior.AllowGet));
                }
                Article model = new Article();
                model.ID = ZNRequest.GetInt("ArticleID");
                if (model.ID > 0)
                {
                    model = db.Single <Article>(x => x.ID == model.ID);
                    if (model == null)
                    {
                        model = new Article();
                    }
                    else
                    {
                        //判断权限
                        if (user.UserRole == Enum_UserRole.Common)
                        {
                            if (user.Number != model.CreateUserNumber)
                            {
                                return(Json(new { result = false, message = "没有权限", code = Enum_ErrorCode.NoPower }, JsonRequestBehavior.AllowGet));
                            }
                        }
                    }
                }
                model.Title = SqlFilter(ZNRequest.GetString("Title"));
                model.Title = CutString(model.Title, 100);
                var dirtyword = AppHelper.HasDirtyWord(model.Title);
                if (!string.IsNullOrWhiteSpace(dirtyword))
                {
                    return(Json(new { result = false, message = "您输入的标题含有敏感内容[" + dirtyword + "],请检查后重试哦" }, JsonRequestBehavior.AllowGet));
                }
                if (string.IsNullOrWhiteSpace(model.Title))
                {
                    model.Title = "我的小微篇";
                }
                model.Province         = ZNRequest.GetString("Province");
                model.City             = ZNRequest.GetString("City");
                model.District         = ZNRequest.GetString("District");
                model.Street           = ZNRequest.GetString("Street");
                model.DetailName       = ZNRequest.GetString("DetailName");
                model.CityCode         = ZNRequest.GetString("CityCode");
                model.Latitude         = Tools.SafeDouble(ZNRequest.GetString("Latitude"));
                model.Longitude        = Tools.SafeDouble(ZNRequest.GetString("Longitude"));
                model.Template         = ZNRequest.GetInt("Template");
                model.ColorTemplate    = ZNRequest.GetInt("ColorTemplate");
                model.UpdateUserNumber = user.Number;
                model.UpdateDate       = DateTime.Now;
                model.UpdateIP         = Tools.GetClientIP;
                model.Status           = Enum_Status.Approved;
                model.Submission       = Enum_Submission.TemporaryApproved;//默认临时投稿审核
                var ArticlePower = ZNRequest.GetInt("ArticlePower", -1);
                if (ArticlePower > -1)
                {
                    model.ArticlePower = ArticlePower;
                }
                var ArticlePowerPwd = ZNRequest.GetString("ArticlePowerPwd");
                if (!string.IsNullOrWhiteSpace(ArticlePowerPwd))
                {
                    model.ArticlePowerPwd = ArticlePowerPwd;
                }
                var TypeID = ZNRequest.GetInt("ArticleType", 0);
                if (TypeID > 0)
                {
                    var articleType = AppHelper.GetArticleType().FirstOrDefault <ArticleType>(x => x.ID == TypeID);
                    if (articleType != null)
                    {
                        model.TypeID     = TypeID;
                        model.TypeIDList = articleType.ParentIDList;
                    }
                }
                var result = false;
                if (model.ID == 0)
                {
                    var cover = ZNRequest.GetString("Cover");
                    if (string.IsNullOrWhiteSpace(cover))
                    {
                        return(Json(new { result = false, message = "文章信息异常" }, JsonRequestBehavior.AllowGet));
                    }
                    var covers = cover.Split(',');
                    model.Cover            = covers[0];
                    model.Recommend        = Enum_ArticleRecommend.None;
                    model.CreateUserNumber = user.Number;
                    model.CreateDate       = DateTime.Now;
                    model.CreateIP         = Tools.GetClientIP;
                    model.Number           = BuildNumber();
                    model.ID = Tools.SafeInt(db.Add <Article>(model));
                    result   = model.ID > 0;

                    //初始化文章段落
                    if (result)
                    {
                        for (var i = 0; i < covers.Length; i++)
                        {
                            ArticlePart part = new ArticlePart();
                            part.ArticleNumber    = model.Number;
                            part.Types            = Enum_ArticlePart.Pic;
                            part.Introduction     = covers[i];
                            part.IntroExpand      = string.Empty;
                            part.SortID           = Tools.SafeInt(i);
                            part.Status           = Enum_Status.Audit;
                            part.CreateDate       = DateTime.Now;
                            part.CreateUserNumber = user.Number;
                            part.CreateIP         = Tools.GetClientIP;
                            part.ID = Tools.SafeInt(db.Add <ArticlePart>(part));
                            result  = part.ID > 0;
                        }
                    }
                    if (result)
                    {
                        ArticleType articleType = AppHelper.GetArticleType().FirstOrDefault <ArticleType>(x => x.ID == model.TypeID);
                        model.TypeName = articleType == null ? string.Empty : articleType.Name;

                        return(Json(new
                        {
                            result = true,
                            message = new
                            {
                                ID = model.ID,
                                Number = model.Number,
                                ArticlePower = model.ArticlePower,
                                ArticlePowerPwd = model.ArticlePowerPwd,
                                ArticleType = model.TypeID,
                                ArticleTypeName = model.TypeName
                            }
                        }, JsonRequestBehavior.AllowGet));
                    }
                }
                else
                {
                    if (model.ArticlePower == Enum_ArticlePower.Public)
                    {
                        model.ArticlePower = Enum_ArticlePower.Myself;
                    }
                    if (string.IsNullOrWhiteSpace(model.Title))
                    {
                        model.Title = "我的小微篇";
                    }
                    result = db.Update <Article>(model) > 0;

                    //取消自定义模板启用
                    if (model.Template != 1)
                    {
                        var list = db.Find <Background>(x => x.ArticleNumber == model.Number && x.IsUsed == Enum_Used.Approved).ToList();
                        if (list.Count > 0)
                        {
                            list.ForEach(x =>
                            {
                                x.IsUsed = Enum_Used.Audit;
                            });
                            db.UpdateMany <Background>(list);
                        }
                    }


                    ArticleType articleType = AppHelper.GetArticleType().FirstOrDefault <ArticleType>(x => x.ID == model.TypeID);
                    model.TypeName = articleType == null ? string.Empty : articleType.Name;

                    parts = SqlFilter(ZNRequest.GetString("Part").Trim(), false, false);

                    if (!string.IsNullOrWhiteSpace(parts))
                    {
                        List <PartJson> list = Newtonsoft.Json.JsonConvert.DeserializeObject <List <PartJson> >(parts);
                        list.ForEach(x =>
                        {
                            if (x.Status == 0)
                            {
                                //排序
                                var partid = Tools.SafeInt(x.ID);
                                var part   = db.Single <ArticlePart>(y => y.ID == partid);
                                if (part != null)
                                {
                                    part.SortID = Tools.SafeInt(x.SortID);
                                    db.Update <ArticlePart>(part);
                                }
                            }
                            else if (x.Status == 1)
                            {
                                //新增
                                ArticlePart part      = new ArticlePart();
                                part.ArticleNumber    = model.Number;
                                part.Types            = x.PartType;
                                part.Introduction     = x.Introduction;
                                part.IntroExpand      = x.IntroExpand;
                                part.SortID           = Tools.SafeInt(x.SortID);
                                part.Status           = Enum_Status.Audit;
                                part.CreateDate       = DateTime.Now;
                                part.CreateUserNumber = user.Number;
                                part.CreateIP         = Tools.GetClientIP;
                                part.ID = Tools.SafeInt(db.Add <ArticlePart>(part));
                            }
                            else if (x.Status == 2)
                            {
                                //编辑
                                var partid = Tools.SafeInt(x.ID);
                                var part   = db.Single <ArticlePart>(y => y.ID == partid);
                                if (part != null)
                                {
                                    part.Introduction = x.Introduction;
                                    part.IntroExpand  = x.IntroExpand;
                                    part.SortID       = Tools.SafeInt(x.SortID);
                                    db.Update <ArticlePart>(part);
                                }
                            }
                            else if (x.Status == 3)
                            {
                                //是否临时删除删除
                                if (x.Temporary == 0)
                                {
                                    db.Delete <ArticlePart>(x.ID);
                                }
                            }
                        });
                    }
                }
                if (result)
                {
                    //更新自定义漂浮
                    var           ShowyUrl  = ZNRequest.GetString("ShowyUrl");
                    var           MusicID   = ZNRequest.GetInt("MusicID");
                    var           MusicName = ZNRequest.GetString("MusicName");
                    var           MusicUrl  = ZNRequest.GetString("MusicUrl");
                    ArticleCustom custom    = db.Single <ArticleCustom>(x => x.ArticleNumber == model.Number);
                    if (custom == null)
                    {
                        custom = new ArticleCustom();
                        custom.ArticleNumber = model.Number;
                    }
                    custom.ShowyUrl  = ShowyUrl;
                    custom.MusicID   = MusicID;
                    custom.MusicName = MusicName;
                    custom.MusicUrl  = MusicUrl;
                    if (custom.ID == 0)
                    {
                        db.Add <ArticleCustom>(custom);
                    }
                    else
                    {
                        db.Update <ArticleCustom>(custom);
                    }

                    return(Json(new
                    {
                        result = true,
                        message = new
                        {
                            ID = model.ID,
                            Number = model.Number,
                            ArticlePower = model.ArticlePower,
                            ArticlePowerPwd = model.ArticlePowerPwd,
                            TypeID = model.TypeID,
                            TypeName = model.TypeName
                        }
                    }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLoger.Error("ArticleController_Edit:" + ex.Message + "," + parts);
            }
            return(Json(new { result = false, message = "失败" }, JsonRequestBehavior.AllowGet));
        }