public ContentResult InsertNewsInfoPost()
        {
            #region - paras -
                NewsMsgModel nmModel = new NewsMsgModel();

                nmModel.Title = Request.Form.Get("newsName");
                nmModel.NewsType=Request.Form.Get("newsType")==null?1:int.Parse(Request.Form.Get("newsType"));
                nmModel.ImageUrl=Request.Form.Get("imageUrl");
                nmModel.Content=Request.Form.Get("newsContent");

                #endregion

                var rltBool = _newsMsgBll.InsertNewsInfo(nmModel);

                return Content(rltBool ? "success" : "fail");
        }
Beispiel #2
0
        /// <summary>
        /// 添加新闻信息
        /// </summary>
        /// <param name="nmModel"></param>
        /// <returns></returns>
        public bool InsertNewsInfo(NewsMsgModel nmModel)
        {
            #region - sql qy -
               string insertSql = @"INSERT INTO `dinlun`.`newsmsg`
                                       (
                                        `Title`,
                                        `Content`,
                                        `NewsType`,
                                        `ImgUrl`,
                                        `InsertTime`,
                                        `avg1`,
                                        `avg2`)
                                VALUES (
                                        @Title,
                                        @Content,
                                        @NewsType,
                                        @ImgUrl,
                                        @InsertTime,
                                        @avg1,
                                        @avg2);";
               #endregion

               #region - paras -
               MySqlParameter[] paras = {
                                new MySqlParameter("@Title",nmModel.Title),
                                new MySqlParameter("@Content",nmModel.Content),
                                new MySqlParameter("@NewsType",nmModel.NewsType),
                                new MySqlParameter("@ImgUrl",nmModel.ImageUrl),
                                new MySqlParameter("@InsertTime",DateTime.Now),
                                new MySqlParameter("@Avg1",nmModel.Avg1),
                                new MySqlParameter("@Avg2",nmModel.Avg2)
                                   };
               #endregion

               #region - excute -
               try
               {

               //记录查询
               int rlt = DbHelperMySql.ExecuteNonQuery(DbHelperMySql.connectionStringManager, CommandType.Text, insertSql, paras);

               return rlt > 0;
               }
               catch (Exception ex)
               {

               return false;
               }
               #endregion
        }
Beispiel #3
0
        /// <summary>
        /// DataRow 转换至 NewsMsgModel 
        /// </summary>
        /// <param name="row">记录行</param>
        /// <returns>NewsMsgModel 实体</returns>
        public NewsMsgModel TransNewsMsgModel(DataRow row)
        {
            NewsMsgModel newsMsgModel = new NewsMsgModel();

            newsMsgModel.ID = row["ID"] != null ? (int)row["ID"]: 0;
            newsMsgModel.Title = row["Title"] != null ? row["Title"].ToString() : string.Empty;
            newsMsgModel.Content = row["Content"] != null ? row["Content"].ToString() : string.Empty;
            newsMsgModel.NewsType = row["NewsType"] != null ? (int)row["NewsType"] : 0;
            newsMsgModel.ImageUrl = row["ImgUrl"] != null ? row["ImgUrl"].ToString() : string.Empty;
            newsMsgModel.InsertTime = row["InsertTime"] != null ? Convert.ToDateTime(row["InsertTime"]) : DateTime.MinValue;
            newsMsgModel.Avg1 = row["avg1"] != null ? row["avg1"].ToString() : string.Empty;
            newsMsgModel.Avg2 = row["avg2"] != null ? row["avg2"].ToString() : string.Empty;

            return newsMsgModel;
        }
Beispiel #4
0
 /// <summary>
 /// 添加新闻信息
 /// </summary>
 /// <param name="nmModel"></param>
 /// <returns></returns>
 public bool InsertNewsInfo(NewsMsgModel nmModel)
 {
     return  _nesmsgDalInstance.InsertNewsInfo(nmModel);
 }