Exemplo n.º 1
0
 public static ArticleInfo Create(ArticleInfo model) {
     if (model.Id == 0)
     {
         //Insert
         int id = ArticleManage.Insert(model);
         model.Id = id;
     }
     else {
         ArticleManage.Update(model);
     }
     //插入ArticleTags表
     ArticleManage.InsertArticleTagData(model.Id,model.Tags);
     return model;
 }
Exemplo n.º 2
0
        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static int Insert(ArticleInfo model) {
            string strSQL = "INSERT INTO Articles(CategoryId,Title,Content,Remark,ImageUrl,QuickLinkUrl,Tags,Author,Sort,IsTop,IsDeleted,PublishDateTime,TimeSpan,Url,CompanyId,AddUserName,LastModifyUserName,LastModifyDateTime,Copyright,SubTitle) VALUES(@CategoryId,@Title,@Content,@Remark,@ImageUrl,@QuickLinkUrl,@Tags,@Author,@Sort,@IsTop,@IsDeleted,@PublishDateTime,@TimeSpan,@Url,@CompanyId,@AddUserName,@AddUserName,GETDATE(),@Copyright,@SubTitle);SELECT @@IDENTITY;";
            SqlParameter[] parms = { 
                                    new SqlParameter("Id",SqlDbType.Int),
                                    new SqlParameter("CategoryId",SqlDbType.Int),
                                    new SqlParameter("Title",SqlDbType.NVarChar),
                                    new SqlParameter("Content",SqlDbType.NVarChar),
                                    new SqlParameter("Remark",SqlDbType.NVarChar),
                                    new SqlParameter("ImageUrl",SqlDbType.VarChar),
                                    new SqlParameter("QuickLinkUrl",SqlDbType.VarChar),
                                    new SqlParameter("Tags",SqlDbType.VarChar),
                                    new SqlParameter("Author",SqlDbType.VarChar),
                                    new SqlParameter("Sort",SqlDbType.Int),
                                    new SqlParameter("IsTop",SqlDbType.Bit),
                                    new SqlParameter("IsDeleted",SqlDbType.Bit),
                                    new SqlParameter("PublishDateTime",SqlDbType.DateTime),
                                    new SqlParameter("TimeSpan",SqlDbType.VarChar),
                                    new SqlParameter("Url",SqlDbType.VarChar),
                                    new SqlParameter("CompanyId",SqlDbType.Int),
                                    new SqlParameter("AddUserName",SqlDbType.NVarChar),
                                    new SqlParameter("Copyright",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.Remark) ? string.Empty : model.Remark;
            parms[5].Value = string.IsNullOrEmpty(model.ImageUrl) ? string.Empty : model.ImageUrl;
            parms[6].Value = string.IsNullOrEmpty(model.QuickLinkUrl) ? string.Empty : model.QuickLinkUrl;
            parms[7].Value = string.IsNullOrEmpty(model.Tags) ? string.Empty : model.Tags;
            parms[8].Value = string.IsNullOrEmpty(model.Author) ? string.Empty : model.Author;
            parms[9].Value = model.Sort;
            parms[10].Value = model.IsTop;
            parms[11].Value = model.IsDeleted;
            parms[12].Value = model.PublishDateTime;
            parms[13].Value = model.TimeSpan ?? DateTime.Now.ToString("yyyyMMddHHmmssffff");
            parms[14].Value = model.Url;
            parms[15].Value = model.CompanyId;
            parms[16].Value = string.IsNullOrEmpty(model.AddUserName) ? string.Empty : model.AddUserName;
            parms[17].Value = model.Copyright ?? string.Empty;
            parms[18].Value = model.SubTitle ?? string.Empty;
            

            return Convert.ToInt32(SQLPlus.ExecuteScalar(CommandType.Text,strSQL,parms));
        }
Exemplo n.º 3
0
        public ActionResult Add(ArticleInfo oldModel,FormCollection fc) {
            bool isAdd = true;
            if(oldModel.Id >0){
                isAdd = false;
            }
            if(ModelState.IsValid){
                //TODO
                //在这,最好检查一下标题是否重复,目前没做
                oldModel.AddUserName = User.Identity.Name;
                oldModel.LastModifyUserName = User.Identity.Name;
                oldModel.CategoryId = Utils.StrToInt(fc["select_column"],0);

                //改变URL
                oldModel.Url = oldModel.QuickLinkUrl;
                if(string.IsNullOrEmpty(oldModel.Url)){
                    oldModel.Url = string.Format("/article/show/{0}.html", oldModel.TimeSpan);
                }

                oldModel = ArticleService.Create(oldModel);

                //插入到Article2Category表中
                //1,技术分类
                var requestTechListArray = CECRequest.GetFormString("cbtechlist").Split(',');
                List<int> techList = new List<int>();
                foreach(string item in requestTechListArray){
                    int id = Utils.StrToInt(item,0);
                    if(id>0){
                        techList.Add(id);
                    }
                }
                ArticleService.InsertArticle2Category(oldModel.Id, CatType.Tech, techList);
                //2,行业分类
                var requestIndustryList = CECRequest.GetFormString("cbindustrylist").Split(',');
                List<int> industryList = new List<int>();
                foreach(string item in requestIndustryList){
                    int id = Utils.StrToInt(item,0);
                    if(id>0){
                        industryList.Add(id);
                    }
                }
                ArticleService.InsertArticle2Category(oldModel.Id, CatType.Industry, industryList);
                

                //完成,提示信息
                if (isAdd)
                {
                    ViewBag.Msg = "添加成功!<a href=\"add\">继续?</a><span class=\"ml10\">或</span><a href=\"list\" class=\"ml10\">返回</a>";
                }
                else
                {
                    ViewBag.Msg = "修改成功!<a href=\"add\">添加新文章?</a><span class=\"ml10\">或</span><a href=\"list\" class=\"ml10\">返回</a>";
                }
            }

            //初始化栏目类别
            //初始化栏目类别
            var allColumnList = ColumnService.List().ToList();
            var dropdownList = new List<ColumnInfo>();
            ColumnService.BuildListForTree(dropdownList, allColumnList, 0);
            ViewBag.ColumnDropDownList = dropdownList;

            //输出技术分类
            ViewBag.TechList = TechService.List().Where(m => m.IsDeleted == false);
            //输出行业分类
            ViewBag.IndustryList = IndustryService.List().Where(m => m.IsDeleted == false);

            //已选择的技术分类和行业分类
            ViewBag.SelectTechList = ArticleService.Article2CategoryListByArticleIdAndType(oldModel.Id, CatType.Tech);
            ViewBag.SelectIndustryList = ArticleService.Article2CategoryListByArticleIdAndType(oldModel.Id, CatType.Industry);

            string companyName = string.Empty;
            if (oldModel.CompanyId > 0)
            {
                //对CompanyName进行赋值
                //数据库中只保存CompanyId,没有保存CompanyName,只能在这里处理一下
                companyName = MemberService.GetBaseCompanyInfo(oldModel.CompanyId).CompanyName;
            }
            ViewBag.CompanyName = companyName;

            return View(oldModel);
        }
Exemplo n.º 4
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,Remark = @Remark,ImageUrl = @ImageUrl,QuickLinkUrl = @QuickLinkUrl,Tags = @Tags,Author = @Author,Sort = @Sort,IsTop = @IsTop,IsDeleted = @IsDeleted,PublishDateTime = @PublishDateTime,CompanyId = @CompanyId,LastModifyUserName = @LastModifyUserName,LastModifyDateTime = GETDATE(),Url = @Url,Copyright = @Copyright,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("Remark",SqlDbType.NVarChar),
                                    new SqlParameter("ImageUrl",SqlDbType.VarChar),
                                    new SqlParameter("QuickLinkUrl",SqlDbType.VarChar),
                                    new SqlParameter("Tags",SqlDbType.VarChar),
                                    new SqlParameter("Author",SqlDbType.VarChar),
                                    new SqlParameter("Sort",SqlDbType.Int),
                                    new SqlParameter("IsTop",SqlDbType.Bit),
                                    new SqlParameter("IsDeleted",SqlDbType.Bit),
                                    new SqlParameter("PublishDateTime",SqlDbType.DateTime),
                                    new SqlParameter("CompanyId",SqlDbType.Int),
                                    new SqlParameter("LastModifyUserName",SqlDbType.NVarChar),
                                    new SqlParameter("Url",SqlDbType.NVarChar),
                                    new SqlParameter("Copyright",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.Remark) ? string.Empty : model.Remark;
            parms[5].Value = string.IsNullOrEmpty(model.ImageUrl) ? string.Empty : model.ImageUrl;
            parms[6].Value = string.IsNullOrEmpty(model.QuickLinkUrl) ? string.Empty : model.QuickLinkUrl;
            parms[7].Value = string.IsNullOrEmpty(model.Tags) ? string.Empty : model.Tags;
            parms[8].Value = string.IsNullOrEmpty(model.Author) ? string.Empty : model.Author;
            parms[9].Value = model.Sort;
            parms[10].Value = model.IsTop;
            parms[11].Value = model.IsDeleted;
            parms[12].Value = model.PublishDateTime;
            parms[13].Value = model.CompanyId;
            parms[14].Value = string.IsNullOrEmpty(model.LastModifyUserName) ? string.Empty : model.LastModifyUserName;
            parms[15].Value = model.Url;
            parms[16].Value = model.Copyright ?? string.Empty;
            parms[17].Value = model.SubTitle ?? string.Empty;

            return SQLPlus.ExecuteNonQuery(CommandType.Text,strSQL,parms);
        }