Ejemplo n.º 1
0
        public ActionResult Create(ArticleInfo articleInfo)
        {
            bool errors = false;
            bool isAdd = articleInfo.Id == 0 ? true : false;
            if (articleInfo.CategoryId == 0)
            {
                errors = true;
                ModelState.AddModelError("CAT", "Please select the category");
            }
            if (string.IsNullOrEmpty(articleInfo.Title))
            {
                errors = true;
                ModelState.AddModelError("TITLT", "Please enter a title ");
            }
            if (!errors && ModelState.IsValid)
            {
                ArticleService.Create(articleInfo);
                if (isAdd)
                {
                    ViewBag.Msg = "Success.Continue?【<a href=\"create\">Yes</a>】&nbsp;&nbsp;【<a href=\"list\">No</a>】";
                }
                else
                {
                    ViewBag.Msg = "Success.Continue?【<a href=\"create\">Yes</a>】&nbsp;&nbsp;【<a href=\"list\">No</a>】";
                }
            }

            return View(articleInfo);
        }
Ejemplo n.º 2
0
        public ActionResult Create(ArticleInfo articleInfo)
        {
            bool errors = false;
            bool isAdd = articleInfo.Id == 0 ? true : false;
            if (articleInfo.CategoryId == 0)
            {
                errors = true;
                ModelState.AddModelError("CAT", "请选择分类");
            }
            if (string.IsNullOrEmpty(articleInfo.Title))
            {
                errors = true;
                ModelState.AddModelError("TITLT", "请输入文章标题");
            }
            if (!errors && ModelState.IsValid)
            {
                ArticleService.Create(articleInfo);
                if (isAdd)
                {
                    ViewBag.Msg = "添加成功!是否继续?【<a href=\"create\">是</a>】&nbsp;&nbsp;【<a href=\"list\">否</a>】";
                }
                else
                {
                    ViewBag.Msg = "修改成功!是否继续?【<a href=\"create\">是</a>】&nbsp;&nbsp;【<a href=\"list\">否</a>】";
                }
            }

            return View(articleInfo);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 添加扩展信息,主要生成文章URL
        /// </summary>
        /// <param name="model"></param>
        /// <param name="language"></param>
        private static void LoadExtensionInfo(ArticleInfo model) {

            if (!string.IsNullOrEmpty(model.LinkUrl))
            {
                model.Url = model.LinkUrl;
            }
            else
            {
                model.Url = string.Format("/n/{0}.html",model.FullTimespan);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static int Insert(ArticleInfo model) {
            string strSQL = "INSERT INTO Articles(CategoryId,Title,Content,ImageUrl,LinkUrl,Sort,IsTop,IsDeleted,PublishDateTime,CreateDateTime,Remark,Timespan,ViewCount,IsPublished,FullTimespan,Keywords,SubTitle) VALUES(@CategoryId,@Title,@Content,@ImageUrl,@LinkUrl,@Sort,@IsTop,@IsDeleted,@PublishDateTime,GETDATE(),@Remark,@Timespan,1,@IsPublished,@FullTimespan,@Keywords,@SubTitle);SELECT @@IDENTITY;";


            //为了保证Timespan和FullTimespan一致
            string timespan = DateTime.Now.ToString("HHmmssfff");

            SqlParameter[] parms = { 
                                    new SqlParameter("Id",SqlDbType.Int),
                                    new SqlParameter("CategoryId",SqlDbType.Int),
                                    new SqlParameter("Title",SqlDbType.NVarChar),
                                    new SqlParameter("Content",SqlDbType.NVarChar),
                                    new SqlParameter("ImageUrl",SqlDbType.NVarChar),
                                    new SqlParameter("LinkUrl",SqlDbType.NVarChar),
                                    new SqlParameter("IsTop",SqlDbType.Int),
                                    new SqlParameter("IsDeleted",SqlDbType.Int),
                                    new SqlParameter("PublishDateTime",SqlDbType.DateTime),
                                    new SqlParameter("Remark",SqlDbType.NVarChar),
                                    new SqlParameter("TimeSpan",SqlDbType.NVarChar),
                                    new SqlParameter("Sort",SqlDbType.Int),
                                    new SqlParameter("IsPublished",SqlDbType.Int),
                                    new SqlParameter("FullTimespan",SqlDbType.NVarChar),
                                    new SqlParameter("Keywords",SqlDbType.NVarChar),
                                    new SqlParameter("SubTitle",SqlDbType.NVarChar),
                                   };
            parms[0].Value = model.Id;
            parms[1].Value = model.CategoryId;
            parms[2].Value = string.IsNullOrEmpty(model.Title) ? string.Empty : model.Title;
            parms[3].Value = string.IsNullOrEmpty(model.Content) ? string.Empty :model.Content;
            parms[4].Value = string.IsNullOrEmpty(model.ImageUrl) ? string.Empty : model.ImageUrl;
            parms[5].Value = string.IsNullOrEmpty(model.LinkUrl) ? string.Empty : model.LinkUrl;
            parms[6].Value = model.IsTop;
            parms[7].Value = model.IsDeleted;            
            parms[8].Value = model.PublishDateTime<= DateTime.MinValue ? DateTime.Now : model.PublishDateTime;
            parms[9].Value = string.IsNullOrEmpty(model.Remark) ? string.Empty : model.Remark;
            parms[10].Value = timespan;
            parms[11].Value = model.Sort;
            parms[12].Value = model.IsPublished ? 1 : 0;
            parms[13].Value = string.Format("{0}{1}",DateTime.Now.ToString("yyyyMMdd"),timespan);
            parms[14].Value = model.Keywords ?? string.Empty;
            parms[15].Value = model.SubTitle ?? string.Empty;
            return Convert.ToInt32(Goodspeed.Library.Data.SQLPlus.ExecuteScalar(CommandType.Text,strSQL,parms));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 添加或编辑
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static int Create(ArticleInfo model) {

            //处理一下关键词
            if(!string.IsNullOrEmpty(model.Keywords)){
                model.Keywords = Regex.Replace(model.Keywords, @"(\s+|,)", ",");
            }

            if (model.Id > 0)
            {
                //Update
                ArticleManage.Update(model);
                
            }
            else {
                int i = ArticleManage.Insert(model);
                model.Id = i;
            }
            return model.Id;
        }
Ejemplo n.º 6
0
        /// <summary>
       /// 更新
       /// </summary>
       /// <param name="model"></param>
       /// <returns></returns>
        public static int Update(ArticleInfo model) {
            string strSQL = "UPDATE Articles SET CategoryId = @CategoryId,Title = @Title,Content = @Content,ImageUrl = @ImageUrl,LinkUrl = @LinkUrl,Sort = @Sort,IsTop = @IsTop,PublishDateTime = @PublishDateTime,IsDeleted = @IsDeleted,Remark = @Remark,IsPublished = @IsPublished,Keywords = @Keywords,SubTitle = @SubTitle WHERE ID = @Id";
            SqlParameter[] parms = { 
                                    new SqlParameter("Id",SqlDbType.Int),
                                    new SqlParameter("CategoryId",SqlDbType.Int),
                                    new SqlParameter("Title",SqlDbType.NVarChar),
                                    new SqlParameter("Content",SqlDbType.NVarChar),
                                    new SqlParameter("ImageUrl",SqlDbType.NVarChar),
                                    new SqlParameter("LinkUrl",SqlDbType.NVarChar),
                                    new SqlParameter("IsTop",SqlDbType.Int),
                                    new SqlParameter("IsDeleted",SqlDbType.Int),
                                    new SqlParameter("PublishDateTime",SqlDbType.DateTime),
                                    new SqlParameter("Remark",SqlDbType.NVarChar),
                                    new SqlParameter("TimeSpan",SqlDbType.NVarChar),
                                    new SqlParameter("Sort",SqlDbType.Int),
                                    new SqlParameter("IsPublished",SqlDbType.Int),
                                    new SqlParameter("Keywords",SqlDbType.NVarChar),
                                    new SqlParameter("SubTitle",SqlDbType.NVarChar),
                                   };
            parms[0].Value = model.Id;
            parms[1].Value = model.CategoryId;
            parms[2].Value = string.IsNullOrEmpty(model.Title) ? string.Empty : model.Title;
            parms[3].Value = string.IsNullOrEmpty(model.Content) ? string.Empty : model.Content;
            parms[4].Value = string.IsNullOrEmpty(model.ImageUrl) ? string.Empty : model.ImageUrl;
            parms[5].Value = string.IsNullOrEmpty(model.LinkUrl) ? string.Empty : model.LinkUrl;
            parms[6].Value = model.IsTop;
            parms[7].Value = model.IsDeleted;
            parms[8].Value = model.PublishDateTime <= DateTime.MinValue ? DateTime.Now : model.PublishDateTime;
            parms[9].Value = string.IsNullOrEmpty(model.Remark) ? string.Empty : model.Remark;
            parms[10].Value = string.IsNullOrEmpty(model.Timespan) ? DateTime.Now.ToString("HHmmssfff") : model.Timespan;
            parms[11].Value = model.Sort;
            parms[12].Value = model.IsPublished ? 1 : 0;
            parms[13].Value = model.Keywords ?? string.Empty;
            parms[14].Value = model.SubTitle ?? string.Empty;

            return Goodspeed.Library.Data.SQLPlus.ExecuteNonQuery(CommandType.Text,strSQL,parms);
        }
Ejemplo n.º 7
0
 private static ArticleInfo Get(DataRow dr) {
     ArticleInfo model = new ArticleInfo();
     if(dr != null){
         model.CategoryId = dr.Field<int>("CategoryId");
         model.Content = dr.Field<string>("Content");
         model.CreateDateTime = dr.Field<DateTime>("CreateDateTime");
         model.GUID = dr.Field<Guid>("GUID");
         model.Id = dr.Field<int>("Id");
         model.ImageUrl = dr.Field<string>("ImageUrl");
         model.IsDeleted = dr.Field<bool>("IsDeleted");
         model.IsTop = dr.Field<bool>("IsTop");
         model.LinkUrl = dr.Field<string>("LinkUrl");
         model.PublishDateTime = dr.Field<DateTime>("PublishDateTime");
         model.Remark = dr.Field<string>("Remark");
         model.Sort = dr.Field<int>("Sort");
         model.Timespan = dr.Field<string>("Timespan");
         model.Title = dr.Field<string>("Title");
         model.ViewCount = dr.Field<int>("ViewCount");
         model.IsPublished = dr.Field<bool>("IsPublished");
         model.FullTimespan = dr.Field<string>("FullTimespan");
         model.Keywords = dr.Field<string>("Keywords");
         model.SubTitle = dr.Field<string>("SubTitle");
     }
     return model;
 }