private DBNews GetNewsFromReader(IDataReader dataReader) { var item = new DBNews(); item.NewsId = NopSqlDataHelper.GetInt(dataReader, "NewsID"); item.LanguageId = NopSqlDataHelper.GetInt(dataReader, "LanguageID"); item.Title = NopSqlDataHelper.GetString(dataReader, "Title"); item.Short = NopSqlDataHelper.GetString(dataReader, "Short"); item.Full = NopSqlDataHelper.GetString(dataReader, "Full"); item.Published = NopSqlDataHelper.GetBoolean(dataReader, "Published"); item.AllowComments = NopSqlDataHelper.GetBoolean(dataReader, "AllowComments"); item.CreatedOn = NopSqlDataHelper.GetUtcDateTime(dataReader, "CreatedOn"); return(item); }
private DBNews GetNewsFromReader(IDataReader dataReader) { DBNews news = new DBNews(); news.NewsID = NopSqlDataHelper.GetInt(dataReader, "NewsID"); news.LanguageID = NopSqlDataHelper.GetInt(dataReader, "LanguageID"); news.Title = NopSqlDataHelper.GetString(dataReader, "Title"); news.Short = NopSqlDataHelper.GetString(dataReader, "Short"); news.Full = NopSqlDataHelper.GetString(dataReader, "Full"); news.Published = NopSqlDataHelper.GetBoolean(dataReader, "Published"); news.AllowComments = NopSqlDataHelper.GetBoolean(dataReader, "AllowComments"); news.CreatedOn = NopSqlDataHelper.GetUtcDateTime(dataReader, "CreatedOn"); return(news); }
/// <summary> /// Gets a news /// </summary> /// <param name="newsId">The news identifier</param> /// <returns>News</returns> public override DBNews GetNewsById(int newsId) { DBNews item = null; Database db = NopSqlDataHelper.CreateConnection(_sqlConnectionString); DbCommand dbCommand = db.GetStoredProcCommand("Nop_NewsLoadByPrimaryKey"); db.AddInParameter(dbCommand, "NewsID", DbType.Int32, newsId); using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { if (dataReader.Read()) { item = GetNewsFromReader(dataReader); } } return(item); }
/// <summary> /// Gets news item collection /// </summary> /// <param name="LanguageID">Language identifier. 0 if you want to get all news</param> /// <param name="NewsCount">News item count. 0 if you want to get all news</param> /// <param name="showHidden">A value indicating whether to show hidden records</param> /// <returns>News item collection</returns> public override DBNewsCollection GetNews(int LanguageID, int NewsCount, bool showHidden) { DBNewsCollection newsCollection = new DBNewsCollection(); Database db = NopSqlDataHelper.CreateConnection(_sqlConnectionString); DbCommand dbCommand = db.GetStoredProcCommand("Nop_NewsLoadAll"); db.AddInParameter(dbCommand, "LanguageID", DbType.Int32, LanguageID); db.AddInParameter(dbCommand, "NewsCount", DbType.Int32, NewsCount); db.AddInParameter(dbCommand, "ShowHidden", DbType.Boolean, showHidden); using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { while (dataReader.Read()) { DBNews news = GetNewsFromReader(dataReader); newsCollection.Add(news); } } return(newsCollection); }
/// <summary> /// Inserts a news item /// </summary> /// <param name="languageId">The language identifier</param> /// <param name="title">The news title</param> /// <param name="shortText">The short text</param> /// <param name="fullText">The full text</param> /// <param name="published">A value indicating whether the entity is published</param> /// <param name="allowComments">A value indicating whether the entity allows comments</param> /// <param name="createdOn">The date and time of instance creation</param> /// <returns>News item</returns> public override DBNews InsertNews(int languageId, string title, string shortText, string fullText, bool published, bool allowComments, DateTime createdOn) { DBNews item = null; Database db = NopSqlDataHelper.CreateConnection(_sqlConnectionString); DbCommand dbCommand = db.GetStoredProcCommand("Nop_NewsInsert"); db.AddOutParameter(dbCommand, "NewsID", DbType.Int32, 0); db.AddInParameter(dbCommand, "LanguageID", DbType.Int32, languageId); db.AddInParameter(dbCommand, "Title", DbType.String, title); db.AddInParameter(dbCommand, "Short", DbType.String, shortText); db.AddInParameter(dbCommand, "Full", DbType.String, fullText); db.AddInParameter(dbCommand, "Published", DbType.Boolean, published); db.AddInParameter(dbCommand, "AllowComments", DbType.Boolean, allowComments); db.AddInParameter(dbCommand, "CreatedOn", DbType.DateTime, createdOn); if (db.ExecuteNonQuery(dbCommand) > 0) { int newsId = Convert.ToInt32(db.GetParameterValue(dbCommand, "@NewsID")); item = GetNewsById(newsId); } return(item); }
/// <summary> /// Updates the news item /// </summary> /// <param name="NewsID">The news identifier</param> /// <param name="LanguageID">The language identifier</param> /// <param name="Title">The news title</param> /// <param name="Short">The short text</param> /// <param name="Full">The full text</param> /// <param name="Published">A value indicating whether the entity is published</param> /// <param name="AllowComments">A value indicating whether the entity allows comments</param> /// <param name="CreatedOn">The date and time of instance creation</param> /// <returns>News item</returns> public override DBNews UpdateNews(int NewsID, int LanguageID, string Title, string Short, string Full, bool Published, bool AllowComments, DateTime CreatedOn) { DBNews news = null; Database db = NopSqlDataHelper.CreateConnection(_sqlConnectionString); DbCommand dbCommand = db.GetStoredProcCommand("Nop_NewsUpdate"); db.AddInParameter(dbCommand, "NewsID", DbType.Int32, NewsID); db.AddInParameter(dbCommand, "LanguageID", DbType.Int32, LanguageID); db.AddInParameter(dbCommand, "Title", DbType.String, Title); db.AddInParameter(dbCommand, "Short", DbType.String, Short); db.AddInParameter(dbCommand, "Full", DbType.String, Full); db.AddInParameter(dbCommand, "Published", DbType.Boolean, Published); db.AddInParameter(dbCommand, "AllowComments", DbType.Boolean, AllowComments); db.AddInParameter(dbCommand, "CreatedOn", DbType.DateTime, CreatedOn); if (db.ExecuteNonQuery(dbCommand) > 0) { news = GetNewsByID(NewsID); } return(news); }