Пример #1
0
        /// <summary>
        /// 用户投稿
        /// </summary>
        /// <param name="news"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public static Result UserPost(News news, User user)
        {
            using (DataEntities ent = new DataEntities())
            {
                Result r = new Result();

                UserGroup g = (from l in ent.UserGroup where l.ID == user.Group select l).FirstOrDefault();

                int? maxPost = 0;
                try
                {
                    maxPost = g.MaxPost;
                }
                catch { }

                //验证用户是否允许投稿
                if (maxPost <= 0)
                {
                    r.Success = false;
                    r.Text = "对不起,您没有投稿的权限!";
                    return r;
                }

                //验证本日投稿数是否已经过多
                //int todayPost = NewsView.Count(string.Format("AutorID={0}", user.ID));
                int todayPost = (from l in ent.News where l.AutorID == user.ID && l.NewsTime > DateTime.Now.Date && l.NewsTime < DateTime.Now.AddDays(1).Date select l).Count();
                if (todayPost > maxPost && news.ID <= 0)
                {
                    r.Success = false;
                    r.Text = "对不起,您本日投稿数量已经达到最大限制,请明天继续!";
                    return r;
                }

                //验证标题是否为空
                if (news.Title.IsNullOrEmpty())
                {
                    r.Success = false;
                    r.Text = "文章标题不能为空";
                    return r;
                }

                //验证栏目
                if (news.ClassID <= 0)
                {
                    r.Success = false;
                    r.Text = "栏目不能为空!";
                    return r;
                }

                news.Audit = g.PostAotuAudit;
                news.AutorID = user.ID;
                if (news.Author.IsNullOrEmpty())
                {
                    news.Author = user.UserName;
                }

                if (news.ID <= 0)
                {
                    ent.AddToNews(news);
                }

                user.Cent += (from l in ent.Class where l.ID == news.ClassID select l).FirstOrDefault().PostAddCent;

                ent.SaveChanges();

                r.Success = true;
                r.Text = "投递成功!";

                return r;
            }
        }
Пример #2
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_Save_Click(object sender, EventArgs e)
        {
            DataEntities ent = new DataEntities();

            cls = WS.RequestInt("class", 0);
            zt = WS.RequestInt("zt", 0);
            url = string.Format("NewsList.aspx?class={0}&zt={1}", cls, zt);

            News n = new News();

            if (WS.RequestInt("id") > 0)
            {
                n = //NewsView.GetModelByID(WS.RequestString("id"));
                    (from l in ent.News where l.ID == id select l).FirstOrDefault();
                cls = n.ClassID.ToInt32();
            }
            else
            {
                n.ClassID = cls;
                n.ZtID = zt;
            }

            Class c = NewsAction.NewsClass.Where(p => p.ID.ToString() == ddl_Class.SelectedValue).First();

            n.ClassID = ddl_Class.SelectedValue.ToInt32();
            n.Title = txt_Title.Text.TrimDbDangerousChar();
            n.TitleColor = cp_TitleColor.Value.TrimDbDangerousChar();
            n.TitleB = chk_TitleB.Checked;
            n.TitleI = chk_TitleI.Checked;
            n.TitleS = chk_TitleS.Checked;

            n.FTitle = txt_FTitle.Text.TrimDbDangerousChar();

            n.Audit = chk_Audit.Checked;
            n.Tuijian = chk_Tuijian.Checked;
            n.Toutiao = chk_Toutiao.Checked;

            n.KeyWords = txt_Key.Text.TrimDbDangerousChar();
            //关键词写入系统
            txt_Key.Text = Regex.Replace(txt_Key.Text, "\\s", ",");
            string[] keys = Regex.Replace(txt_Key.Text, "\\s", ",").Split(',');
            foreach (string k in keys)
            {
                InsertKeyWords(1, k);
            }

            n.NavUrl = txt_NavUrl.Text.TrimDbDangerousChar();
            n.NewsTime=txt_NewsTime.Text.ToDateTime();
            n.TitleImage = txt_TitleImage.Text.TrimDbDangerousChar();
            n.Description = txt_Description.Text.TrimDbDangerousChar();
            n.Author = txt_Author.Text.TrimDbDangerousChar();
            n.Source = txt_Source.Text.TrimDbDangerousChar();
            n.Content = FCKeditor1.Text.TrimDbDangerousChar();
            //n.ContentEn = FCKeditor2.Text.TrimDbDangerousChar();

            n.SetTop = chk_SetTop.Checked;
            n.EnableReply = !chk_CloseReply.Checked;
            n.ModelID = ddl_contentTemp.SelectedValue.ToInt32();
            n.ClickCount = txt_ClickCount.Text.ToInt32();
            n.DownCount = txt_DownCount.Text.ToInt32();
            n.FileForder = txt_FileForder.Text;
            n.FileName = txt_FileName.Text;
            n.ReplyCount = 0;

            if (id <= 0)
            {
                ent.AddToNews(n);
            }

            ent.SaveChanges();
            ent.Dispose();

            if (SystemSetting.EnableStatic)
            {

                CreatePage.CreateContentPage(n, c);

                News news_pre = GetPreNews(n, c);

                if (news_pre != null)
                {
                    CreatePage.CreateContentPage(news_pre, c);
                }
                switch (c.EditcreateList)
                {
                    case 0:
                        break;
                    case 1:
                        CreatePage.CreateListPage(c, 1);
                        break;
                    case 2:
                        CreatePage.GreateIndexPage();
                        break;
                    case 3:
                    case 4:
                        CreatePage.CreateListPage(c, 1);
                        break;
                    case 5:
                        CreatePage.GreateIndexPage();
                        break;
                    case 6:
                        CreatePage.CreateListPage(c, 1);
                        CreatePage.GreateIndexPage();
                        break;
                }
            }

            Js.AlertAndChangUrl("保存成功!",url);
        }