public NewsTags GetNewsTags(int _tagsID, int _newsGroupID) { NewsTags _newsTags = null; using (SqlConnection connection = GetConnection()) { SqlCommand command = new SqlCommand("_NewsTagsGet", connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@TagsID", _tagsID); command.Parameters.AddWithValue("@NewsGroupID", _newsGroupID); connection.Open(); using (SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection)) { if (reader.Read()) { _newsTags = NewsTagsReader(reader); } else { _newsTags = null; } // throw new DataAccessException("Không tìm thấy giá trị"); command.Dispose(); } } return(_newsTags); }
public NewsTags GetNewsTagsById(int Id) { NewsTags _newsTags = null; using (SqlConnection connection = GetConnection()) { SqlCommand command = new SqlCommand("_NewsTagsGetById", connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@NewsTagsID", Id); connection.Open(); using (SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection)) { if (reader.Read()) { _newsTags = NewsTagsReader(reader); } else { throw new DataAccessException("Khong tim thay gia tri nao"); } command.Dispose(); } } return(_newsTags); }
public virtual IList <NewsTags> GetAllNewsTags(int storeId, int languageId, bool showHidden = false) { var blogPostTags = new List <NewsTags>(); var news = GetAllNews(storeId: storeId, languageId: languageId, showHidden: showHidden); foreach (var newsItem in news) { var tags = this.ParseTags(newsItem); foreach (var tag in tags) { var foundNewsTag = blogPostTags.Find(bpt => bpt.Name.Equals(tag, StringComparison.InvariantCultureIgnoreCase)); if (foundNewsTag == null) { foundNewsTag = new NewsTags { Name = tag, NewsCount = 1 }; blogPostTags.Add(foundNewsTag); } else { foundNewsTag.NewsCount++; } } } return(blogPostTags); }
public NewsTagsDto CreateNewsTagDto(NewsTags newsTags) { return(new NewsTagsDto { Name = newsTags.Name }); }
public static string GetTagDescription(NewsTags tag) { switch (tag) { case NewsTags.Clothes: return("#smartclothes"); case NewsTags.Startups: return("#startups"); case NewsTags.Devices: return("#devices"); case NewsTags.Robots: return("#robots"); case NewsTags.AI: return("#ai"); case NewsTags.Video: return("#video"); default: return("#commons"); } }
private NewsTags NewsTagsReader(SqlDataReader reader) { NewsTags _newsTags = new NewsTags(); _newsTags.NewsTagsID = (int)reader["NewsTagsID"]; _newsTags.TagsID = (int)reader["TagsID"]; _newsTags.NewsGroupID = (int)reader["NewsGroupID"]; return(_newsTags); }
public bool CheckExitTags(int _tagsID, int _newsGroupID) { bool check = false; NewsTags _newstags = new NewsTags(); _newstags = GetNewsTags(_tagsID, _newsGroupID); if (_newstags != null) { check = true; } return(check); }
internal static void InserNewPair(int newId, int tagId) { using (SampleContext context = new SampleContext()) { var idTag = context.newsTags.SingleOrDefault(u => u.newsId == newId && tagId == u.tagId); if (idTag == null) { NewsTags newsTags = new NewsTags(); newsTags.newsId = newId; newsTags.tagId = tagId; context.newsTags.Add(newsTags); context.SaveChanges(); } } }
internal static void InserNewPairs(List <string> tagList, string title) { if (tagList.Count != 0) { using (SampleContext context = new SampleContext()) { int newId = context.news.SingleOrDefault(x => x.title == title).newsId; NewsTags newTagNews = new NewsTags(); foreach (var item in tagList) { var tagId = context.tags.SingleOrDefault(x => x.tag == item).tagId; newTagNews.newsId = newId; newTagNews.tagId = tagId; context.newsTags.Add(newTagNews); context.SaveChanges(); } } JsonController.tagList.Clear(); } }
public void UpdateNewsTags(NewsTags _newsTags) { using (SqlConnection connection = GetConnection()) { SqlCommand command = new SqlCommand("_NewsTagsUpdate", connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@Type", 1); command.Parameters.AddWithValue("@NewsTagsID", _newsTags.NewsTagsID); command.Parameters.AddWithValue("@TagsID", _newsTags.TagsID); command.Parameters.AddWithValue("@NewsGroupID", _newsTags.NewsGroupID); connection.Open(); if (command.ExecuteNonQuery() <= 0) { throw new DataAccessException("Khong cap nhat duoc quang cao"); } else { command.Dispose(); } } }
public void UpdateNewsTags(NewsTags _newsTags) { NewsTagsDAO _newstagsDAO = new NewsTagsDAO(); _newstagsDAO.UpdateNewsTags(_newsTags); }
public void CreateNewsTags(NewsTags _newsTags) { NewsTagsDAO _newstagsDAO = new NewsTagsDAO(); _newstagsDAO.CreateNewsTags(_newsTags); }